Skip to content

Commit

Permalink
Merge pull request #193 from Team-HMH/fix/#192-admin-change-challenge…
Browse files Browse the repository at this point in the history
…-info-api

�fix - admin에서 challenge의 startDate가 변경되지 않았던 이슈 해결
  • Loading branch information
kseysh authored Sep 9, 2024
2 parents 6409927 + 3737810 commit 55ecaf1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import sopt.org.hmh.domain.admin.dto.response.AdminTokenResponse;
import sopt.org.hmh.domain.admin.exception.AdminError;
import sopt.org.hmh.domain.admin.exception.AdminException;
import sopt.org.hmh.domain.challenge.domain.Challenge;
import sopt.org.hmh.domain.challenge.domain.exception.ChallengeError;
import sopt.org.hmh.domain.challenge.domain.exception.ChallengeException;
import sopt.org.hmh.domain.challenge.service.ChallengeService;
Expand Down Expand Up @@ -65,15 +66,17 @@ public void changeUserInfo(AdminUserInfoRequest request) {
@Transactional
public void changeDailyChallengeInfo(AdminDailyChallengeRequest request) {
Long currentChallengeId = userService.getCurrentChallengeIdByUserId(request.userId());
Challenge challenge = challengeService.findByIdOrElseThrow(currentChallengeId);
List<Status> statuses = request.statuses();
LocalDate challengeDate = request.startDate();

validateStatusesPeriod(currentChallengeId, statuses);
validateStatusesPeriod(challenge, statuses);
challenge.changeStartDate(challengeDate);
dailyChallengeService.changeInfoOfDailyChallenges(currentChallengeId, statuses, challengeDate);
}

private void validateStatusesPeriod(Long challengeId, List<Status> statuses) {
Integer challengePeriod = challengeService.getChallengePeriod(challengeId);
private void validateStatusesPeriod(Challenge challenge, List<Status> statuses) {
Integer challengePeriod = challenge.getPeriod();
if (challengePeriod != statuses.size()) {
throw new ChallengeException(ChallengeError.INVALID_PERIOD_NUMERIC);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ private Challenge(Integer period, Long userId, Long goalTime, List<ChallengeApp>
this.apps = apps;
this.startDate = startDate;
}

public void changeStartDate(LocalDate startDate) {
this.startDate = startDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,4 @@ public List<ChallengeApp> getCurrentChallengeAppByChallengeId(Long challengeId)
public Challenge addChallenge(Challenge challenge) {
return challengeRepository.save(challenge);
}

public Integer getChallengePeriod(Long challengeId) {
return this.findByIdOrElseThrow(challengeId).getPeriod();
}
}

0 comments on commit 55ecaf1

Please sign in to comment.