From 799ff4da7b658ffd0671385d6cbce08dc0d1dc8c Mon Sep 17 00:00:00 2001 From: Ju Date: Tue, 23 May 2023 22:48:09 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[Feat]=20=EA=B8=B0=EB=85=90=EC=9D=BC=20API?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84=20-=20#29?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/favor/favor/user/UserController.java | 34 +++++++++++++++++-- .../com/favor/favor/user/UserService.java | 12 +++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/favor/src/main/java/com/favor/favor/user/UserController.java b/favor/src/main/java/com/favor/favor/user/UserController.java index 5aa278a..97f0644 100644 --- a/favor/src/main/java/com/favor/favor/user/UserController.java +++ b/favor/src/main/java/com/favor/favor/user/UserController.java @@ -1,6 +1,7 @@ package com.favor.favor.user; +import com.favor.favor.anniversary.AnniversaryResponseDto; import com.favor.favor.common.DefaultResponseDto; import com.favor.favor.common.enums.Category; import com.favor.favor.common.enums.Emotion; @@ -353,7 +354,7 @@ public ResponseEntity> readGiftList( @ApiOperation("회원의 친구 전체 조회") @ApiResponses(value={ @ApiResponse(code = 200, - message = "FRIENDSS_FOUND", + message = "FRIENDS_FOUND", response = UserResponseDto.class), @ApiResponse(code = 401, message = "UNAUTHORIZED_USER"), @@ -373,12 +374,41 @@ public ResponseEntity> readFriendList(@PathVariable L return ResponseEntity.status(200) .body(DefaultResponseDto.builder() - .responseCode("FRIENDSS_FOUND") + .responseCode("FRIENDS_FOUND") .responseMessage("회원의 친구 전체 조회 완료") .data(friends) .build()); } + @ApiOperation("회원의 기념일 전체 조회") + @ApiResponses(value={ + @ApiResponse(code = 200, + message = "ANNIVERSARY_FOUND", + response = UserResponseDto.class), + @ApiResponse(code = 401, + message = "UNAUTHORIZED_USER"), + @ApiResponse(code = 404, + message = "USER_NOT_FOUND"), + @ApiResponse(code = 500, + message = "SERVER_ERROR") + }) + @ResponseStatus(HttpStatus.OK) + @Transactional + @GetMapping("/anniversary-list/{userNo}") + public ResponseEntity> readAnniversaryList(@PathVariable Long userNo){ + + userService.isExistingUserNo(userNo); + + List friends = userService.readAnniversaryList(userNo); + + return ResponseEntity.status(200) + .body(DefaultResponseDto.builder() + .responseCode("ANNIVERSARY_FOUND") + .responseMessage("회원의 기념일 전체 조회 완료") + .data(friends) + .build()); + } + @ApiOperation("전체 회원 조회") @ApiResponses(value={ diff --git a/favor/src/main/java/com/favor/favor/user/UserService.java b/favor/src/main/java/com/favor/favor/user/UserService.java index af0dab2..1497fcf 100644 --- a/favor/src/main/java/com/favor/favor/user/UserService.java +++ b/favor/src/main/java/com/favor/favor/user/UserService.java @@ -162,6 +162,18 @@ public List readReminderList(Long userNo){ return r_List; } + @Transactional + public List readAnniversaryList(Long userNo){ + User user = findUserByUserNo(userNo); + + List r_List = new ArrayList<>(); + for(Anniversary r : user.getAnniversaryList()){ + AnniversaryResponseDto dto = new AnniversaryResponseDto(r); + r_List.add(dto); + } + return r_List; + } + @Transactional public List readGiftList(Long userNo){ User user = findUserByUserNo(userNo); From 101927d0504ec524d5521815c33f1ada52c15ab6 Mon Sep 17 00:00:00 2001 From: Ju Date: Tue, 23 May 2023 23:37:30 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[Fix]=20CustomAuthenticationEntryPoint.java?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- favor/build.gradle | 1 + .../CustomAuthenticationEntryPoint.java | 26 +++++++------------ 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/favor/build.gradle b/favor/build.gradle index 6ee1960..b1bd9c4 100644 --- a/favor/build.gradle +++ b/favor/build.gradle @@ -26,6 +26,7 @@ dependencies { implementation 'io.springfox:springfox-swagger-ui:2.9.2' implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'com.googlecode.json-simple:json-simple:1.1.1' testImplementation 'org.springframework.boot:spring-boot-starter-test' compileOnly 'org.projectlombok:lombok' diff --git a/favor/src/main/java/com/favor/favor/exception/CustomAuthenticationEntryPoint.java b/favor/src/main/java/com/favor/favor/exception/CustomAuthenticationEntryPoint.java index d6ed218..24f73a3 100644 --- a/favor/src/main/java/com/favor/favor/exception/CustomAuthenticationEntryPoint.java +++ b/favor/src/main/java/com/favor/favor/exception/CustomAuthenticationEntryPoint.java @@ -1,39 +1,31 @@ package com.favor.favor.exception; -import com.fasterxml.jackson.databind.ObjectMapper; +import org.json.simple.JSONObject; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.AuthenticationEntryPoint; -import org.springframework.stereotype.Component; -import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; -import java.io.OutputStream; -import static com.favor.favor.exception.ExceptionCode.UNAUTHORIZED_USER; - -@Component("customAuthenticationEntryPoint") public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint { - private static CustomException errorResponse = - new CustomException(new RuntimeException(), UNAUTHORIZED_USER); - @Override public void commence(HttpServletRequest request, HttpServletResponse response, - AuthenticationException ex) throws IOException, ServletException { + AuthenticationException ex) throws IOException { // [commence] 인증 실패로 response.sendError 발생 - ObjectMapper objectMapper = new ObjectMapper(); - response.setStatus(401); response.setContentType("application/json"); response.setCharacterEncoding("utf-8"); - try (OutputStream os = response.getOutputStream()) { - objectMapper.writeValue(os, errorResponse); - os.flush(); - } + response.setStatus(401); + + JSONObject responseJson = new JSONObject(); + responseJson.put("ResponseCode", "AUTHENTICATION_FAILED"); + responseJson.put("ResponseMessage", "인증에 실패하였습니다."); + + response.getWriter().print(responseJson); } } \ No newline at end of file