Skip to content

Commit

Permalink
fixed bug with get messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Gorzala committed Dec 18, 2023
1 parent 260553e commit 760c5ed
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/dancier/dancer/chat/ChatController.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public ResponseEntity<ChatDto> getChat(

@GetMapping("/{chatId}/messages")
@Secured(ROLE_USER)
public ResponseEntity<MessagesDto> getMessages(
public ResponseEntity<MessageDto[]> getMessages(
@CurrentUser AuthenticatedUser authenticatedUser,
@PathVariable UUID chatId,
@RequestParam Optional<UUID> lastMessageId) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/dancier/dancer/chat/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public ChatDto getChat(UUID chatId, UUID dancerId) {
return chat;
}

public MessagesDto getMessages(UUID chatId, UUID dancerId, Optional<UUID> lastMessageId) {
public MessageDto[] getMessages(UUID chatId, UUID dancerId, Optional<UUID> lastMessageId) {
ChatDto chat = chatServiceClient.getChat(chatId);

throwIfDancerIsNotInChat(chat.getParticipantIds(), dancerId);

MessagesDto messages = chatServiceClient.getMessages(chatId, dancerId, lastMessageId);
MessageDto[] messages = chatServiceClient.getMessages(chatId, dancerId, lastMessageId);
return messages;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public ChatDto getChat(UUID chatId) {
.block();
}

public MessagesDto getMessages(UUID chatId, UUID dancerId, Optional<UUID> lastMessageId) {
public MessageDto[] getMessages(UUID chatId, UUID dancerId, Optional<UUID> lastMessageId) {
return webClient.get()
.uri(uriBuilder -> uriBuilder
.path(BASE_URI + "/{chatId}/messages")
Expand All @@ -91,7 +91,7 @@ public MessagesDto getMessages(UUID chatId, UUID dancerId, Optional<UUID> lastMe
.build(chatId)
)
.retrieve()
.bodyToMono(MessagesDto.class)
.bodyToMono(MessageDto[].class)
.block();
}

Expand Down
5 changes: 3 additions & 2 deletions src/test/java/net/dancier/dancer/chat/ChatControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.springframework.security.test.context.support.WithUserDetails;
import org.springframework.test.web.servlet.ResultActions;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
Expand Down Expand Up @@ -184,13 +185,13 @@ void getMessagesShouldReturnMessagesIfUserIsInChat() throws Exception {
messages.setMessages(List.of(message));

when(chatServiceClient.getChat(chatId)).thenReturn(chat);
when(chatServiceClient.getMessages(chatId, dancerId, Optional.empty())).thenReturn(messages);
when(chatServiceClient.getMessages(chatId, dancerId, Optional.empty())).thenReturn(new MessageDto[]{message});

ResultActions result = mockMvc.perform(
get("/chats/" + chatId + "/messages"))
.andExpect(status().isOk());

result.andExpect(jsonPath("$.messages[0].text").value("Hallo"));
result.andExpect(jsonPath("$[0].text").value("Hallo"));

}
}
Expand Down
11 changes: 4 additions & 7 deletions swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ paths:
- $ref: '#/components/parameters/lastMessageId'
responses:
'200':
description: "detailed data of a chat"
description: "list of message in a chat"
content:
application/json:
schema:
Expand Down Expand Up @@ -944,12 +944,9 @@ components:
type:
$ref: '#/components/schemas/chatType'
messageListResponse:
type: object
properties:
messages:
type: array
items:
$ref: '#/components/schemas/message'
type: array
items:
$ref: '#/components/schemas/message'
message:
allOf:
- $ref: '#/components/schemas/baseMessage'
Expand Down

0 comments on commit 760c5ed

Please sign in to comment.