From 4821557f025215ce06e467745bf697a0132c6d09 Mon Sep 17 00:00:00 2001 From: rabeaM Date: Mon, 9 Dec 2024 08:30:38 +0100 Subject: [PATCH] delete methode added else --- .../java/org/highmed/numportal/service/MessageService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/highmed/numportal/service/MessageService.java b/src/main/java/org/highmed/numportal/service/MessageService.java index 0c31274d..c2c84bec 100644 --- a/src/main/java/org/highmed/numportal/service/MessageService.java +++ b/src/main/java/org/highmed/numportal/service/MessageService.java @@ -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) {