Skip to content
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

Merged
merged 8 commits into from
Feb 3, 2025
Merged

Feature/hashtag 01 #9

merged 8 commits into from
Feb 3, 2025

Conversation

sobaman
Copy link
Collaborator

@sobaman sobaman commented Jan 31, 2025

πŸ“Œ 과제 μ„€λͺ…


post 의 content 둜 λΆ€ν„° ν•΄μ‹œνƒœκ·Έλ₯Ό μΆ”μΆœν•˜μ—¬ λ“±λ‘ν•˜λŠ” κΈ°λŠ₯을 κ΅¬ν˜„

πŸ‘©β€πŸ’» μš”κ΅¬ 사항과 κ΅¬ν˜„ λ‚΄μš©


  • ν•΄μ‹œνƒœκ·Έ μΆ”μΆœμ„ λ‹΄λ‹Ήν•˜λŠ” ν΄λž˜μŠ€λŠ” λ‹€λ₯Έ κ³³μ—μ„œλ„ ν•„μš”ν•  수 μžˆμœΌλ‹ˆ λ³„λ„μ˜ 클래슀둜 ꡬ뢄
  • ν•΄μ‹œνƒœκ·Έ 엔티티에 λŒ€ν•œ μœ νš¨μ„± 검증 둜직 κ΅¬ν˜„
    • ν•΄μ‹œνƒœκ·ΈλŠ” κΈ€μžμˆ˜λŠ” 10자λ₯Ό μ΄ˆκ³Όν•  수 μ—†λ‹€
    • ν•΄μ‹œνƒœκ·ΈλŠ”οΏ½ μ˜μ–΄,숫자,ν•œκΈ€,_ 만 ν—ˆμš©λœλ‹€
  • post μ„œλΉ„μŠ€μ—μ„œ 등둝 μ‹œμ μ— content λ₯Ό κ°€μ Έμ™€μ„œ ν•΄μ‹œνƒœκ·Έ μΆ”μΆœκ³Ό ν•΄μ‹œνƒœκ·Έ 생성을 진행
  • λ§Œμ•½ ν•΄μ‹œνƒœκ·Έκ°€ 이미 μ‘΄μž¬ν•˜λ©΄ μ €μž₯ν•˜μ§€ μ•Šκ³  κ°€μ Έμ˜€κΈ°λ§Œ μ‹€ν–‰

βœ… ν”Όλ“œλ°± λ°˜μ˜μ‚¬ν•­

βœ… PR 포인트 & κΆκΈˆν•œ 점

close #8

- ν•΄μ‹œνƒœκ·Έμ˜ κΈΈμ΄λŠ” 10κΈ€μž μ΄ν•˜
- 영문,숫자,ν•œκΈ€,_ 만 κ°€λŠ₯
- λ‹€λ₯Έ κ³³μ—μ„œλ„ μ‚¬μš©ν•  수 μžˆλŠ” κΈ°λŠ₯이기에 λ³„λ„μ˜ 클래슀둜 κ΅¬ν˜„
- ν•΄μ‹œνƒœκ·Έκ°€ DB에 μ‘΄μž¬ν•˜μ§€ μ•Šμ„λ•Œλ§Œ 생성
- ν•΄μ‹œνƒœκ·Έ content 둜 λΆ€ν„° 단건 μ‘°νšŒν•˜λŠ” 둜직 생성
@sobaman sobaman self-assigned this Jan 31, 2025
@sobaman sobaman requested a review from joonaeng January 31, 2025 08:59
Copy link
Collaborator

@ChoiHyunSan ChoiHyunSan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ „μ²΄μ μœΌλ‘œ 잘 μž‘μ„±ν•΄μ£Όμ…”μ„œ 이번 ν”„λ‘œμ νŠΈ 진행에 μžˆμ–΄μ„œ 큰 도움이 된 것 κ°™μŠ΅λ‹ˆλ‹€!

νŠΉνžˆλ‚˜ μ—λŸ¬ μ²˜λ¦¬ν•˜λŠ” 뢀뢄듀을 μ„ΈλΆ„ν™”ν•΄μ„œ λ‚˜νƒ€λ‚΄κΈ° νŽΈλ¦¬ν•˜λ‹€λŠ” 점이 μ’‹μ•„ λ³΄μ˜€μŠ΅λ‹ˆλ‹€:)
개인적으둜 κΆκΈˆν•œ 뢀뢄듀은 λ”°λ‘œ 리뷰λ₯Ό λ‚¨κ²¨λ‘μ—ˆμŠ΅λ‹ˆλ‹€

κ³ μƒν•˜μ…¨μŠ΅λ‹ˆλ‹«!!

Comment on lines +37 to +54
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);
}

}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HashtagEntityκ°€ μƒμ„±μžλ₯Ό 톡해 validateContentλ₯Ό μ²˜λ¦¬ν•˜λŠ” 것 같은데, ν˜Ήμ‹œ λΉŒλ” νŒ¨ν„΄μœΌλ‘œ μ²˜λ¦¬ν•  λ•Œμ—λ„ validateContent λ©”μ„œλ“œκ°€ 호좜되고 μžˆλ‚˜μš”?? (μ œκ°€ μ œλŒ€λ‘œ λͺ» 봀을 μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€... γ…œ)

Copy link
Collaborator Author

@sobaman sobaman Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HashtagEntityκ°€ μƒμ„±μžλ₯Ό 톡해 validateContentλ₯Ό μ²˜λ¦¬ν•˜λŠ” 것 같은데, ν˜Ήμ‹œ λΉŒλ” νŒ¨ν„΄μœΌλ‘œ μ²˜λ¦¬ν•  λ•Œμ—λ„ validateContent λ©”μ„œλ“œκ°€ 호좜되고 μžˆλ‚˜μš”?? (μ œκ°€ μ œλŒ€λ‘œ λͺ» 봀을 μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€... γ…œ)

μ•„ λ§žλ„€μš” 이뢀뢄은 μˆ˜μ •ν•˜κ² μŠ΅λ‹ˆλ‹€ κ°μ‚¬ν•©λ‹ˆλ‹€

Comment on lines +23 to +38
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);

}
Copy link
Collaborator

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 μ—λ…Έν…Œμ΄μ…˜μ„ μ„€μ •ν•  것이기 λ•Œλ¬Έμ— μ„€μ •ν•˜μ§€ μ•ŠμœΌμ‹  κ²ƒμœΌλ‘œ μ˜ˆμƒν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€ :)

Copy link
Collaborator Author

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λ₯Ό μΆ”κ°€ν•΄μ£Όλ €κ³  ν•©λ‹ˆλ‹€

Copy link
Collaborator

@Metronon Metronon left a 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));
}

}
Copy link
Collaborator

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, "ν•΄μ‹œνƒœν¬ λ‚΄μš©μ΄ μ—†μŠ΅λ‹ˆλ‹€."),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ˜€νƒ€μžˆμ–΄μš©!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ˜€νƒ€μžˆμ–΄μš©!

κ°μ‚¬ν•©λ‹ˆλ‹€!

@sobaman sobaman merged commit 5fa3bc1 into main Feb 3, 2025
@Metronon Metronon deleted the feature/hashtag-01 branch February 5, 2025 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] ν•΄μ‹œνƒœκ·Έ 생성 κΈ°λŠ₯ κ΅¬ν˜„
3 participants