-
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.
- Loading branch information
Showing
32 changed files
with
311 additions
and
8 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/java/com/stempo/api/domain/application/event/BoardEventProcessor.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,30 @@ | ||
package com.stempo.api.domain.application.event; | ||
|
||
import com.stempo.api.domain.domain.model.Board; | ||
import com.stempo.api.domain.domain.repository.BoardRepository; | ||
import jakarta.annotation.PostConstruct; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class BoardEventProcessor implements UserEventProcessor { | ||
|
||
private final BoardRepository boardRepository; | ||
private final UserEventProcessorRegistry processorRegistry; | ||
|
||
@PostConstruct | ||
public void init() { | ||
processorRegistry.register(this); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void processUserDeleted(String deviceTag) { | ||
List<Board> boards = boardRepository.findByDeviceTag(deviceTag); | ||
boardRepository.deleteAll(boards); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/stempo/api/domain/application/event/HomeworkEventProcessor.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,30 @@ | ||
package com.stempo.api.domain.application.event; | ||
|
||
import com.stempo.api.domain.domain.model.Homework; | ||
import com.stempo.api.domain.domain.repository.HomeworkRepository; | ||
import jakarta.annotation.PostConstruct; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class HomeworkEventProcessor implements UserEventProcessor { | ||
|
||
private final HomeworkRepository homeworkRepository; | ||
private final UserEventProcessorRegistry processorRegistry; | ||
|
||
@PostConstruct | ||
public void init() { | ||
processorRegistry.register(this); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void processUserDeleted(String deviceTag) { | ||
List<Homework> records = homeworkRepository.findByDeviceTag(deviceTag); | ||
homeworkRepository.deleteAll(records); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/stempo/api/domain/application/event/RecordEventProcessor.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,30 @@ | ||
package com.stempo.api.domain.application.event; | ||
|
||
import com.stempo.api.domain.domain.model.Record; | ||
import com.stempo.api.domain.domain.repository.RecordRepository; | ||
import jakarta.annotation.PostConstruct; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class RecordEventProcessor implements UserEventProcessor { | ||
|
||
private final RecordRepository recordRepository; | ||
private final UserEventProcessorRegistry processorRegistry; | ||
|
||
@PostConstruct | ||
public void init() { | ||
processorRegistry.register(this); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void processUserDeleted(String deviceTag) { | ||
List<Record> records = recordRepository.findByDeviceTag(deviceTag); | ||
recordRepository.deleteAll(records); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/stempo/api/domain/application/event/UserDeletedEvent.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,15 @@ | ||
package com.stempo.api.domain.application.event; | ||
|
||
import lombok.Getter; | ||
import org.springframework.context.ApplicationEvent; | ||
|
||
@Getter | ||
public class UserDeletedEvent extends ApplicationEvent { | ||
|
||
private final String deviceTag; | ||
|
||
public UserDeletedEvent(Object source, String deviceTag) { | ||
super(source); | ||
this.deviceTag = deviceTag; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/stempo/api/domain/application/event/UserEventDispatcher.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,19 @@ | ||
package com.stempo.api.domain.application.event; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class UserEventDispatcher { | ||
|
||
private final List<UserEventProcessor> processors; | ||
|
||
@EventListener | ||
public void handleUserDeletedEvent(UserDeletedEvent event) { | ||
processors.forEach(processor -> processor.processUserDeleted(event.getDeviceTag())); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/stempo/api/domain/application/event/UserEventProcessor.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,6 @@ | ||
package com.stempo.api.domain.application.event; | ||
|
||
public interface UserEventProcessor { | ||
|
||
void processUserDeleted(String deviceTag); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/stempo/api/domain/application/event/UserEventProcessorRegistry.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,21 @@ | ||
package com.stempo.api.domain.application.event; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
@Component | ||
public class UserEventProcessorRegistry { | ||
|
||
private final List<UserEventProcessor> processors = new ArrayList<>(); | ||
|
||
public void register(UserEventProcessor processor) { | ||
processors.add(processor); | ||
} | ||
|
||
public List<UserEventProcessor> getProcessors() { | ||
return Collections.unmodifiableList(processors); | ||
} | ||
} |
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
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
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
Oops, something went wrong.