diff --git a/src/main/java/com/zatch/zatchserver/controller/ZatchController.java b/src/main/java/com/zatch/zatchserver/controller/ZatchController.java index 74236d6..0f36946 100644 --- a/src/main/java/com/zatch/zatchserver/controller/ZatchController.java +++ b/src/main/java/com/zatch/zatchserver/controller/ZatchController.java @@ -53,27 +53,25 @@ public void makeNewZatch(@RequestBody PostZatchReq postZatchReq) { } @ApiResponses(value = { - @ApiResponse(code = 200, message = "Success", response = PostZatchLikeRes.class, + @ApiResponse(code = 200, message = "Success", response = PostZatchLikeResDto.class, examples = @Example(@ExampleProperty(value = "{'property1': 'value1', 'property2': 'value2'}", mediaType = MediaType.APPLICATION_JSON_VALUE))) }) @PostMapping("/{zatchId}/likes") @ApiOperation(value = "좋아요", notes = "좋아요") - public PostZatchLikeRes postZatchlike(HttpServletRequest request, @PathVariable("zatchId") Long zatchId) { - Long userId = (Long) request.getAttribute("userId"); - Integer likeCount = postService.makeZatchLike(userId, zatchId); - return new PostZatchLikeRes(zatchId, likeCount); + public PostZatchLikeResDto postZatchlike(@PathVariable("zatchId") Long zatchId, @RequestBody PostZatchLikeReqDto postZatchLikeReqDto) { + Integer likeCount = postService.makeZatchLike(postZatchLikeReqDto.getUserId(), zatchId); + return new PostZatchLikeResDto(zatchId, likeCount, Boolean.TRUE); //좋아요 시, True 값 } @ApiResponses(value = { - @ApiResponse(code = 200, message = "Success", response = PostZatchLikeRes.class, + @ApiResponse(code = 200, message = "Success", response = PostZatchLikeResDto.class, examples = @Example(@ExampleProperty(value = "{'property1': 'value1', 'property2': 'value2'}", mediaType = MediaType.APPLICATION_JSON_VALUE))) }) @DeleteMapping("/{zatchId}/dislikes") @ApiOperation(value = "좋아요 취소", notes = "좋아요 취소") - public PostZatchLikeRes postZatchDislike(HttpServletRequest request, @PathVariable("zatchId") Long zatchId) { - Long userId = (Long) request.getAttribute("userId"); - Integer likeCount = postService.makeZatchDisLike(userId, zatchId); - return new PostZatchLikeRes(zatchId, likeCount); + public PostZatchLikeResDto postZatchDislike(@PathVariable("zatchId") Long zatchId, @RequestBody PostZatchLikeReqDto postZatchLikeReqDto) { + Integer likeCount = postService.makeZatchDisLike(postZatchLikeReqDto.getUserId(), zatchId); + return new PostZatchLikeResDto(zatchId, likeCount, Boolean.FALSE); //취소 시, False 값 } @ApiResponses(value = { diff --git a/src/main/java/com/zatch/zatchserver/dto/PostZatchLikeReqDto.java b/src/main/java/com/zatch/zatchserver/dto/PostZatchLikeReqDto.java new file mode 100644 index 0000000..d21ea81 --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/dto/PostZatchLikeReqDto.java @@ -0,0 +1,12 @@ +package com.zatch.zatchserver.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class PostZatchLikeReqDto { + private Long userId; +} diff --git a/src/main/java/com/zatch/zatchserver/dto/PostZatchLikeRes.java b/src/main/java/com/zatch/zatchserver/dto/PostZatchLikeResDto.java similarity index 73% rename from src/main/java/com/zatch/zatchserver/dto/PostZatchLikeRes.java rename to src/main/java/com/zatch/zatchserver/dto/PostZatchLikeResDto.java index f603414..ebe5d80 100644 --- a/src/main/java/com/zatch/zatchserver/dto/PostZatchLikeRes.java +++ b/src/main/java/com/zatch/zatchserver/dto/PostZatchLikeResDto.java @@ -5,7 +5,8 @@ @Getter @AllArgsConstructor -public class PostZatchLikeRes { +public class PostZatchLikeResDto { private Long zatchId; private Integer likeCount; + private Boolean isLiked; }