From d440dd2c376769ad38d93695a90e14261cf016e7 Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 28 Nov 2024 14:27:22 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[refactor]=20UserId=20->=20AuthUser=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EB=B0=9B=EB=8A=94=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/controller/CommentControllerApi.java | 9 ++++----- .../budgetbuddies/domain/faq/controller/FaqApi.java | 9 +++------ .../domain/faq/controller/FaqController.java | 8 ++++---- .../domain/mainpage/controller/MainPageApi.java | 12 +++--------- .../mainpage/controller/MainPageController.java | 10 ++++------ 5 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java index b8279e41..69336b43 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentControllerApi.java @@ -5,7 +5,8 @@ import com.bbteam.budgetbuddies.domain.comment.dto.CommentRequestDto; import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; import com.bbteam.budgetbuddies.domain.comment.validation.ExistComment; -import com.bbteam.budgetbuddies.domain.user.validation.ExistUser; +import com.bbteam.budgetbuddies.domain.user.dto.UserDto; +import com.bbteam.budgetbuddies.global.security.utils.AuthUser; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; @@ -24,12 +25,11 @@ public interface CommentControllerApi { @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), }) @Parameters({ - @Parameter(name = "userId", description = "현재 댓글을 다는 유저 id입니다. parameter"), @Parameter(name = "discountInfoId", description = "댓글을 다는 할인 정보 게시글 id입니다. requestBody"), @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), }) ApiResponse saveDiscountInfoComment( - @ExistUser Long userId, + @AuthUser UserDto.AuthUserDto userDto, CommentRequestDto.DiscountInfoCommentRequestDto discountInfoCommentRequestDto); @@ -51,12 +51,11 @@ ApiResponse> findAllByDi @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), }) @Parameters({ - @Parameter(name = "userId", description = "현재 댓글을 다는 유저 id입니다. parameter"), @Parameter(name = "supportInfoId", description = "댓글을 다는 지원 정보 게시글 id입니다. requestBody"), @Parameter(name = "content", description = "댓글 내용입니다. requestBody"), }) ApiResponse saveSupportInfoComment( - @ExistUser Long userId, + @AuthUser UserDto.AuthUserDto userDto, CommentRequestDto.SupportInfoCommentRequestDto supportInfoCommentRequestDto); @Operation(summary = "[User] 특정 지원 정보 게시글의 댓글 조회하기", description = "특정 지원 정보 게시글의 댓글을 가져오는 API입니다.") diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/faq/controller/FaqApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/faq/controller/FaqApi.java index 8485960f..1f2d5fb7 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/faq/controller/FaqApi.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/faq/controller/FaqApi.java @@ -4,7 +4,8 @@ import com.bbteam.budgetbuddies.apiPayload.ApiResponse; import com.bbteam.budgetbuddies.domain.faq.dto.FaqRequestDto; import com.bbteam.budgetbuddies.domain.faq.validation.ExistFaq; -import com.bbteam.budgetbuddies.domain.user.validation.ExistUser; +import com.bbteam.budgetbuddies.domain.user.dto.UserDto; +import com.bbteam.budgetbuddies.global.security.utils.AuthUser; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; @@ -44,11 +45,7 @@ public interface FaqApi { @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), }) - @Parameters({ - @Parameter(name = "userId", description = "FAQ를 사용하는 userId입니다.. pathVariable", in = ParameterIn.QUERY), - } - ) - ApiResponse postFaq(@ExistUser @RequestParam Long userId, + ApiResponse postFaq(@AuthUser UserDto.AuthUserDto userDto, @Valid @org.springframework.web.bind.annotation.RequestBody FaqRequestDto.FaqPostRequest dto); @Operation(summary = "[Admin] FAQ 조회 API", description = "FAQ를 조회하는 API입니다." ) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/faq/controller/FaqController.java b/src/main/java/com/bbteam/budgetbuddies/domain/faq/controller/FaqController.java index c15fe5d2..5c0b1a1b 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/faq/controller/FaqController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/faq/controller/FaqController.java @@ -5,9 +5,9 @@ import com.bbteam.budgetbuddies.domain.faq.dto.FaqResponseDto; import com.bbteam.budgetbuddies.domain.faq.service.FaqService; import com.bbteam.budgetbuddies.domain.faq.validation.ExistFaq; -import com.bbteam.budgetbuddies.domain.user.validation.ExistUser; +import com.bbteam.budgetbuddies.domain.user.dto.UserDto; +import com.bbteam.budgetbuddies.global.security.utils.AuthUser; import jakarta.validation.Valid; -import jakarta.validation.constraints.Null; import lombok.RequiredArgsConstructor; import org.springdoc.core.annotations.ParameterObject; import org.springframework.data.domain.Page; @@ -26,9 +26,9 @@ public class FaqController implements FaqApi{ @Override @PostMapping("") - public ApiResponse postFaq(@ExistUser @RequestParam Long userId, + public ApiResponse postFaq(@AuthUser UserDto.AuthUserDto userDto, @Valid @RequestBody FaqRequestDto.FaqPostRequest dto) { - return ApiResponse.onSuccess(faqService.postFaq(dto, userId)); + return ApiResponse.onSuccess(faqService.postFaq(dto, userDto.getId())); } @Override diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/controller/MainPageApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/controller/MainPageApi.java index 757722f8..9caf9f26 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/controller/MainPageApi.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/controller/MainPageApi.java @@ -2,13 +2,10 @@ import com.bbteam.budgetbuddies.apiPayload.ApiResponse; import com.bbteam.budgetbuddies.domain.mainpage.dto.MainPageResponseDto; -import com.bbteam.budgetbuddies.domain.user.validation.ExistUser; +import com.bbteam.budgetbuddies.domain.user.dto.UserDto; +import com.bbteam.budgetbuddies.global.security.utils.AuthUser; import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.responses.ApiResponses; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RequestParam; public interface MainPageApi { @@ -16,8 +13,5 @@ public interface MainPageApi { @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), }) - @Parameters({ - @Parameter(name = "userId", description = "현재 데이터를 요청하는 사용자입니다. parameter"), - }) - ApiResponse getMainPage(@RequestParam("userId") @ExistUser Long userId); + ApiResponse getMainPage(@AuthUser UserDto.AuthUserDto userDto); } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/controller/MainPageController.java b/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/controller/MainPageController.java index 534bb66a..1be20827 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/controller/MainPageController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/mainpage/controller/MainPageController.java @@ -3,13 +3,11 @@ import com.bbteam.budgetbuddies.apiPayload.ApiResponse; import com.bbteam.budgetbuddies.domain.mainpage.dto.MainPageResponseDto; import com.bbteam.budgetbuddies.domain.mainpage.service.MainPageService; -import com.bbteam.budgetbuddies.domain.user.validation.ExistUser; +import com.bbteam.budgetbuddies.domain.user.dto.UserDto; +import com.bbteam.budgetbuddies.global.security.utils.AuthUser; import lombok.RequiredArgsConstructor; -import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController @@ -21,8 +19,8 @@ public class MainPageController implements MainPageApi{ @GetMapping("/main") public ApiResponse getMainPage - (@RequestParam("userId") @ExistUser Long userId) { - MainPageResponseDto mainPage = mainPageService.getMainPage(userId); + (@AuthUser UserDto.AuthUserDto userDto) { + MainPageResponseDto mainPage = mainPageService.getMainPage(userDto.getId()); return ApiResponse.onSuccess(mainPage); } } From 2e3fd217e1f84a52a8cc5233a2881858b3e7965b Mon Sep 17 00:00:00 2001 From: wnd01jun Date: Thu, 28 Nov 2024 14:27:44 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[refactor]=20UserId=20->=20AuthUser=20?= =?UTF-8?q?=EC=9C=A0=EC=A0=80=20=EB=B0=9B=EB=8A=94=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/comment/controller/CommentController.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java index 3d96a560..ece131ec 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/comment/controller/CommentController.java @@ -5,7 +5,8 @@ import com.bbteam.budgetbuddies.domain.comment.dto.CommentResponseDto; import com.bbteam.budgetbuddies.domain.comment.service.CommentService; import com.bbteam.budgetbuddies.domain.comment.validation.ExistComment; -import com.bbteam.budgetbuddies.domain.user.validation.ExistUser; +import com.bbteam.budgetbuddies.domain.user.dto.UserDto; +import com.bbteam.budgetbuddies.global.security.utils.AuthUser; import jakarta.validation.Valid; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.data.domain.Page; @@ -36,9 +37,9 @@ public CommentController(CommentService saveDiscountInfoComment( - @RequestParam("userId") @ExistUser Long userId, + @AuthUser UserDto.AuthUserDto userDto, @RequestBody CommentRequestDto.DiscountInfoCommentRequestDto discountInfoCommentRequestDto){ - CommentResponseDto.DiscountInfoCommentResponseDto dto = discountCommentService.saveComment(userId, discountInfoCommentRequestDto); + CommentResponseDto.DiscountInfoCommentResponseDto dto = discountCommentService.saveComment(userDto.getId(), discountInfoCommentRequestDto); return ApiResponse.onSuccess(dto); } @@ -54,9 +55,9 @@ public ApiResponse> find @PostMapping("/supports/comments") public ApiResponse saveSupportInfoComment( - @RequestParam("userId") @ExistUser Long userId, + @AuthUser UserDto.AuthUserDto userDto, @RequestBody CommentRequestDto.SupportInfoCommentRequestDto supportInfoCommentRequestDto){ - CommentResponseDto.SupportInfoCommentResponseDto dto = supportCommentService.saveComment(userId, supportInfoCommentRequestDto); + CommentResponseDto.SupportInfoCommentResponseDto dto = supportCommentService.saveComment(userDto.getId(), supportInfoCommentRequestDto); return ApiResponse.onSuccess(dto); }