From 438ac2f21f1301333b33fa6d962827a20b95356b Mon Sep 17 00:00:00 2001 From: chaewonkim Date: Tue, 3 Sep 2024 00:52:12 +0900 Subject: [PATCH] [fix] #117 delete promise according to the number of participants when leave promise --- .../server/service/participant/ParticipantService.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/kkumulkkum/server/service/participant/ParticipantService.java b/src/main/java/org/kkumulkkum/server/service/participant/ParticipantService.java index 877a136..76849d0 100644 --- a/src/main/java/org/kkumulkkum/server/service/participant/ParticipantService.java +++ b/src/main/java/org/kkumulkkum/server/service/participant/ParticipantService.java @@ -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; @@ -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 @@ -169,6 +171,11 @@ public void leavePromise( ) { Participant participant = participantRetriever.findByPromiseIdAndUserId(promiseId, userId); participantRemover.deleteById(participant.getId()); + + List remainingParticipants = participantRetriever.findAllByPromiseId(promiseId); + if(remainingParticipants.isEmpty()) { + promiseRemover.deleteById(promiseId); + } } private boolean validateState(