Skip to content

Commit 82cb1e9

Browse files
author
Marc Gorzala
committed
debug
1 parent 54ae275 commit 82cb1e9

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

src/main/java/net/dancier/dancer/chat/ChatController.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,23 @@ public ResponseEntity<ChatsDto> getChats(@CurrentUser AuthenticatedUser authenti
4141

4242
@PostMapping("")
4343
@Secured(ROLE_USER)
44-
public ResponseEntity<ChatDto> postChat(
44+
public ResponseEntity postChat(
4545
@CurrentUser AuthenticatedUser authenticatedUser,
4646
@RequestBody CreateChatDto createChatDto) {
4747
log.info("Creating a new chat for User {}.", authenticatedUser.getUserId());
4848

49-
ChatDto createdChat = chatService.createChat(authenticatedUser.getDancerIdOrThrow(), createChatDto);
50-
log.info("this chat was created " + createdChat);
49+
CreatedChatDto createdChatDto = chatService.createChat(authenticatedUser.getDancerIdOrThrow(), createChatDto);
50+
log.info("Got this stuff: " + createdChatDto);
5151
URI location = ServletUriComponentsBuilder
5252
.fromCurrentContextPath()
53-
.path("/chats/" + createdChat.getChatId())
53+
.path("/chats/" + createdChatDto.id)
5454
.build()
5555
.toUri();
5656

5757
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
5858
headers.set("Location", location.toString());
5959

6060
return new ResponseEntity(
61-
createdChat,
6261
headers,
6362
HttpStatus.CREATED
6463
);

src/main/java/net/dancier/dancer/chat/ChatService.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import net.dancier.dancer.core.exception.BusinessException;
88
import org.slf4j.Logger;
99
import org.slf4j.LoggerFactory;
10+
import org.springframework.http.ResponseEntity;
1011
import org.springframework.stereotype.Service;
1112

1213
import java.util.List;
@@ -26,7 +27,7 @@ public ChatsDto getChatsByUserId(UUID dancerId) {
2627
return chatServiceClient.getChats(dancerId);
2728
}
2829

29-
public ChatDto createChat(UUID dancerId, CreateChatDto createChatDto) {
30+
public CreatedChatDto createChat(UUID dancerId, CreateChatDto createChatDto) {
3031
log.info("check if dancer is in chat.");
3132
throwIfDancerIsNotInChat(createChatDto.getParticipantIds(), dancerId);
3233
log.info("About to make the rest-call");

src/main/java/net/dancier/dancer/chat/client/ChatServiceClient.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package net.dancier.dancer.chat.client;
22

33
import io.netty.handler.logging.LogLevel;
4-
import net.dancier.dancer.chat.dto.ChatDto;
5-
import net.dancier.dancer.chat.dto.CreateChatDto;
6-
import net.dancier.dancer.chat.dto.ChatsDto;
7-
import net.dancier.dancer.chat.dto.MessagesDto;
4+
import net.dancier.dancer.chat.dto.*;
85
import org.slf4j.Logger;
96
import org.slf4j.LoggerFactory;
107
import org.springframework.beans.factory.annotation.Value;
8+
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties;
9+
import org.springframework.http.ResponseEntity;
1110
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
1211
import org.springframework.stereotype.Service;
1312
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
@@ -39,6 +38,7 @@ public void init() {
3938
.create()
4039
.wiretap("reactor.netty.http.client.HttpClient",
4140
LogLevel.INFO, AdvancedByteBufFormat.TEXTUAL);
41+
4242
this.webClient = WebClient.builder()
4343
.baseUrl(host)
4444
.clientConnector(new ReactorClientHttpConnector(httpClient))
@@ -58,7 +58,7 @@ public ChatsDto getChats(UUID dancerId) {
5858
.block();
5959
}
6060

61-
public ChatDto createChat(CreateChatDto createChatDto) {
61+
public CreatedChatDto createChat(CreateChatDto createChatDto) {
6262
log.info("now creating");
6363
return webClient.post()
6464
.uri(uriBuilder -> uriBuilder
@@ -67,7 +67,7 @@ public ChatDto createChat(CreateChatDto createChatDto) {
6767
)
6868
.body(Mono.just(createChatDto), CreateChatDto.class)
6969
.retrieve()
70-
.bodyToMono(ChatDto.class)
70+
.bodyToMono(CreatedChatDto.class)
7171
.block();
7272
}
7373

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package net.dancier.dancer.chat.dto;
2+
3+
import java.util.UUID;
4+
5+
public class CreatedChatDto {
6+
public UUID id;
7+
}

src/test/java/net/dancier/dancer/chat/ChatControllerTest.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
import org.junit.jupiter.api.Test;
1212
import org.springframework.beans.factory.annotation.Autowired;
1313
import org.springframework.boot.test.mock.mockito.MockBean;
14+
import org.springframework.http.HttpHeaders;
15+
import org.springframework.http.HttpStatus;
1416
import org.springframework.http.MediaType;
17+
import org.springframework.http.ResponseEntity;
1518
import org.springframework.security.test.context.support.WithUserDetails;
1619
import org.springframework.test.web.servlet.ResultActions;
1720

@@ -84,16 +87,18 @@ void postChatShouldReturnTheChat() throws Exception {
8487
createdChat.setParticipantIds(dancerIds);
8588
createdChat.setChatId(UUID.randomUUID());
8689

87-
when(chatServiceClient.createChat(chat)).thenReturn(createdChat);
90+
CreatedChatDto createdChatDto = new CreatedChatDto();
91+
createdChatDto.id = UUID.randomUUID();
92+
93+
when(chatServiceClient.createChat(chat)).thenReturn(createdChatDto);
8894

8995
ResultActions result = mockMvc.perform(post("/chats")
9096
.contentType(MediaType.APPLICATION_JSON)
9197
.content(objectMapper.writeValueAsBytes(chat)))
9298
.andExpect(status().isCreated())
9399
.andExpect(header().exists("Location"));
94100

95-
result.andExpect(jsonPath("$.participantIds").isNotEmpty());
96-
result.andExpect(jsonPath("$.chatId").isNotEmpty());
101+
result.andExpect(jsonPath("$").doesNotExist());
97102
}
98103

99104
@Test

0 commit comments

Comments
 (0)