-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from YAPP-Github/feat/ISSUE-91
feat: Carpool delete API
- Loading branch information
Showing
18 changed files
with
250 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/com/fullcar/carpool/application/form/CarpoolClosedEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.fullcar.carpool.application.form; | ||
|
||
|
||
import com.fullcar.carpool.domain.carpool.event.CarpoolClosedEvent; | ||
import com.fullcar.carpool.domain.form.Form; | ||
import com.fullcar.carpool.domain.form.FormRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Propagation; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.transaction.event.TransactionPhase; | ||
import org.springframework.transaction.event.TransactionalEventListener; | ||
|
||
import java.util.List; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class CarpoolClosedEventHandler { | ||
private final FormRepository formRepository; | ||
|
||
@Transactional(propagation = Propagation.REQUIRES_NEW) | ||
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) | ||
public void rejectForms(CarpoolClosedEvent carpoolClosedEvent) { | ||
log.info("CarpoolClosedEvent received"); | ||
List<Form> forms = carpoolClosedEvent.getForms(); | ||
|
||
forms.forEach(Form::reject); | ||
formRepository.saveAllAndFlush(forms); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/fullcar/carpool/application/form/CarpoolDeletedEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.fullcar.carpool.application.form; | ||
|
||
import com.fullcar.carpool.domain.carpool.event.CarpoolDeletedEvent; | ||
import com.fullcar.carpool.domain.form.Form; | ||
import com.fullcar.carpool.domain.form.FormRepository; | ||
import com.fullcar.carpool.domain.form.FormState; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Propagation; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.transaction.event.TransactionPhase; | ||
import org.springframework.transaction.event.TransactionalEventListener; | ||
|
||
import java.util.List; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class CarpoolDeletedEventHandler { | ||
private final FormRepository formRepository; | ||
|
||
@Transactional(propagation = Propagation.REQUIRES_NEW) | ||
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) | ||
public void rejectForms(CarpoolDeletedEvent carpoolDeletedEvent) { | ||
log.info("CarpoolDeletedEvent received"); | ||
List<Form> forms = carpoolDeletedEvent.getForms(); | ||
|
||
for (Form form: forms) { | ||
if (form.getFormState() == FormState.REQUEST || form.getFormState() == FormState.ACCEPT) { | ||
form.reject(); | ||
} | ||
form.disconnectCarpool(); | ||
} | ||
formRepository.saveAllAndFlush(forms); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/com/fullcar/carpool/application/form/FormStateChangedEventHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.fullcar.carpool.application.form; | ||
|
||
import com.fullcar.carpool.domain.form.event.FormStateChangedEvent; | ||
import com.fullcar.carpool.domain.service.NotificationService; | ||
import com.fullcar.carpool.infra.dto.NotificationDto; | ||
import com.fullcar.member.domain.member.MemberRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Propagation; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.transaction.event.TransactionPhase; | ||
import org.springframework.transaction.event.TransactionalEventListener; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class FormStateChangedEventHandler { | ||
private final NotificationService notificationService; | ||
private final MemberRepository memberRepository; | ||
|
||
@Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW) | ||
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) | ||
public void sendNotification(FormStateChangedEvent formStateChangedEvent) { | ||
log.info("FormStateChangedEvent received"); | ||
notificationService.sendNotification( | ||
NotificationDto.builder() | ||
.member( | ||
memberRepository.findByIdAndIsDeletedOrThrow(formStateChangedEvent.getMemberId(), false) | ||
) | ||
.title(formStateChangedEvent.getTitle()) | ||
.body(formStateChangedEvent.getBody()) | ||
.build() | ||
); | ||
log.info("Notification send"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/com/fullcar/carpool/domain/carpool/event/CarpoolClosedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.fullcar.carpool.domain.carpool.event; | ||
|
||
import com.fullcar.carpool.domain.form.Form; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class CarpoolClosedEvent { | ||
private List<Form> forms; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/fullcar/carpool/domain/carpool/event/CarpoolDeletedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.fullcar.carpool.domain.carpool.event; | ||
|
||
import com.fullcar.carpool.domain.form.Form; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class CarpoolDeletedEvent { | ||
private List<Form> forms; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 11 additions & 1 deletion
12
src/main/java/com/fullcar/carpool/domain/form/event/FormStateChangedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
package com.fullcar.carpool.domain.form.event; | ||
|
||
import com.fullcar.carpool.infra.dto.NotificationDto; | ||
import com.fullcar.member.domain.member.Member; | ||
import com.fullcar.member.domain.member.MemberId; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class FormStateChangedEvent { | ||
private NotificationDto notificationDto; | ||
private MemberId memberId; | ||
|
||
private String title; | ||
|
||
private String body; | ||
} |
Oops, something went wrong.