-
Notifications
You must be signed in to change notification settings - Fork 1
Refactor : 각 Entity에 맞는 success, error 코드 추가 및 적용 #90
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
Conversation
WalkthroughAdds domain-specific success/error enums for post, comment, and notification and replaces general codes with these domain codes across controllers and services; no public API signatures changed. Some newly added enums contain trailing comma syntax issues. Changes
Sequence Diagram(s)(omitted — changes are limited to replacing error/success constants and do not introduce new control-flow interactions) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Assessment against linked issues
Assessment against linked issues: Out-of-scope changes
Possibly related PRs
Suggested labels
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. 📜 Recent review detailsConfiguration used: CodeRabbit UI 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (4)
src/main/java/naughty/tuzamate/domain/post/service/query/PostQueryServiceImpl.java (1)
35-41: Mark-as-read won’t persist without a transaction.
post.setIsRead()will not be flushed if this method isn’t transactional. Either annotate the method with@Transactionalor explicitly save the entity when toggling the flag.Option A — make the method transactional:
- public PostResDTO.PostDTO getPost(Long postId, PrincipalDetails principalDetails) { + @Transactional + public PostResDTO.PostDTO getPost(Long postId, PrincipalDetails principalDetails) {Option B — explicitly persist when mutating:
if (!post.isRead()) { post.setIsRead(); + postRepository.save(post); }src/main/java/naughty/tuzamate/domain/post/service/command/PostCommandServiceImpl.java (3)
110-115: Guard against missing PostLike before deletionWrap the call to
findByPostAndUserin a null check and throw aCustomExceptionif no like exists (fallback to the generic NOT_FOUND code, since there’s no dedicated LIKE_NOT_FOUND constant).• File:
src/main/java/naughty/tuzamate/domain/post/service/command/PostCommandServiceImpl.java(around line 110)
• Replace:PostLike like = postLikeRepository.findByPostAndUser(post, user); postLikeRepository.delete(like); post.decreaseLike(); return "좋아요 취소";with:
PostLike like = postLikeRepository.findByPostAndUser(post, user); if (like == null) { // No domain-specific code exists for missing likes, so use generic 404 throw new CustomException(GeneralErrorCode.NOT_FOUND_404); } postLikeRepository.delete(like); post.decreaseLike(); return "좋아요 취소";
142-146: Guard against missing PostScrap before delete
postScrapRepository.findByPostAndUser(post, user)can returnnull, leading to an NPE on delete. Add a null check and throw a domain-specific exception:• In
PostCommandServiceImpl.java:- PostScrap scrap = postScrapRepository.findByPostAndUser(post, user); - postScrapRepository.delete(scrap); + PostScrap scrap = postScrapRepository.findByPostAndUser(post, user); + if (scrap == null) { + // Define POST_SCRAP_NOT_FOUND in PostErrorCode + throw new CustomException(PostErrorCode.POST_SCRAP_NOT_FOUND); + } + postScrapRepository.delete(scrap);• In
src/main/java/naughty/tuzamate/domain/post/code/PostErrorCode.java(add belowPOST_NOT_FOUND):public enum PostErrorCode implements BaseErrorCode { POST_NOT_FOUND(HttpStatus.NOT_FOUND, "POST404", "게시글이 존재하지 않습니다."), + POST_SCRAP_NOT_FOUND(HttpStatus.NOT_FOUND, "POST40402", "스크랩을 찾을 수 없습니다."), ; }
98-101: InitializelikeNumto Prevent NPEWe’ve confirmed that
likeNumis declared as aLongwithout a default value and isn’t set in the builder, so callingpost.increaseLike()can NPE whenlikeNumis null.Please add one of the following fixes:
- In Post.java (around line 33):
- @Column(name = "like_num") - private Long likeNum; + @Column(name = "like_num") + private Long likeNum = 0L;- Or in
PostConverter.toPost(...)(builder chain), explicitly set:return Post.builder() .title(reqDTO.title()) .content(reqDTO.content())
.likeNum(0L) .boardType(boardType) .user(user) … .build();
- (Optional) Make
increaseLikenull‐safe:public void increaseLike() { this.likeNum = (this.likeNum == null || this.likeNum == 0) ? 1 : this.likeNum + 1; }These changes will ensure
likeNumis nevernullwhen incrementing.
🧹 Nitpick comments (17)
src/main/java/naughty/tuzamate/domain/post/service/query/PostQueryServiceImpl.java (1)
5-5: Remove unused imports.
UserRepository,GeneralErrorCode, andjava.security.Principalare unused in this class.import naughty.tuzamate.auth.principal.PrincipalDetails; import naughty.tuzamate.domain.post.code.PostErrorCode; import naughty.tuzamate.domain.post.converter.PostConverter; import naughty.tuzamate.domain.post.dto.PostResDTO; import naughty.tuzamate.domain.post.entity.Post; import naughty.tuzamate.domain.post.enums.BoardType; import naughty.tuzamate.domain.post.repository.PostRepository; import naughty.tuzamate.domain.postLike.repository.PostLikeRepository; import naughty.tuzamate.domain.postScrap.repository.PostScrapRepository; -import naughty.tuzamate.domain.user.entity.User; -import naughty.tuzamate.domain.user.repository.UserRepository; -import naughty.tuzamate.global.error.GeneralErrorCode; import naughty.tuzamate.global.error.exception.CustomException; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.security.Principal; import java.util.List;Also applies to: 14-15, 23-23
src/main/java/naughty/tuzamate/domain/notification/service/NotificationService.java (1)
9-9: Remove unused import.
GeneralErrorCodeis no longer used in this class.-import naughty.tuzamate.global.error.GeneralErrorCode;src/main/java/naughty/tuzamate/domain/comment/service/query/CommentQueryServiceImpl.java (2)
3-5: Remove unused import(s).
GeneralErrorCodeis not used. Keep only what’s necessary.import lombok.RequiredArgsConstructor; import naughty.tuzamate.domain.comment.code.CommentErrorCode; import naughty.tuzamate.domain.comment.converter.CommentConverter; import naughty.tuzamate.domain.comment.dto.CommentResDTO; import naughty.tuzamate.domain.comment.entity.Comment; import naughty.tuzamate.domain.comment.repository.CommentRepository; -import naughty.tuzamate.global.error.GeneralErrorCode; import naughty.tuzamate.global.error.exception.CustomException;Also applies to: 9-9
47-47: Minor style nit: stray space after dot.Tighten
commentRepository. findChildrenInParentIds(...)to improve readability.- Map<Long, List<Comment>> childMap = commentRepository. findChildrenInParentIds(parentIds) + Map<Long, List<Comment>> childMap = commentRepository.findChildrenInParentIds(parentIds)src/main/java/naughty/tuzamate/domain/post/controller/PostController.java (4)
71-72: Consider switching update to PostSuccessCode for consistency.Keep controller responses consistent within the Post domain.
- return CustomResponse.onSuccess(GeneralSuccessCode.OK, resDTO); + return CustomResponse.onSuccess(PostSuccessCode.POST_OK, resDTO);
92-93: Optional: unify like/scrap endpoints to use PostSuccessCode as well.For domain consistency you can use PostSuccessCode for these endpoints too.
- return CustomResponse.onSuccess(GeneralSuccessCode.CREATED, message); + return CustomResponse.onSuccess(PostSuccessCode.POST_CREATED, message);- return CustomResponse.onSuccess(GeneralSuccessCode.OK, message); + return CustomResponse.onSuccess(PostSuccessCode.POST_OK, message);Also applies to: 103-104, 114-115, 125-126
11-11: Remove unused import.
naughty.tuzamate.domain.post.entity.Postisn’t used in this controller.-import naughty.tuzamate.domain.post.entity.Post;
82-83: PostController.deletePost – choose appropriate success codeConfirmed that
PostSuccessCode.DELETEDmaps toHttpStatus.NO_CONTENT (204)and thatCustomResponse.onSuccess(BaseSuccessCode)omits theresultfield when it’snull(due to@JsonInclude.NON_NULL). You can pick one of the following:• Option A (keep 200 OK and body):
--- a/src/main/java/naughty/tuzamate/domain/post/controller/PostController.java +++ b/src/main/java/naughty/tuzamate/domain/post/controller/PostController.java @@ -82,7 +82,7 @@ public class PostController { - return CustomResponse.onSuccess(GeneralSuccessCode.OK, resDTO); + return CustomResponse.onSuccess(PostSuccessCode.POST_OK, resDTO);• Option B (use 204 semantics, drop body, change return type):
--- a/src/main/java/naughty/tuzamate/domain/post/controller/PostController.java +++ b/src/main/java/naughty/tuzamate/domain/post/controller/PostController.java @@ -78,11 +78,9 @@ public class PostController { - public CustomResponse<PostResDTO.DeletePostResponseDTO> deletePost( + public CustomResponse<Void> deletePost( @PathVariable Long postId, PrincipalDetails principalDetails ) { - PostResDTO.DeletePostResponseDTO resDTO = postCommandService.deletePost(postId, principalDetails); - - return CustomResponse.onSuccess(GeneralSuccessCode.OK, resDTO); + postCommandService.deletePost(postId, principalDetails); + return CustomResponse.onSuccess(PostSuccessCode.DELETED, null); }src/main/java/naughty/tuzamate/domain/post/service/command/PostCommandServiceImpl.java (2)
52-54: Unify PrincipalDetails usage.You’re mixing
principalDetails.getUser().getId()here withprincipalDetails.getId()elsewhere. Pick one consistently (prefer the simplest accessor).- if (!post.getUser().getId().equals(principalDetails.getUser().getId())) { + if (!post.getUser().getId().equals(principalDetails.getId())) { throw new CustomException(GeneralErrorCode.FORBIDDEN_403); // 권한 없음 }
125-127: Define and use a scrap-specific error codeWe’ve confirmed there is no scrap-related constant in GeneralErrorCode, so ALREADY_LIKED is semantically incorrect here. Introduce a new enum value (e.g., ALREADY_SCRAPPED) and use it instead:
• Add to
src/main/java/naughty/tuzamate/global/error/GeneralErrorCode.java@@ enum GeneralErrorCode { ALREADY_LIKED(HttpStatus.BAD_REQUEST, "LIKE400", "이미 좋아요를 누르셨습니다"), + ALREADY_SCRAPPED(HttpStatus.BAD_REQUEST, "SCRAP400", "이미 스크랩하셨습니다");• Update in
src/main/java/naughty/tuzamate/domain/post/service/command/PostCommandServiceImpl.java- if (postScrapRepository.existsByPostAndUser(post, user)) { - throw new CustomException(GeneralErrorCode.ALREADY_LIKED); - } + if (postScrapRepository.existsByPostAndUser(post, user)) { + throw new CustomException(GeneralErrorCode.ALREADY_SCRAPPED); + }src/main/java/naughty/tuzamate/domain/comment/service/command/CommentCommandServiceImpl.java (4)
39-41: Use a user-domain error code when the authenticated user is missing.Throwing COMMENT_NOT_FOUND here is misleading. If the principal’s user cannot be loaded, prefer a user-domain error (or UNAUTHORIZED).
Apply this diff:
- User commentWriter = userRepository.findById(principalDetails.getId()) - .orElseThrow(() -> new CustomException(CommentErrorCode.COMMENT_NOT_FOUND)); + User commentWriter = userRepository.findById(principalDetails.getId()) + .orElseThrow(() -> new CustomException(UserErrorCode.USER_NOT_FOUND));Add the missing import outside this hunk:
import naughty.tuzamate.domain.user.error.UserErrorCode;
65-67: Guard FCM call against null/blank token and isolate external failures from DB transaction.Null/blank tokens or transient FCM failures can throw and roll back the whole transaction. Add a token guard and catch exceptions.
Apply this diff:
- fcmService.sendNotification(title, preview, postWriter.getFcmToken()); + String token = postWriter.getFcmToken(); + if (token != null && !token.trim().isEmpty()) { + try { + fcmService.sendNotification(title, preview, token); + } catch (Exception ex) { + // TODO: log and continue; avoid rolling back the DB transaction due to FCM failure + } + }Consider dispatching notifications via an after-commit event (e.g., @TransactionalEventListener(phase = AFTER_COMMIT)) or an outbox to fully decouple external I/O from the transactional boundary.
79-82: Apply the same FCM safety for replies; also guard against unexpected null parentWriter.Follow the same token/exception guards and add a null-check for parentWriter.
- if (parent != null && !parentWriter.getId().equals(commentWriter.getId())) { - fcmService.sendNotification(title, preview, parentWriter.getFcmToken()); + if (parent != null && parentWriter != null && !parentWriter.getId().equals(commentWriter.getId())) { + String token = parentWriter.getFcmToken(); + if (token != null && !token.trim().isEmpty()) { + try { + fcmService.sendNotification(title, preview, token); + } catch (Exception ex) { + // TODO: log and continue + } + }
39-41: Ensure consistent use of PrincipalDetails API.This class uses principalDetails.getId() (Line 39) and principalDetails.getUser().getId() (Line 106). Prefer one approach for consistency and to avoid subtle bugs if PrincipalDetails changes.
Also applies to: 106-108
src/main/java/naughty/tuzamate/domain/post/code/PostErrorCode.java (1)
1-17: Package naming consistency across domains.Existing enums live under “...domain..error” (e.g., UserErrorCode, ProfileErrorCode), while new ones are under “...domain..code”. Consider standardizing package naming for discoverability.
src/main/java/naughty/tuzamate/domain/comment/code/CommentErrorCode.java (2)
10-16: Consider adding an explicit code for invalid parent-child relation.You’re validating parent existence but not the parent-post relation in the enum layer. Adding a dedicated BAD_REQUEST code clarifies API contracts.
Example addition:
public enum CommentErrorCode implements BaseErrorCode { - COMMENT_NOT_FOUND(HttpStatus.NOT_FOUND, "COMMENT404", "댓글이 존재하지 않습니다."),; + COMMENT_NOT_FOUND(HttpStatus.NOT_FOUND, "COMMENT404", "댓글이 존재하지 않습니다."), + INVALID_PARENT_COMMENT(HttpStatus.BAD_REQUEST, "COMMENT40001", "부모 댓글과 게시글이 일치하지 않습니다."),; private final HttpStatus status; private final String code; private final String message; }
1-1: Package naming consistency.Same note as for PostErrorCode: consider consolidating under “...domain.comment.error” for uniformity with existing modules.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (10)
src/main/java/naughty/tuzamate/domain/comment/code/CommentErrorCode.java(1 hunks)src/main/java/naughty/tuzamate/domain/comment/service/command/CommentCommandServiceImpl.java(5 hunks)src/main/java/naughty/tuzamate/domain/comment/service/query/CommentQueryServiceImpl.java(2 hunks)src/main/java/naughty/tuzamate/domain/notification/code/NotificationErrorCode.java(1 hunks)src/main/java/naughty/tuzamate/domain/notification/service/NotificationService.java(4 hunks)src/main/java/naughty/tuzamate/domain/post/code/PostErrorCode.java(1 hunks)src/main/java/naughty/tuzamate/domain/post/code/PostSuccessCode.java(1 hunks)src/main/java/naughty/tuzamate/domain/post/controller/PostController.java(4 hunks)src/main/java/naughty/tuzamate/domain/post/service/command/PostCommandServiceImpl.java(7 hunks)src/main/java/naughty/tuzamate/domain/post/service/query/PostQueryServiceImpl.java(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (8)
src/main/java/naughty/tuzamate/domain/comment/service/query/CommentQueryServiceImpl.java (1)
src/main/java/naughty/tuzamate/domain/comment/service/query/CommentQueryService.java (2)
getComment(6-6)CommentQueryService(5-8)
src/main/java/naughty/tuzamate/domain/post/service/query/PostQueryServiceImpl.java (2)
src/main/java/naughty/tuzamate/domain/post/service/query/PostQueryService.java (1)
PostQueryService(7-11)src/main/java/naughty/tuzamate/domain/post/entity/Post.java (1)
Post(16-88)
src/main/java/naughty/tuzamate/domain/comment/code/CommentErrorCode.java (4)
src/main/java/naughty/tuzamate/domain/user/error/UserErrorCode.java (1)
AllArgsConstructor(8-29)src/main/java/naughty/tuzamate/global/error/GeneralErrorCode.java (1)
GeneralErrorCode(8-24)src/main/java/naughty/tuzamate/domain/profile/error/ProfileErrorCode.java (1)
AllArgsConstructor(9-21)src/main/java/naughty/tuzamate/domain/stock/error/StockErrorCode.java (1)
StockErrorCode(8-19)
src/main/java/naughty/tuzamate/domain/post/code/PostSuccessCode.java (3)
src/main/java/naughty/tuzamate/auth/success/AuthSuccessCode.java (1)
AuthSuccessCode(8-23)src/main/java/naughty/tuzamate/global/success/GeneralSuccessCode.java (1)
GeneralSuccessCode(7-24)src/main/java/naughty/tuzamate/global/success/BaseSuccessCode.java (2)
BaseSuccessCode(5-10)getStatus(7-7)
src/main/java/naughty/tuzamate/domain/post/controller/PostController.java (2)
src/main/java/naughty/tuzamate/domain/post/dto/PostResDTO.java (1)
PostResDTO(8-70)src/main/java/naughty/tuzamate/global/success/GeneralSuccessCode.java (1)
GeneralSuccessCode(7-24)
src/main/java/naughty/tuzamate/domain/post/code/PostErrorCode.java (4)
src/main/java/naughty/tuzamate/global/error/GeneralErrorCode.java (1)
GeneralErrorCode(8-24)src/main/java/naughty/tuzamate/domain/profile/error/ProfileErrorCode.java (1)
AllArgsConstructor(9-21)src/main/java/naughty/tuzamate/domain/user/error/UserErrorCode.java (1)
AllArgsConstructor(8-29)src/main/java/naughty/tuzamate/domain/stock/error/StockErrorCode.java (1)
StockErrorCode(8-19)
src/main/java/naughty/tuzamate/domain/notification/code/NotificationErrorCode.java (2)
src/main/java/naughty/tuzamate/domain/user/error/UserErrorCode.java (1)
AllArgsConstructor(8-29)src/main/java/naughty/tuzamate/global/error/BaseErrorCode.java (1)
BaseErrorCode(5-11)
src/main/java/naughty/tuzamate/domain/comment/service/command/CommentCommandServiceImpl.java (3)
src/main/java/naughty/tuzamate/domain/comment/converter/CommentConverter.java (1)
CommentConverter(13-79)src/main/java/naughty/tuzamate/domain/comment/repository/CommentRepository.java (1)
CommentRepository(12-35)src/main/java/naughty/tuzamate/domain/comment/entity/Comment.java (1)
Comment(12-50)
🔇 Additional comments (13)
src/main/java/naughty/tuzamate/domain/post/service/query/PostQueryServiceImpl.java (1)
37-37: Good shift to domain-specific error code (POST_NOT_FOUND).Swapping to PostErrorCode improves clarity and client-facing diagnosability.
src/main/java/naughty/tuzamate/domain/notification/service/NotificationService.java (3)
61-63: LGTM: Use of NotificationErrorCode.NOTIFICATION_NOT_FOUND.Consistent with the PR’s objective to use domain-specific codes.
70-72: LGTM: Domain-specific error code on updateIsRead().The transactional context is correctly present for the state mutation.
80-82: LGTM: Domain-specific error code on delete.Consistent and clear error semantics for notifications.
src/main/java/naughty/tuzamate/domain/comment/service/query/CommentQueryServiceImpl.java (1)
31-31: LGTM: Use of CommentErrorCode.COMMENT_NOT_FOUND.Appropriate domain-specific error handling.
src/main/java/naughty/tuzamate/domain/post/controller/PostController.java (3)
37-37: LGTM: POST_CREATED for createPost.Matches post domain success semantics.
48-48: LGTM: POST_OK for getPost.Consistent with new PostSuccessCode usage.
59-59: LGTM: POST_OK for getPostList.Aligns with domain-specific success codes.
src/main/java/naughty/tuzamate/domain/post/service/command/PostCommandServiceImpl.java (1)
50-50: LGTM: Migrated to PostErrorCode.POST_NOT_FOUND across command paths.Consistent domain-specific error semantics on not-found post across update/delete/like/scrap.
Also applies to: 69-69, 83-83, 106-106, 121-121, 138-138
src/main/java/naughty/tuzamate/domain/post/code/PostErrorCode.java (1)
1-17: LGTM on domain-specific error code.Clear enum with proper status/code/message. Adoption in services improves error specificity.
src/main/java/naughty/tuzamate/domain/comment/code/CommentErrorCode.java (1)
1-17: LGTM on comment not-found error code.Matches usage in services and aligns with the new pattern.
src/main/java/naughty/tuzamate/domain/notification/code/NotificationErrorCode.java (1)
1-10: LGTM otherwise.Enum structure and fields align with BaseErrorCode and other domains.
src/main/java/naughty/tuzamate/domain/post/code/PostSuccessCode.java (1)
1-21: LGTM on success codes and adoption plan.The enum is well-structured and mirrors GeneralSuccessCode semantics for posts.
| if (reqDTO.parentId() != null) { | ||
| parent = commentRepository.findById(reqDTO.parentId()) | ||
| .orElseThrow(() -> new CustomException(GeneralErrorCode.NOT_FOUND_404)); | ||
| .orElseThrow(() -> new CustomException(CommentErrorCode.COMMENT_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.
Validate that parent comment belongs to the same post to prevent cross-post replies.
Without this check, a reply can be attached to a parent from a different post, creating inconsistent data.
Apply this diff:
if (reqDTO.parentId() != null) {
parent = commentRepository.findById(reqDTO.parentId())
.orElseThrow(() -> new CustomException(CommentErrorCode.COMMENT_NOT_FOUND));
+ // Ensure the parent comment belongs to the same post
+ if (!parent.getPost().getId().equals(postId)) {
+ throw new CustomException(GeneralErrorCode.BAD_REQUEST_400);
+ }
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (reqDTO.parentId() != null) { | |
| parent = commentRepository.findById(reqDTO.parentId()) | |
| .orElseThrow(() -> new CustomException(GeneralErrorCode.NOT_FOUND_404)); | |
| .orElseThrow(() -> new CustomException(CommentErrorCode.COMMENT_NOT_FOUND)); | |
| } | |
| if (reqDTO.parentId() != null) { | |
| parent = commentRepository.findById(reqDTO.parentId()) | |
| .orElseThrow(() -> new CustomException(CommentErrorCode.COMMENT_NOT_FOUND)); | |
| // Ensure the parent comment belongs to the same post | |
| if (!parent.getPost().getId().equals(postId)) { | |
| throw new CustomException(GeneralErrorCode.BAD_REQUEST_400); | |
| } | |
| } |
🤖 Prompt for AI Agents
In
src/main/java/naughty/tuzamate/domain/comment/service/command/CommentCommandServiceImpl.java
around lines 47 to 50, after fetching the parent comment add a validation that
the parent’s postId matches reqDTO.postId(); if it does not, throw a suitable
CustomException (e.g. CommentErrorCode.INVALID_PARENT_COMMENT or another
existing error code for invalid parent) to prevent attaching replies to a parent
from a different post. Ensure the check runs only when parentId is non-null and
use the parent object's postId getter and reqDTO.postId() for comparison.
src/main/java/naughty/tuzamate/domain/notification/code/NotificationErrorCode.java
Outdated
Show resolved
Hide resolved
| POST_OK(HttpStatus.OK, "200", "게시글 조회에 성공했습니다."), | ||
|
|
||
| POST_CREATED(HttpStatus.CREATED, "201", "게시글이 생성되었습니다."), | ||
|
|
||
| DELETED(HttpStatus.NO_CONTENT, "204", "성공적으로 삭제되었습니다."); |
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.
💡 Verification agent
🧩 Analysis chain
Verify controller usage and 204 semantics.
Ensure PostController consistently returns PostSuccessCode and that 204 (DELETED) responses don’t include a body.
Run to verify usages and check for any remaining GeneralSuccessCode references in post controllers:
🏁 Script executed:
#!/bin/bash
# Find usages of PostSuccessCode and any remaining GeneralSuccessCode in post controllers
rg -n -C2 -g '!**/build/**' -g '!**/out/**' 'PostSuccessCode|GeneralSuccessCode' --type=java | rg -n -C2 'PostController|post'Length of output: 9693
Align PostController Success Codes & 204 Semantics
– The deletePost endpoint (PostController#deletePost, line 82) is still using GeneralSuccessCode.OK and returning a body. Replace it with:
• CustomResponse.onSuccess(PostSuccessCode.DELETED)
• Ensure the HTTP 204 response has no response body.
– The updatePost endpoint (line 71) uses GeneralSuccessCode.OK. Either switch to PostSuccessCode.POST_OK or add a dedicated POST_UPDATED code to the PostSuccessCode enum for clarity.
– Several other actions (postLike, deleteLike, postScrap, deleteScrap) also use GeneralSuccessCode; consider defining and using domain-specific success codes for likes/scraps or confirm that GeneralSuccessCode is acceptable.
Please update these endpoints to use the appropriate PostSuccessCode values and verify that 204 responses omit the body.
🤖 Prompt for AI Agents
In src/main/java/naughty/tuzamate/domain/post/code/PostSuccessCode.java around
lines 12 to 16, update and align controller usage: replace usages of
GeneralSuccessCode.OK in PostController#deletePost with
CustomResponse.onSuccess(PostSuccessCode.DELETED) and ensure the controller
returns an actual 204 with no body (e.g., ResponseEntity.noContent().build() or
equivalent), change PostController#updatePost to use a post-specific code by
either switching the response to PostSuccessCode.POST_OK or preferably add a new
enum constant POST_UPDATED in PostSuccessCode and use
CustomResponse.onSuccess(PostSuccessCode.POST_UPDATED); finally, review
endpoints postLike/deleteLike/postScrap/deleteScrap and either create and use
dedicated success codes in PostSuccessCode (e.g.,
LIKE_CREATED/LIKE_DELETED/SCRAP_CREATED/SCRAP_DELETED) or confirm
GeneralSuccessCode is acceptable, then replace usages accordingly so
domain-specific responses are consistent and 204 responses return no body.
📍 PR 타입 (하나 이상 선택)
🏷️ 관련 이슈
Close #78
📌 개요
🔁 변경 사항
📸 스크린샷
✅ 체크리스트
💡 추가 사항 (리뷰어가 참고해야 할 것)
Summary by CodeRabbit
New Features
Refactor