Skip to content

Commit

Permalink
delete methode added else
Browse files Browse the repository at this point in the history
  • Loading branch information
ramueSVA committed Dec 9, 2024
1 parent 80e638f commit 4821557
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ public void deleteUserMessage(Long id, String userId) {
Message messageToDelete = messageRepository.findById(id)
.orElseThrow(() -> new ResourceNotFound(MessageService.class, MESSAGE_NOT_FOUND,
String.format(MESSAGE_NOT_FOUND, id)));
if (messageToDelete.getStartDate().isBefore(now) || messageToDelete.getEndDate().isAfter(now)) {
//just planned messages can be deleted
if (messageToDelete.getStartDate().isAfter(now)) {
messageRepository.deleteById(id);
} else {
throw new BadRequestException(MessageService.class, CANNOT_DELETE_MESSAGE,
String.format(CANNOT_DELETE_MESSAGE, messageToDelete.getId()));
}
messageRepository.deleteById(id);
}

private static boolean isInactiveMessage(Message messageToUpdate, LocalDateTime now) {
Expand Down

0 comments on commit 4821557

Please sign in to comment.