Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] 응답형식 리팩토링 #88

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}
Loading