Skip to content

Commit

Permalink
update methods after testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mafasva committed Dec 10, 2024
1 parent 0bc2c85 commit 2f9fffe
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public class MessageService {
public MessageDto createUserMessage(MessageDto messageDto, String userId) {
userDetailsService.checkIsUserApproved(userId);
Message message = messageMapper.convertToEntity(messageDto);
message.setText(Jsoup.clean(message.getText(), safeList));
if (message.getText() != null && !message.getText().isBlank()) {
message.setText(Jsoup.clean(message.getText(), safeList));
}
validateDates(message.getStartDate(), message.getEndDate(), LocalDateTime.now().minusMinutes(5));

Message savedMessage = messageRepository.save(message);
Expand Down Expand Up @@ -78,7 +80,9 @@ public MessageDto updateUserMessage(Long id, MessageDto messageDto, String userI
validateDates(messageDto.getStartDate(), messageDto.getEndDate(), now);

messageToUpdate.setTitle(messageDto.getTitle());
messageToUpdate.setText(Jsoup.clean(messageDto.getText(), safeList));
if (messageToUpdate.getText() != null && !messageToUpdate.getText().isBlank()) {
messageToUpdate.setText(Jsoup.clean(messageToUpdate.getText(), safeList));
}
messageToUpdate.setStartDate(messageDto.getStartDate());
messageToUpdate.setEndDate(messageDto.getEndDate());
messageToUpdate.setType(messageDto.getType());
Expand Down Expand Up @@ -130,6 +134,7 @@ public void markUserMessageAsRead(Long id, String userId) {
.orElseThrow(() -> new ResourceNotFound(MessageService.class, USER_NOT_FOUND,
String.format(USER_NOT_FOUND, userId)));
readMessage.getReadByUsers().add(userDetails);
messageRepository.save(readMessage);
} else {
throw new ForbiddenException(MessageService.class, CANNOT_ACCESS_THIS_RESOURCE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public GroupedOpenApi attachmentApi() {
return getDocket("Attachment", "/attachment/**", NUM_PACKAGES_TO_SCAN);
}

@Bean
public GroupedOpenApi messageApi() {
return getDocket("Message", "/message/**", NUM_PACKAGES_TO_SCAN);
}

@Bean
public OpenAPI customOpenAPI() {
OAuthFlow oAuthFlow = new OAuthFlow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.data.web.SortDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
Expand Down Expand Up @@ -91,7 +92,7 @@ public ResponseEntity<Void> deleteUserMessage(
@PathVariable("id") Long id,
@AuthenticationPrincipal @NotNull Jwt principal) {
messageService.deleteUserMessage(id, principal.getSubject());
return ResponseEntity.ok().build();
return ResponseEntity.noContent().build();
}

@PostMapping(value = "/read/{id}")
Expand All @@ -101,7 +102,7 @@ public ResponseEntity<Void> markUserMessageAsRead(
@PathVariable("id") Long id,
@AuthenticationPrincipal @NotNull Jwt principal) {
messageService.markUserMessageAsRead(id, principal.getSubject());
return ResponseEntity.ok().build();
return ResponseEntity.noContent().build();
}

@GetMapping(value = "/read")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
DROP TABLE IF EXISTS message;

CREATE TABLE message
(
id serial PRIMARY KEY,
Expand All @@ -9,7 +7,7 @@ CREATE TABLE message
end_date timestamp NOT NULL,
type varchar(125) NOT NULL,
mark_as_deleted boolean,
sessionBased boolean
session_based boolean
);

CREATE TABLE read_message_by_users
Expand Down

0 comments on commit 2f9fffe

Please sign in to comment.