[Feat] 정산 api 수정(동일한 api로 정산 완료/미완 상태 변경하기) #364#365
Merged
Conversation
| this.state = ChallengeState.COMPLETED_SETTLED; | ||
| } | ||
|
|
||
| public void setStateCanceledSettled() { |
Contributor
There was a problem hiding this comment.
동일한 기능을 하는 setter가 여러 이름으로 만들어지다보니 나중에 유지보수 할 때 헷갈릴 수 있다는 생각이 드는데요.
setter에 매개변수를 전달하는 방식으로 만드는 건 어떠세요?
public SuccessResponse<Void> settleChallenge(Long challengeId, Member member) {
// 중략
switch (challenge.getState()) {
case COMPLETED_PENDING_SETTLEMENT -> changeChallengeState(challenge, false, ChallengeState.COMPLETE_SETTLED);
// 나머지 케이스 생략
default -> throw new BadRequestException(ErrorCode.INVALID_CHALLENGE_STATE_FOR_SETTLEMENT);
}
challengeRepository.save(challenge);
return SuccessResponse.of(SuccessCode.CHALLENGE_SETTLEMENT_SUCCESS);
}
private void changeChallengeState(Challenge challenge, boolean isPaidAll, ChallengeState state) {
challenge.setIsPaidAll(isPaidAll);
challenge.setState(state);
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
개요
챌린지 상태를 추가했습니다.
CANCELED_SETTLED상태를 추가했습니다.챌린지 정산 API를 수정했습니다.
종료시,정산 완료로상태를 변경하는 로직만 존재했습니다.정산 미완 -> 정산 완료,정산 완료 -> 정산 미완의 상태 변경이 모두 가능합니다.종료된 챌린지뿐만 아니라,중도 취소한 챌린지에도정산 미완 or 완료상태 변경이 가능하도록 했습니다.코드 내용
1.
ChallengeState에CANCELED_SETTLED추가ChallengeStateenum에CANCELED_SETTLED를 추가했습니다.정산 X)를 뜻하는CANCELED, 챌린지 중도 취소(정산 O)를 뜻하는CANCELED_SETTLED로중도 취소상태를정산여부에 따라 나누어 관리할 수 있게 되었습니다.2. 챌린지 정산 API 수정
/api/challenges/{id}/settlement의 내부 메서드에 상태에 따른 분기문 로직을 추가했습니다.챌린지의 7가지 상태 중 정산 관련 네 상태를 제외하고는, 모두
default를 통해 예외 처리가 됩니다.정산관련된 네 가지 상태는switch-case분기문을 통해 처리됩니다.COMPLETED_PENDING_SETTLEMENT),종료 - 정산 완료(
COMPLETED_SETTLED),중도 취소 - 정산 미완(
CANCELED),중도 취소 - 정산 완료(
CANCELED_SETTLED)의 네 가지 상태만 처리합니다.
정산 미완인 경우정산 완료로,정산 완료인 경우정산 미완으로 변경합니다.종료상태는종료상태 간에만,중도 취소는중도 취소간에만정산상태가 변경됩니다.3. 챌린지 정보를 담는 DTO에 챌린지 상태 속성 추가
Challenge도메인의ChallengeDetailsResponse,ChallengeEnrolledListItemResponseDTO에ChallengeState속성을 추가했습니다.4. 관련된 코드를 추가 및 수정했습니다.
Challenge도메인 내부 setter 메서드 추가