From 56e23728ebb87330582ea82ee93ca0ae63a07d31 Mon Sep 17 00:00:00 2001 From: plum-king Date: Tue, 16 May 2023 00:26:43 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=A2=8B=EC=95=84=EC=9A=94/=EC=A2=8B?= =?UTF-8?q?=EC=95=84=EC=9A=94=20=EC=B7=A8=EC=86=8C=20API=20=EB=B0=8F=20?= =?UTF-8?q?=EA=B4=80=EB=A0=A8=20=EC=9D=91=EB=8B=B5=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?#52?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ZatchController.java | 18 ++++++++---------- .../zatchserver/dto/PostZatchLikeReqDto.java | 12 ++++++++++++ ...chLikeRes.java => PostZatchLikeResDto.java} | 3 ++- 3 files changed, 22 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/zatch/zatchserver/dto/PostZatchLikeReqDto.java rename src/main/java/com/zatch/zatchserver/dto/{PostZatchLikeRes.java => PostZatchLikeResDto.java} (73%) 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; }