Skip to content

Commit

Permalink
[ADD] added challenge cancel code
Browse files Browse the repository at this point in the history
  • Loading branch information
thguss committed Jan 15, 2025
1 parent e60479b commit edc015e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ public void achieve() {
this.achievedCount++;
this.achieved = true;
}

public void cancel() {
this.achievedCount--;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public void achieveMemberChallenge(long memberId) {

@Transactional
public void deleteHistory(long historyId) {
val history = challengeHistoryAdapter.findById(historyId);
val memberChallenge = memberChallengeAdapter.findById(history.getMemberChallengeId());
memberChallenge.cancel();
memberChallengeAdapter.update(memberChallenge);
challengeHistoryAdapter.deleteById(historyId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import org.springframework.stereotype.Component;

import com.soptie.server.common.exception.ExceptionCode;
import com.soptie.server.common.exception.SoftieException;
import com.soptie.server.domain.challenge.Challenge;
import com.soptie.server.domain.challenge.ChallengeHistory;
import com.soptie.server.domain.challenge.MemberChallenge;
Expand Down Expand Up @@ -39,4 +41,10 @@ public List<ChallengeHistory> findAllByMemberIdAndCreatedAtBetween(
return historyRepository.findAllByMemberIdAndCreatedAtBetween(memberId, startDateTime, endDateTime).stream()
.map(ChallengeHistoryEntity::toDomain).toList();
}

public ChallengeHistory findById(final long id) {
return historyRepository.findById(id)
.orElseThrow(() -> new SoftieException(ExceptionCode.NOT_FOUND, "ChallengeHistoryId: " + id))
.toDomain();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public List<MemberChallenge> findAllByMemberId(long memberId) {
.toList();
}

public MemberChallenge findById(long id) {
return find(id).toDomain();
}

private MemberChallengeEntity find(long id) {
return memberChallengeRepository.findById(id)
.orElseThrow(() -> new SoftieException(ExceptionCode.NOT_FOUND, "MemberChallenge ID: " + id));
Expand Down

0 comments on commit edc015e

Please sign in to comment.