Skip to content

Commit

Permalink
fixed ErrorMessage in chat-server-generated
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-kuba committed Apr 2, 2024
1 parent 39ce738 commit c87ad6f
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import cz.muni.chat.generated.server.model.BackgroundColorEnum;
import cz.muni.chat.generated.server.model.ChatMessage;
import cz.muni.chat.generated.server.model.ErrorMessage;
import cz.muni.chat.generated.server.model.NewChatMessageRequest;
import cz.muni.chat.generated.server.model.NewChatMessageRequest.TextColorEnum;
import cz.muni.chat.generated.server.model.PageChatMessage;
Expand Down Expand Up @@ -36,11 +37,22 @@ public ResponseEntity<List<ChatMessage>> getAllMessages() {
return new ResponseEntity<>(messages, HttpStatus.OK);
}

@SuppressWarnings({"rawtypes","unchecked"})
@Override
public ResponseEntity<ChatMessage> getMessage(String id) {
log.debug("getMessage({})", id);
ChatMessage chatMessage = messages.stream().filter(x -> x.getId().equals(id)).findFirst().orElse(null);
return new ResponseEntity<>(chatMessage, chatMessage != null ? HttpStatus.OK : HttpStatus.NOT_FOUND);
if (chatMessage != null) {
return new ResponseEntity<>(chatMessage, HttpStatus.OK);
} else {
ErrorMessage errorMessage = new ErrorMessage()
.error(HttpStatus.NOT_FOUND.getReasonPhrase())
.status(HttpStatus.NOT_FOUND.value())
.path("/api/message/"+id)
.timestamp(OffsetDateTime.now())
.message("message with id=" + id + " not found");
return new ResponseEntity(errorMessage, HttpStatus.NOT_FOUND);
}
}

@Override
Expand Down

0 comments on commit c87ad6f

Please sign in to comment.