From 1e611febc32093d2832a5ceca3b6c3ccbe29032e Mon Sep 17 00:00:00 2001 From: choeun7 Date: Mon, 4 Mar 2024 23:04:52 +0900 Subject: [PATCH] =?UTF-8?q?[Refactor]=20=EC=9D=91=EB=8B=B5=ED=98=95?= =?UTF-8?q?=EC=8B=9D=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Service 단에 무의미한 반복이 많아서, ApiResponse를 반환하는 방법으로 바꿨습니다. Benefit 파일만 우선 예시로 수정했습니다. --- .../benefit/application/BenefitService.java | 27 +++++-------------- .../presentation/BenefitController.java | 6 ++--- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/ttubeog/domain/benefit/application/BenefitService.java b/src/main/java/com/ttubeog/domain/benefit/application/BenefitService.java index 74f39940..38de8493 100644 --- a/src/main/java/com/ttubeog/domain/benefit/application/BenefitService.java +++ b/src/main/java/com/ttubeog/domain/benefit/application/BenefitService.java @@ -41,7 +41,7 @@ public class BenefitService { //게임 성공 후 혜택 저장 @Transactional - public ResponseEntity saveBenefit(HttpServletRequest request, Long benefitId) throws JsonProcessingException { + public ApiResponse saveBenefit(HttpServletRequest request, Long benefitId) throws JsonProcessingException { Long memberId = jwtTokenProvider.getMemberId(request); Member member = memberRepository.findById(memberId).orElseThrow(InvalidMemberException::new); Benefit benefit = benefitRepository.findById(benefitId).orElseThrow(NonExistentBenefitException::new); @@ -73,18 +73,13 @@ public ResponseEntity saveBenefit(HttpServletRequest request, Long benefitId) .createdAt(memberBenefit.getCreatedAt()) .build(); - ApiResponse apiResponse = ApiResponse.builder() - .check(true) - .information(saveBenefitRes) - .build(); - - return ResponseEntity.ok(apiResponse); + return new ApiResponse(true, saveBenefitRes); } //혜택 사용 @Transactional - public ResponseEntity useBenefit(HttpServletRequest request, Long benefitId) throws JsonProcessingException { + public ApiResponse useBenefit(HttpServletRequest request, Long benefitId) throws JsonProcessingException { Long memberId = jwtTokenProvider.getMemberId(request); Member member = memberRepository.findById(memberId).orElseThrow(InvalidMemberException::new); Benefit benefit = benefitRepository.findById(benefitId).orElseThrow(NonExistentBenefitException::new); @@ -112,16 +107,11 @@ public ResponseEntity useBenefit(HttpServletRequest request, Long benefitId) .type(benefit.getType()) .build(); - ApiResponse apiResponse = ApiResponse.builder() - .check(true) - .information(saveBenefitRes) - .build(); - - return ResponseEntity.ok(apiResponse); + return new ApiResponse(true, saveBenefitRes); } //혜택 조회(사용 가능, 사용 완료, 만료 혜택 모두 조회) - public ResponseEntity findMyBenefit(HttpServletRequest request, Integer page) throws JsonProcessingException { + public ApiResponse findMyBenefit(HttpServletRequest request, Integer page) throws JsonProcessingException { Long memberId = jwtTokenProvider.getMemberId(request); Member member = memberRepository.findById(memberId).orElseThrow(InvalidMemberException::new); @@ -141,12 +131,7 @@ public ResponseEntity findMyBenefit(HttpServletRequest request, Integer page) .build() ).toList(); - ApiResponse apiResponse = ApiResponse.builder() - .check(true) - .information(saveBenefitRes) - .build(); - - return ResponseEntity.ok(apiResponse); + return new ApiResponse(true, saveBenefitRes); } //한달지나면 expired true로 만들기 diff --git a/src/main/java/com/ttubeog/domain/benefit/presentation/BenefitController.java b/src/main/java/com/ttubeog/domain/benefit/presentation/BenefitController.java index 88b7a03a..8f122153 100644 --- a/src/main/java/com/ttubeog/domain/benefit/presentation/BenefitController.java +++ b/src/main/java/com/ttubeog/domain/benefit/presentation/BenefitController.java @@ -34,7 +34,7 @@ public ResponseEntity saveBenefit( HttpServletRequest request, @PathVariable(value = "benefitId") Long benefitId ) throws JsonProcessingException { - return benefitService.saveBenefit(request, benefitId); + return ResponseEntity.ok(benefitService.saveBenefit(request, benefitId)); } //혜택 사용 @@ -48,7 +48,7 @@ public ResponseEntity useBenefit( HttpServletRequest request, @PathVariable(value = "benefitId") Long benefitId ) throws JsonProcessingException { - return benefitService.useBenefit(request, benefitId); + return ResponseEntity.ok(benefitService.useBenefit(request, benefitId)); } //혜택 조회 @@ -62,6 +62,6 @@ public ResponseEntity findMyBenefit( HttpServletRequest request, @RequestParam(name = "page") Integer page ) throws JsonProcessingException { - return benefitService.findMyBenefit(request, page); + return ResponseEntity.ok(benefitService.findMyBenefit(request, page)); } }