-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/hashtag 01 #9
Conversation
- ν΄μνκ·Έμ κΈΈμ΄λ 10κΈμ μ΄ν - μλ¬Έ,μ«μ,νκΈ,_ λ§ κ°λ₯
- λ€λ₯Έ κ³³μμλ μ¬μ©ν μ μλ κΈ°λ₯μ΄κΈ°μ λ³λμ ν΄λμ€λ‘ ꡬν
- ν΄μνκ·Έκ° DBμ μ‘΄μ¬νμ§ μμλλ§ μμ± - ν΄μνκ·Έ content λ‘ λΆν° λ¨κ±΄ μ‘°ννλ λ‘μ§ μμ±
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ 체μ μΌλ‘ μ μμ±ν΄μ£Όμ μ μ΄λ² νλ‘μ νΈ μ§νμ μμ΄μ ν° λμμ΄ λ κ² κ°μ΅λλ€!
νΉνλ μλ¬ μ²λ¦¬νλ λΆλΆλ€μ μΈλΆνν΄μ λνλ΄κΈ° νΈλ¦¬νλ€λ μ μ΄ μ’μ 보μμ΅λλ€:)
κ°μΈμ μΌλ‘ κΆκΈν λΆλΆλ€μ λ°λ‘ 리뷰λ₯Ό λ¨κ²¨λμμ΅λλ€
κ³ μνμ ¨μ΅λλ«!!
public HashtagEntity(String content) { | ||
validateContent(content); | ||
this.content = content; | ||
} | ||
|
||
private void validateContent(String content) { | ||
|
||
if (content == null || content.isBlank()) { | ||
throw new HashtagException(HashtagErrorCode.EMPTY_CONTENT); | ||
} | ||
if (content.length() > 10) { | ||
throw new HashtagException(HashtagErrorCode.TOO_LONG_HASHTAG_CONTENT); | ||
} | ||
if (!HASHTAG_PATTERN.matcher(content).matches()) { | ||
throw new HashtagException(HashtagErrorCode.INVALID_HASHTAG_CONTENT); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HashtagEntityκ° μμ±μλ₯Ό ν΅ν΄ validateContentλ₯Ό μ²λ¦¬νλ κ² κ°μλ°, νΉμ λΉλ ν¨ν΄μΌλ‘ μ²λ¦¬ν λμλ validateContent λ©μλκ° νΈμΆλκ³ μλμ?? (μ κ° μ λλ‘ λͺ» λ΄€μ μλ μμ΅λλ€... γ )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HashtagEntityκ° μμ±μλ₯Ό ν΅ν΄ validateContentλ₯Ό μ²λ¦¬νλ κ² κ°μλ°, νΉμ λΉλ ν¨ν΄μΌλ‘ μ²λ¦¬ν λμλ validateContent λ©μλκ° νΈμΆλκ³ μλμ?? (μ κ° μ λλ‘ λͺ» λ΄€μ μλ μμ΅λλ€... γ )
μ λ§λ€μ μ΄λΆλΆμ μμ νκ² μ΅λλ€ κ°μ¬ν©λλ€
public List<PostHashtagEntity> create(PostEntity post, Set<String> contents) { | ||
List<HashtagEntity> hashtags = contents.stream() | ||
.map(hashtagService::createIfNotExists) | ||
.collect(Collectors.toList()); | ||
|
||
List<PostHashtagEntity> postHashtags = hashtags.stream() | ||
.map(hashtag -> | ||
PostHashtagEntity.builder() | ||
.post(post) | ||
.hashtag(hashtag) | ||
.build() | ||
).collect(Collectors.toList()); | ||
|
||
return postHashtagRepository.saveAll(postHashtags); | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ν΄μνκ·Έλ₯Ό μμ±ν contentsλ₯Ό extractν΄μ create λ©μλλ‘ λ€κ³ μμ, κ°κ° μ€νΈλ¦Όμ ν΅ν΄ μ‘΄μ¬νμ§ μλ κ²½μ° μμ±νκ³ PostHashtagEntityλ₯Ό μ§μ ν΄μ£Όκ³ μλλ°, ν΄μνκ·Έ μμ± κ³Όμ μμ validate exceptionκ³Ό κ°μ κ²μ΄ λ°μνλ©΄ μ΄λ€ μμΌλ‘ μ²λ¦¬κ° λλμ§ κΆκΈν©λλ€!
- μ λ ν΄μνκ·Έλ₯Ό μμ±νλ κ²μ κ²μκΈμ μΆκ°νλ©΄μ PostService κ°μ κ³³μμ μλ§ Transactional μλ Έν μ΄μ μ μ€μ ν κ²μ΄κΈ° λλ¬Έμ μ€μ νμ§ μμΌμ κ²μΌλ‘ μμνκ³ μμ΅λλ€ :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ν΄μνκ·Έλ₯Ό μμ±ν contentsλ₯Ό extractν΄μ create λ©μλλ‘ λ€κ³ μμ, κ°κ° μ€νΈλ¦Όμ ν΅ν΄ μ‘΄μ¬νμ§ μλ κ²½μ° μμ±νκ³ PostHashtagEntityλ₯Ό μ§μ ν΄μ£Όκ³ μλλ°, ν΄μνκ·Έ μμ± κ³Όμ μμ validate exceptionκ³Ό κ°μ κ²μ΄ λ°μνλ©΄ μ΄λ€ μμΌλ‘ μ²λ¦¬κ° λλμ§ κΆκΈν©λλ€!
- μ λ ν΄μνκ·Έλ₯Ό μμ±νλ κ²μ κ²μκΈμ μΆκ°νλ©΄μ PostService κ°μ κ³³μμ μλ§ Transactional μλ Έν μ΄μ μ μ€μ ν κ²μ΄κΈ° λλ¬Έμ μ€μ νμ§ μμΌμ κ²μΌλ‘ μμνκ³ μμ΅λλ€ :)
λ§μ΅λλ€ postservice μμ νλμ νΈλμμ
μΌλ‘ λ¬Άμ¬ μ€νλ κ±°λΌ ν΄λΉλΆλΆμμ μΌλ¨ κ±Έμ§ μμμ΅λλ€
hashtag μμ κ²μ¦μμΈκ° λ°μνλ©΄ μλ¬νΈλ€λ¬κ° μ‘μμ λμ μ£Όλ νλ‘μ°λ₯Ό μκ°νκ³ μμμ΅λλ€
μΆνμ μλ¬νΈλ€λ¬μλ λ°λ‘ hashtagerrorλ₯Ό μΆκ°ν΄μ£Όλ €κ³ ν©λλ€
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ 체μ μΌλ‘ κ΅¬μ‘°κ° μ μ§μ¬ μμ΄μ λ°°μκ°λκ² λ§μμ΅λλ€.
μ ν¨μ± κ²μ¦μ λν ν
μ€νΈ μΌμ΄μ€λ§ λͺ κ°μ§ λ ν΄λ³΄λ©΄ λμ± κ²¬κ³ ν΄μ§ κ² κ°μ΅λλ€!
.orElseThrow(() -> new HashtagException(HashtagErrorCode.NOT_FOUND)); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
κ²μκΈ μμ±μμ ν΄μνκ·Έ μ‘°νμμ μ΄λ°μμ ꡬμ±λ κ°λ₯νκ΅°μ.
λ°°μκ°λλ€ :)
public enum HashtagErrorCode implements ErrorCodeIfs { | ||
|
||
INVALID_HASHTAG_CONTENT(HttpStatus.BAD_REQUEST, 400, "ν΄μνκ·Έ νΉμλ¬Έμλ₯Ό ν¬ν¨ν μ μμ΅λλ€."), | ||
EMPTY_CONTENT(HttpStatus.BAD_REQUEST, 400, "ν΄μνν¬ λ΄μ©μ΄ μμ΅λλ€."), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ€νμμ΄μ©!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ€νμμ΄μ©!
κ°μ¬ν©λλ€!
π κ³Όμ μ€λͺ
post μ content λ‘ λΆν° ν΄μνκ·Έλ₯Ό μΆμΆνμ¬ λ±λ‘νλ κΈ°λ₯μ ꡬν
π©βπ» μꡬ μ¬νκ³Ό ꡬν λ΄μ©
β νΌλλ°± λ°μμ¬ν
β PR ν¬μΈνΈ & κΆκΈν μ
close #8