Skip to content

Commit

Permalink
feat: 돈길 상세 API 작성 #268
Browse files Browse the repository at this point in the history
  • Loading branch information
sanbonai06 committed Nov 10, 2022
1 parent 98f9fad commit c710924
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/com/ceos/bankids/controller/ChallengeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ public CommonResponse<List<ChallengeDTO>> getListChallenge(
return CommonResponse.onSuccess(challengeDTOList);
}

@ApiOperation(value = "돈길 상세 가져오기")
@GetMapping(value = "/{challengeId}", produces = "application/json; charset=utf-8")
public CommonResponse<ChallengeDTO> getChallengeDetail(@AuthenticationPrincipal User authUser,
@PathVariable Long challengeId) {

log.info("api = 돈길 상세 가져오기, user = {}, challenge = {}", authUser.getUsername(),
challengeId);

return CommonResponse.onSuccess(challengeMapper.readChallengeDetail(authUser, challengeId));
}

@ApiOperation(value = "자녀의 돈길 리스트 가져오기")
@GetMapping(value = "/kid/{kidId}", produces = "application/json; charset=utf-8")
public CommonResponse<KidChallengeListDTO> getListKidChallenge(
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/ceos/bankids/mapper/ChallengeMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ public List<ChallengeDTO> readChallengeListMapper(User authUser, String status)
return challengeDTOList;
}

@Transactional
public ChallengeDTO readChallengeDetail(User authUser, Long challengeId) {
ChallengeUser challengeUser = challengeUserService.readChallengeUser(challengeId);
if (authUser.getId() != challengeUser.getUser().getId()) {
throw new BadRequestException(ErrorCode.NOT_MATCH_CHALLENGE_USER.getErrorCode());
}
return challengeService.readChallengeDetail(challengeId);
}

// 자녀의 돈길 리스트 가져오기 API Mapper
@Transactional
public KidChallengeListDTO readKidChallengeListMapper(User authUser, Long kidId,
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/ceos/bankids/service/ChallengeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,6 @@ public ChallengeCompleteDeleteByKidMapperDTO challengeCompleteDeleteByKid(
List<Challenge> challengeList);

public List<ChallengeDTO> readChallengeHistory(String status);

public ChallengeDTO readChallengeDetail(Long challengeId);
}
10 changes: 10 additions & 0 deletions src/main/java/com/ceos/bankids/service/ChallengeServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ public ChallengeListMapperDTO readPendingChallenge(Challenge challenge) {
return new ChallengeListMapperDTO(challenge, null, false);
}

@Transactional
@Override
public ChallengeDTO readChallengeDetail(Long challengeId) {
Challenge challenge = challengeRepository.findById(challengeId).orElseThrow(
() -> new BadRequestException(ErrorCode.NOT_EXIST_CHALLENGE.getErrorCode()));
return new ChallengeDTO(challenge, challenge.getProgressList().stream()
.map(progress -> new ProgressDTO(progress, challenge)).collect(
Collectors.toList()), challenge.getComment());
}

// 돈길 수락 / 거절 API
@Transactional
@Override
Expand Down

0 comments on commit c710924

Please sign in to comment.