Skip to content

Commit

Permalink
delete person ref from task assignee
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSebastian committed Mar 17, 2024
1 parent bac8af7 commit c4a635a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public void updateTaskAssignee(final UUID taskId, @Nullable final TaskAssigneeDT
}
}

@PreAuthorize("hasAnyRole(T(de.mrsebastian.todoappdemo.backend.security.AuthoritiesEnum).TASK_ADMIN.name())")
public void removePersonFromTasks(final UUID personId) {
getTaskWithAssignee(personId).forEach(task -> taskDAService.removeAssignee(task.id()));
}

private void checkIfExistsOrThrow(final UUID taskId) {
if (!taskDAService.taskExsits(taskId)) {
throw new NotFoundException(taskId, Task.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package de.mrsebastian.todoappdemo.backend.task.service.events;

import de.mrsebastian.todoappdemo.backend.person.service.events.PersonDeleteEvent;
import de.mrsebastian.todoappdemo.backend.task.service.TaskService;
import lombok.AllArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

@Component
@AllArgsConstructor
public class PersonEventsListener {

private final TaskService taskService;

@EventListener
public void handlePersonDeletedEvent(final PersonDeleteEvent personDeleteEvent) {
taskService.removePersonFromTasks(personDeleteEvent.personId());
}
}

0 comments on commit c4a635a

Please sign in to comment.