Skip to content

Commit

Permalink
style: #49 포인트 전체 내역 조회 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hydrationn committed May 15, 2024
1 parent 2343319 commit 2d67671
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public class UserPointDetailController {

/**
* 회원의 포인트 타입에 따른 포인트 상세 내역 조회 API
* @param pointDetailType 조회할 포인트 타입(사용/적립)
* @param memberId 회원 ID
* @param pointDetailType 조회할 포인트 타입(사용/적립), null이면 전체 내역 조회
* @return 해당 포인트 상세 내역을 포함한 200(OK) 상태 반환
* @author hydrationn(박수화)
*/
Expand All @@ -31,6 +32,10 @@ public ResponseEntity<BaseResponse<List<PointDetailResponse>>> getPointDetailByP
@RequestParam(name = "pointDetailType", required = false) String pointDetailType) {
List<PointDetailResponse> pointDetailResponse = userPointDetailService.getPointDetailByPointDetailType(memberId, pointDetailType);

if(pointDetailType==null)
pointDetailResponse = userPointDetailService.getPointDetailList(memberId);


return ResponseEntity.status(HttpStatus.OK).body(new BaseResponse<List<PointDetailResponse>>().data(pointDetailResponse));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,29 @@ public class UserPointDetailService {
private final MemberRepository memberRepository;
private final PointDetailRepository pointDetailRepository;

/**
* 포인트 전체 내역 조회
* @param memberId 회원 ID
* @return 조회된 포인트 상세 정보를 {@link PointDetailResponse} 객체로 반환
* @throws PointDetailNotFoundException 포인트 상세 정보를 찾을 수 없는 경우 발생
* @author hydrationn(박수화)
*/
public List<PointDetailResponse> getPointDetailList(Long memberId) {
if(!memberRepository.existsById(memberId))
throw new MemberNotFoundException();

List<Optional<PointDetail>> pointDetailList = pointDetailRepository.findByMemberId(memberId);

return pointDetailList.stream()
.filter(Optional::isPresent)
.map(Optional::get)
.map(PointDetailResponse::of)
.collect(Collectors.toList());
}

/**
* 포인트 타입에 따른 상세 정보 조회
* @param memberId 회원 ID
* @param pointDetailType 조회할 포인트 타입
* @return 조회된 포인트 상세 정보를 {@link PointDetailResponse} 객체로 반환
* @throws PointDetailNotFoundException 포인트 상세 정보를 찾을 수 없는 경우 발생
Expand All @@ -42,9 +63,7 @@ public List<PointDetailResponse> getPointDetailByPointDetailType(Long memberId,
List<Optional<PointDetail>> addPointDetails = pointDetailRepository.findByMemberIdAndPointDetailType(memberId, pointDetailType);

for (int i = 0; i < addPointDetails.size(); i++) {
if(addPointDetails.get(i).get().getPointDetailType().equals(""))
pointDetails.add(addPointDetails.get(i).get());
else if (addPointDetails.get(i).get().getPointDetailType().equals("used")) {
if (addPointDetails.get(i).get().getPointDetailType().equals("used")) {
pointDetails.add(addPointDetails.get(i).get());
} else {
pointDetails.add(addPointDetails.get(i).get());
Expand Down

0 comments on commit 2d67671

Please sign in to comment.