From b3e65412319561cfde4d0c9af84335dd239c23bb Mon Sep 17 00:00:00 2001 From: eekrwl Date: Fri, 8 Nov 2024 19:09:39 +0900 Subject: [PATCH] =?UTF-8?q?KKUMI-118=20[FEATURE]=20#73=20postId=20?= =?UTF-8?q?=EC=97=86=EC=9D=B4=20=EC=A2=8B=EC=95=84=EC=9A=94=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=EC=8B=9C=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존: 500 서버 에러로 내려감 변경후: postId가 null이면 안된다는 메시지 내려감 --- .../com/swmarastro/mykkumiserver/like/LikesController.java | 5 +++-- .../com/swmarastro/mykkumiserver/like/dto/LikesRequest.java | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/swmarastro/mykkumiserver/like/LikesController.java b/src/main/java/com/swmarastro/mykkumiserver/like/LikesController.java index 3ebbe96..93e92ec 100644 --- a/src/main/java/com/swmarastro/mykkumiserver/like/LikesController.java +++ b/src/main/java/com/swmarastro/mykkumiserver/like/LikesController.java @@ -4,6 +4,7 @@ import com.swmarastro.mykkumiserver.auth.annotation.RequiresLogin; import com.swmarastro.mykkumiserver.like.dto.LikesRequest; import com.swmarastro.mykkumiserver.user.User; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; @@ -20,14 +21,14 @@ public class LikesController { @RequiresLogin @PostMapping("/like") - public ResponseEntity like(@Login User user, @RequestBody LikesRequest request) { + public ResponseEntity like(@Login User user, @Valid @RequestBody LikesRequest request) { likeService.like(user, request.getPostId()); return ResponseEntity.ok().build(); } @RequiresLogin @PostMapping("/unlike") - public ResponseEntity unlike(@Login User user, @RequestBody LikesRequest request) { + public ResponseEntity unlike(@Login User user, @Valid @RequestBody LikesRequest request) { likeService.unlike(user, request.getPostId()); return ResponseEntity.ok().build(); } diff --git a/src/main/java/com/swmarastro/mykkumiserver/like/dto/LikesRequest.java b/src/main/java/com/swmarastro/mykkumiserver/like/dto/LikesRequest.java index e20c40b..d9e8c1a 100644 --- a/src/main/java/com/swmarastro/mykkumiserver/like/dto/LikesRequest.java +++ b/src/main/java/com/swmarastro/mykkumiserver/like/dto/LikesRequest.java @@ -1,9 +1,11 @@ package com.swmarastro.mykkumiserver.like.dto; +import jakarta.validation.constraints.NotNull; import lombok.Getter; @Getter public class LikesRequest { + @NotNull private Long postId; }