Implementation of publication deletion.
This commit is contained in:
@@ -123,4 +123,18 @@ public class PublicationUseCases {
|
||||
|
||||
return updatedPublication;
|
||||
}
|
||||
|
||||
public void deletePublication(UUID publicationId) {
|
||||
Publication publicationToDelete = publicationPort.findById(publicationId)
|
||||
.orElseThrow(() -> new PublicationNotFoundException(publicationId));
|
||||
|
||||
User authenticatedUser = userUseCases.getAuthenticatedUser()
|
||||
.orElseThrow(AuthenticationRequiredException::new);
|
||||
|
||||
if (!publicationToDelete.author().id().equals(authenticatedUser.id())) {
|
||||
throw new PublicationUpdateForbiddenException();
|
||||
}
|
||||
|
||||
publicationPort.delete(publicationToDelete);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user