Skip to content

Commit

Permalink
new api
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Gorzala committed Dec 15, 2023
1 parent 1b9777f commit 8efd185
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/main/java/net/dancier/dancer/chat/ChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.dancier.dancer.chat.client.ChatServiceClient;
import net.dancier.dancer.chat.client.RemoteCreateMessageDto;
import net.dancier.dancer.chat.dto.*;
import net.dancier.dancer.core.DancerService;
import net.dancier.dancer.core.exception.BusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -28,7 +27,7 @@ public ChatsDto getChatsByUserId(UUID dancerId) {
}

public ChatDto createChat(UUID dancerId, CreateChatDto createChatDto) {
throwIfDancerIsNotInChat(createChatDto.getDancerIds(), dancerId);
throwIfDancerIsNotInChat(createChatDto.getParticipantIds(), dancerId);

return chatServiceClient.createChat(createChatDto);
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/net/dancier/dancer/chat/dto/CreateChatDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@

@Data
public class CreateChatDto {
private List<UUID> dancerIds;
@Enumerated(EnumType.STRING)
private ChatType type;
private List<UUID> participantIds;
}
8 changes: 2 additions & 6 deletions src/test/java/net/dancier/dancer/chat/ChatControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,10 @@ public class PostChats {
void postChatShouldReturnTheChat() throws Exception {
List dancerIds = List.of(dancerId, UUID.randomUUID());
CreateChatDto chat = new CreateChatDto();
chat.setDancerIds(dancerIds);
chat.setType(ChatType.DIRECT);
chat.setParticipantIds(dancerIds);

ChatDto createdChat = new ChatDto();
createdChat.setDancerIds(dancerIds);
createdChat.setType(ChatType.DIRECT);
createdChat.setChatId(UUID.randomUUID());

when(chatServiceClient.createChat(chat)).thenReturn(createdChat);
Expand All @@ -96,16 +94,14 @@ void postChatShouldReturnTheChat() throws Exception {

result.andExpect(jsonPath("$.dancerIds").isNotEmpty());
result.andExpect(jsonPath("$.chatId").isNotEmpty());
result.andExpect(jsonPath("$.type").value(ChatType.DIRECT.name()));
}

@Test
@WithUserDetails("user-with-a-profile@dancier.net")
void postChatShouldNotCreateTheChatIfUserIsNotPartOfIt() throws Exception {
List dancerIds = List.of(UUID.randomUUID(), UUID.randomUUID());
CreateChatDto chat = new CreateChatDto();
chat.setDancerIds(dancerIds);
chat.setType(ChatType.DIRECT);
chat.setParticipantIds(dancerIds);

mockMvc.perform(post("/chats")
.contentType(MediaType.APPLICATION_JSON)
Expand Down

0 comments on commit 8efd185

Please sign in to comment.