-
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 all commits
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,15 @@ | ||
| package ddingdong.ddingdongBE.domain.feed.api; | ||
|
|
||
| import static ddingdong.ddingdongBE.common.constant.ValidationConstants.UUID_V4_REGEXP; | ||
|
|
||
| import ddingdong.ddingdongBE.domain.feed.controller.dto.request.CreateFeedLikeRequest; | ||
| 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 jakarta.validation.Valid; | ||
| 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.PatchMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
|
||
|
|
@@ -21,30 +19,13 @@ 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 = "400", description = "좋아요 횟수 초과 (최대 100)") | ||
| }) | ||
|
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( | ||
| @PatchMapping("/{feedId}/likes") | ||
| void createLike( | ||
| @PathVariable("feedId") Long feedId, | ||
| @Pattern(regexp = UUID_V4_REGEXP, message = "유효하지 않은 UUID v4 형식입니다.") | ||
| @RequestHeader("X-Anonymous-UUID") String uuid | ||
| @RequestBody @Valid CreateFeedLikeRequest request | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,20 @@ | ||
| 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.controller.dto.request.CreateFeedLikeRequest; | ||
| 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, CreateFeedLikeRequest request) { | ||
| feedService.getById(feedId); | ||
| feedService.addLikeCount(feedId, request.count()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package ddingdong.ddingdongBE.domain.feed.controller.dto.request; | ||
|
|
||
| import jakarta.validation.constraints.Max; | ||
| import jakarta.validation.constraints.Min; | ||
| import jakarta.validation.constraints.NotNull; | ||
|
|
||
| public record CreateFeedLikeRequest( | ||
| @NotNull(message = "count는 null이 될 수 없습니다.") | ||
| @Min(value = 1, message = "count는 1 이상이어야 합니다.") | ||
| @Max(value = 100, message = "count는 100 이하여야 합니다.") | ||
| Integer count | ||
| ) { | ||
|
|
||
| } |
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(400)설명이 유효성 검사 케이스를 일부만 기술합니다현재 설명
"좋아요 횟수 초과 (최대 100)"은@Max위반만 설명하지만,count < 1(@Min위반)이나count = null(@NotNull위반) 시에도 동일하게 400이 반환됩니다.✏️ 수정 제안
📝 Committable suggestion
🤖 Prompt for AI Agents