-
Notifications
You must be signed in to change notification settings - Fork 3
refactor: 피드 좋아요를 UUID 기반에서 카운터 방식으로 전환 #391
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,17 +1,12 @@ | ||||||||||||||||||||||||||||||||||
| package ddingdong.ddingdongBE.domain.feed.api; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| import static ddingdong.ddingdongBE.common.constant.ValidationConstants.UUID_V4_REGEXP; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| import io.swagger.v3.oas.annotations.Operation; | ||||||||||||||||||||||||||||||||||
| import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||||||||||||||||||||||||||||||||||
| import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||||||||||||||||||||||||||||||||||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||||||||||||||||||||||||||||||||||
| import jakarta.validation.constraints.Pattern; | ||||||||||||||||||||||||||||||||||
| import org.springframework.http.HttpStatus; | ||||||||||||||||||||||||||||||||||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||||||||||||||||||||||||||||||||||
| import org.springframework.web.bind.annotation.PathVariable; | ||||||||||||||||||||||||||||||||||
| import org.springframework.web.bind.annotation.PostMapping; | ||||||||||||||||||||||||||||||||||
| import org.springframework.web.bind.annotation.RequestHeader; | ||||||||||||||||||||||||||||||||||
| import org.springframework.web.bind.annotation.RequestMapping; | ||||||||||||||||||||||||||||||||||
| import org.springframework.web.bind.annotation.ResponseStatus; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
@@ -21,30 +16,10 @@ public interface FeedLikeApi { | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @Operation(summary = "피드 좋아요 API") | ||||||||||||||||||||||||||||||||||
| @ApiResponses({ | ||||||||||||||||||||||||||||||||||
| @ApiResponse(responseCode = "201", description = "피드 좋아요 성공"), | ||||||||||||||||||||||||||||||||||
| @ApiResponse(responseCode = "400", description = "유효하지 않은 UUID 형식"), | ||||||||||||||||||||||||||||||||||
| @ApiResponse(responseCode = "404", description = "피드 없음"), | ||||||||||||||||||||||||||||||||||
| @ApiResponse(responseCode = "409", description = "이미 좋아요한 피드") | ||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||
| @ResponseStatus(HttpStatus.CREATED) | ||||||||||||||||||||||||||||||||||
| @PostMapping("/{feedId}/likes") | ||||||||||||||||||||||||||||||||||
| void createLike( | ||||||||||||||||||||||||||||||||||
| @PathVariable("feedId") Long feedId, | ||||||||||||||||||||||||||||||||||
| @Pattern(regexp = UUID_V4_REGEXP, message = "유효하지 않은 UUID v4 형식입니다.") | ||||||||||||||||||||||||||||||||||
| @RequestHeader("X-Anonymous-UUID") String uuid | ||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @Operation(summary = "피드 좋아요 취소 API") | ||||||||||||||||||||||||||||||||||
| @ApiResponses({ | ||||||||||||||||||||||||||||||||||
| @ApiResponse(responseCode = "204", description = "피드 좋아요 취소 성공"), | ||||||||||||||||||||||||||||||||||
| @ApiResponse(responseCode = "400", description = "유효하지 않은 UUID 형식"), | ||||||||||||||||||||||||||||||||||
| @ApiResponse(responseCode = "404", description = "좋아요 기록 없음") | ||||||||||||||||||||||||||||||||||
| @ApiResponse(responseCode = "204", description = "피드 좋아요 성공"), | ||||||||||||||||||||||||||||||||||
| @ApiResponse(responseCode = "404", description = "피드 없음") | ||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||
|
Comment on lines
20
to
24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
📄 수정 제안 `@ApiResponses`({
`@ApiResponse`(responseCode = "204", description = "피드 좋아요 성공"),
- `@ApiResponse`(responseCode = "400", description = "좋아요 횟수 초과 (최대 100)")
+ `@ApiResponse`(responseCode = "400", description = "좋아요 횟수 초과 (최대 100)"),
+ `@ApiResponse`(responseCode = "404", description = "피드 없음")
})🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
| @ResponseStatus(HttpStatus.NO_CONTENT) | ||||||||||||||||||||||||||||||||||
| @DeleteMapping("/{feedId}/likes") | ||||||||||||||||||||||||||||||||||
| void deleteLike( | ||||||||||||||||||||||||||||||||||
| @PathVariable("feedId") Long feedId, | ||||||||||||||||||||||||||||||||||
| @Pattern(regexp = UUID_V4_REGEXP, message = "유효하지 않은 UUID v4 형식입니다.") | ||||||||||||||||||||||||||||||||||
| @RequestHeader("X-Anonymous-UUID") String uuid | ||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||
| @PostMapping("/{feedId}/likes") | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| @ApiResponse(responseCode = "204", description = "피드 좋아요 성공"), | |
| @ApiResponse(responseCode = "404", description = "피드 없음") | |
| }) | |
| @ResponseStatus(HttpStatus.NO_CONTENT) | |
| @DeleteMapping("/{feedId}/likes") | |
| void deleteLike( | |
| @PathVariable("feedId") Long feedId, | |
| @Pattern(regexp = UUID_V4_REGEXP, message = "유효하지 않은 UUID v4 형식입니다.") | |
| @RequestHeader("X-Anonymous-UUID") String uuid | |
| ); | |
| @PostMapping("/{feedId}/likes") | |
| `@ApiResponse`(responseCode = "201", description = "피드 좋아요 성공"), | |
| `@ApiResponse`(responseCode = "404", description = "피드 없음") | |
| }) | |
| `@ResponseStatus`(HttpStatus.CREATED) | |
| `@PostMapping`("/{feedId}/likes") |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/main/java/ddingdong/ddingdongBE/domain/feed/api/FeedLikeApi.java` around
lines 19 - 23, The POST endpoint annotated with `@PostMapping`("/{feedId}/likes")
currently uses `@ResponseStatus`(HttpStatus.NO_CONTENT) and an `@ApiResponse` with
responseCode "204"; update these to follow project conventions by replacing
HttpStatus.NO_CONTENT with HttpStatus.CREATED and changing the ApiResponse
responseCode/description to "201" (피드 좋아요 성공) so the method (FeedLikeApi POST
/{feedId}/likes) returns 201 Created instead of 204 No Content.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,18 @@ | ||
| package ddingdong.ddingdongBE.domain.feed.controller; | ||
|
|
||
| import ddingdong.ddingdongBE.domain.feed.api.FeedLikeApi; | ||
| import ddingdong.ddingdongBE.domain.feed.service.FeedLikeService; | ||
| import ddingdong.ddingdongBE.domain.feed.service.FeedService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.validation.annotation.Validated; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @Validated | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class FeedLikeController implements FeedLikeApi { | ||
|
|
||
| private final FeedLikeService feedLikeService; | ||
| private final FeedService feedService; | ||
|
|
||
| @Override | ||
| public void createLike(Long feedId, String uuid) { | ||
| feedLikeService.create(feedId, uuid); | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteLike(Long feedId, String uuid) { | ||
| feedLikeService.delete(feedId, uuid); | ||
| public void createLike(Long feedId) { | ||
| feedService.incrementLikeCount(feedId); | ||
| } | ||
| } |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
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.
@ApiResponse(responseCode = "404")가 실제 동작과 불일치합니다.FeedLikeControllerE2ETest의createLike_nonExistentFeed(feedId=999999L)가 204를 기대하고 있어, 실제 구현은 존재하지 않는 피드에 대해 404를 반환하지 않음을 확인할 수 있습니다.FeedLikeController가feedService.incrementLikeCount(feedId)를 호출할 뿐, 피드 존재 여부를 검증하지 않기 때문입니다.아래 두 방법 중 하나를 선택해야 합니다:
FeedService.incrementLikeCount에서 피드 존재 여부를 검증하고 없으면FeedException.FeedNotFoundException을 throw → 404 반환@ApiResponse를 제거하고, 존재하지 않는 피드 요청을 조용히 무시하는 현 동작을 명확히 문서화현재 상태는 API 계약과 실제 동작이 다르며, 클라이언트 오류 처리를 어렵게 만듭니다.
🤖 Prompt for AI Agents