-
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.
Sometimes the events are consumed in Task-Service, while other times it is consumed in TimeEntry-Service; whereas it should be consumed by both services!
- Loading branch information
1 parent
494341a
commit aa1f744
Showing
5 changed files
with
55 additions
and
10 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
36 changes: 36 additions & 0 deletions
36
src/main/java/com/seyed/ali/timeentryservice/event/ProjectEventService.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,36 @@ | ||
package com.seyed.ali.timeentryservice.event; | ||
|
||
import com.seyed.ali.timeentryservice.model.payload.ProjectDTO; | ||
import com.seyed.ali.timeentryservice.repository.TimeEntryRepository; | ||
import com.seyed.ali.timeentryservice.service.interfaces.TimeEntryService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Optional; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class ProjectEventService { | ||
|
||
private final TimeEntryService timeEntryService; | ||
private final TimeEntryRepository timeEntryRepository; | ||
|
||
public void handleDeleteOperation(ProjectDTO projectDTO) { | ||
log.info("\"Delete\" project, associated tasks & time entries: {}", projectDTO); | ||
this.timeEntryRepository.findByProjectId(projectDTO.getProjectId()) | ||
.forEach(this.timeEntryService::deleteTimeEntry); | ||
} | ||
|
||
public void handleDetachOperation(ProjectDTO projectDTO) { | ||
log.info("\"Detach\" project, associated tasks & time entries: {}", projectDTO); | ||
this.timeEntryRepository.findByProjectId(projectDTO.getProjectId()) | ||
.forEach(timeEntry -> { | ||
timeEntry.setProjectId(null); | ||
timeEntry.setTaskId(null); | ||
this.timeEntryRepository.save(timeEntry); | ||
}); | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/seyed/ali/timeentryservice/model/enums/OperationType.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,7 @@ | ||
package com.seyed.ali.timeentryservice.model.enums; | ||
|
||
public enum OperationType { | ||
|
||
DELETE, DETACH | ||
|
||
} |
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