Skip to content

Commit

Permalink
Merge pull request #88 from AR-TTUBEOG/refactor/87
Browse files Browse the repository at this point in the history
[Refactor] 응답형식 리팩토링
  • Loading branch information
choeun7 authored Mar 10, 2024
2 parents 566237d + 1e611fe commit d68d231
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand All @@ -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로 만들기
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

//혜택 사용
Expand All @@ -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));
}

//혜택 조회
Expand All @@ -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));
}
}

0 comments on commit d68d231

Please sign in to comment.