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

fix - admin에서 challenge의 startDate가 변경되지 않았던 이슈 해결 #193

Merged
merged 3 commits into from
Sep 9, 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 @@ -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();
}
}
Loading