From bcdae12cf08733819f05e723770701fb42429124 Mon Sep 17 00:00:00 2001 From: Yeseo Date: Tue, 19 Mar 2024 21:02:26 +0900 Subject: [PATCH 1/2] feat: Add exception handling (#19) Co-authored-by: chaeeun-Han --- src/main/java/com/beotkkot/qtudy/common/ResponseCode.java | 1 + src/main/java/com/beotkkot/qtudy/common/ResponseMessage.java | 1 + .../beotkkot/qtudy/dto/response/posts/PostsResponseDto.java | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/src/main/java/com/beotkkot/qtudy/common/ResponseCode.java b/src/main/java/com/beotkkot/qtudy/common/ResponseCode.java index 74b65fb..eb5f033 100644 --- a/src/main/java/com/beotkkot/qtudy/common/ResponseCode.java +++ b/src/main/java/com/beotkkot/qtudy/common/ResponseCode.java @@ -8,6 +8,7 @@ public interface ResponseCode { String VALIDATION_FAILED = "VF"; String NOT_EXISTED_USER = "NEU"; String NOT_EXISTED_POST = "NEP"; + String NOT_EXISTED_COMMENT = "NEC"; // HTTP Status 401 String SIGN_IN_FAIL = "SF"; diff --git a/src/main/java/com/beotkkot/qtudy/common/ResponseMessage.java b/src/main/java/com/beotkkot/qtudy/common/ResponseMessage.java index e7a8cde..6985937 100644 --- a/src/main/java/com/beotkkot/qtudy/common/ResponseMessage.java +++ b/src/main/java/com/beotkkot/qtudy/common/ResponseMessage.java @@ -8,6 +8,7 @@ public interface ResponseMessage { String VALIDATION_FAILED = "Validation Failed."; String NOT_EXISTED_USER = "This user does not exist."; String NOT_EXISTED_POST = "This post does not exist."; + String NOT_EXISTED_COMMENT = "This comment does not exist."; // HTTP Status 401 String SIGN_IN_FAIL = "Login information mismatch."; diff --git a/src/main/java/com/beotkkot/qtudy/dto/response/posts/PostsResponseDto.java b/src/main/java/com/beotkkot/qtudy/dto/response/posts/PostsResponseDto.java index b8fe771..f70b350 100644 --- a/src/main/java/com/beotkkot/qtudy/dto/response/posts/PostsResponseDto.java +++ b/src/main/java/com/beotkkot/qtudy/dto/response/posts/PostsResponseDto.java @@ -34,4 +34,9 @@ public static ResponseEntity noPermission() { return ResponseEntity.status(HttpStatus.FORBIDDEN).body(result); } + public static ResponseEntity noAuthentication() { + ResponseDto result = new ResponseDto(ResponseCode.AUTHORIZATION_FAIL, ResponseMessage.AUTHORIZATION_FAIL); + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(result); + } + } From 9c0c7301b852e1bb80be03db5f6b9581c3068c46 Mon Sep 17 00:00:00 2001 From: Yeseo Date: Tue, 19 Mar 2024 21:06:46 +0900 Subject: [PATCH 2/2] feat: Add PostsRepository code (#19) Co-authored-by: chaeeun-Han --- .../com/beotkkot/qtudy/repository/posts/PostsRepository.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/beotkkot/qtudy/repository/posts/PostsRepository.java b/src/main/java/com/beotkkot/qtudy/repository/posts/PostsRepository.java index 4ba46bd..ab3a0d9 100644 --- a/src/main/java/com/beotkkot/qtudy/repository/posts/PostsRepository.java +++ b/src/main/java/com/beotkkot/qtudy/repository/posts/PostsRepository.java @@ -20,6 +20,8 @@ public interface PostsRepository extends JpaRepository { Posts findByPostId(Long postId); + List findAllByPostId(Long postId); + @Query("SELECT p FROM Posts p WHERE p.postId IN :postIds") List findByPostIds(@Param("postIds") List postIds); }