Skip to content

Commit

Permalink
further
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Gorzala committed Dec 15, 2023
1 parent f6eea87 commit 6f98c70
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/main/java/net/dancier/dancer/chat/ChatController.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import java.net.URI;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

Expand All @@ -32,10 +33,10 @@ public class ChatController {

@GetMapping("")
@Secured(ROLE_USER)
public ResponseEntity<ChatsDto> getChats(@CurrentUser AuthenticatedUser authenticatedUser) {
public ResponseEntity<List<ChatDto>> getChats(@CurrentUser AuthenticatedUser authenticatedUser) {
log.info("Fetching chats for user {}.", authenticatedUser.getUserId());
return ResponseEntity.ok(
chatService.getChatsByUserId(authenticatedUser.getDancerIdOrThrow())
List.of(chatService.getChatsByUserId(authenticatedUser.getDancerIdOrThrow()))
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/dancier/dancer/chat/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ChatService {

private final ChatServiceClient chatServiceClient;

public ChatsDto getChatsByUserId(UUID dancerId) {
public ChatDto[] getChatsByUserId(UUID dancerId) {
log.info("Getting Chats for: " + dancerId);
return chatServiceClient.getChats(dancerId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public void init() {
.build();
}

public ChatsDto getChats(UUID dancerId) {
public ChatDto[] getChats(UUID dancerId) {
return webClient.get()
.uri(uriBuilder -> uriBuilder
.path(BASE_URI)
.queryParam("participantId", dancerId)
.build()
)
.retrieve()
.bodyToMono(ChatsDto.class)
.bodyToMono(ChatDto[].class)
.block();
}

Expand Down
5 changes: 2 additions & 3 deletions src/test/java/net/dancier/dancer/chat/ChatControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,15 @@ void getChatsShouldReturnChats() throws Exception {
ChatDto chat = new ChatDto();
chat.setParticipantIds(List.of(dancerId, UUID.randomUUID()));
chat.setChatId(chatId);
ChatsDto chats = new ChatsDto();
chats.setChats(List.of(chat));
ChatDto[] chats = {chat};

when(chatServiceClient.getChats(dancerId)).thenReturn(chats);

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

result.andExpect(jsonPath("$.chats[0].chatId").value(chatId.toString()));
result.andExpect(jsonPath("$.[0].chatId").value(chatId.toString()));
}
}

Expand Down

0 comments on commit 6f98c70

Please sign in to comment.