Skip to content

Commit

Permalink
[fix] #117 delete promise according to the number of participants whe…
Browse files Browse the repository at this point in the history
…n leave promise
  • Loading branch information
chaewonni committed Sep 2, 2024
1 parent f98357f commit 438ac2f
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.kkumulkkum.server.external.dto.FcmMessageDto;
import org.kkumulkkum.server.external.enums.FcmContent;
import org.kkumulkkum.server.service.member.MemberRetreiver;
import org.kkumulkkum.server.service.promise.PromiseRemover;
import org.kkumulkkum.server.service.promise.PromiseRetriever;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -35,6 +36,7 @@ public class ParticipantService {
private final PromiseRetriever promiseRetriever;
private final MemberRetreiver memberRetreiver;
private final ParticipantRemover participantRemover;
private final PromiseRemover promiseRemover;
private final FcmService fcmService;

@Transactional
Expand Down Expand Up @@ -169,6 +171,11 @@ public void leavePromise(
) {
Participant participant = participantRetriever.findByPromiseIdAndUserId(promiseId, userId);
participantRemover.deleteById(participant.getId());

List<Participant> remainingParticipants = participantRetriever.findAllByPromiseId(promiseId);
if(remainingParticipants.isEmpty()) {
promiseRemover.deleteById(promiseId);
}
}

private boolean validateState(
Expand Down

0 comments on commit 438ac2f

Please sign in to comment.