-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marc Gorzala
committed
Dec 14, 2023
1 parent
6547ef7
commit c145a21
Showing
48 changed files
with
967 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ target/ | |
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
volumes | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 0 additions & 35 deletions
35
src/main/java/net/dancier/chatdancer/adapter/in/ChatsByParticipantsController.java
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
src/main/java/net/dancier/chatdancer/adapter/in/CreateChatController.java
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
src/main/java/net/dancier/chatdancer/adapter/in/CreateChatDto.java
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
src/main/java/net/dancier/chatdancer/adapter/in/web/GetChatResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package net.dancier.chatdancer.adapter.in.web; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import net.dancier.chatdancer.application.domain.model.Chat; | ||
import net.dancier.chatdancer.application.domain.model.Message; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.time.ZoneOffset; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
import java.util.stream.Collectors; | ||
|
||
@Data | ||
@Builder | ||
public class GetChatResponseDto { | ||
public static GetChatResponseDto of(Chat chat) { | ||
Optional<Message> optionalLastMessage = chat.getMessages().stream().reduce((first, second) -> second); | ||
return GetChatResponseDto.builder() | ||
.chatId(chat.getChatId().getId()) | ||
.participantIds( | ||
chat.getChatParticipants().stream() | ||
.map(Chat.ParticipantId::getId).collect(Collectors.toSet()) | ||
).createdAt(OffsetDateTime.of(chat.getCreatedAt(), ZoneOffset.UTC)) | ||
.lastMessage( | ||
MessageDto.of( | ||
chat.getMessages().stream().reduce( | ||
(first, second) -> second | ||
).orElse(null) | ||
) | ||
).lastActivity( | ||
optionalLastMessage | ||
.map(m -> OffsetDateTime.of(m.getCreatedAt(), ZoneOffset.UTC)) | ||
.orElse(null) | ||
) | ||
.build(); | ||
} | ||
|
||
UUID chatId; | ||
Set<String> participantIds; | ||
OffsetDateTime lastActivity; | ||
MessageDto lastMessage; | ||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX") | ||
OffsetDateTime createdAt; | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/net/dancier/chatdancer/adapter/in/web/MessageDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package net.dancier.chatdancer.adapter.in.web; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
import net.dancier.chatdancer.application.domain.model.Message; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.time.ZoneOffset; | ||
import java.util.Set; | ||
|
||
@Data | ||
@Builder | ||
public class MessageDto { | ||
public static MessageDto of(Message message) { | ||
if (message!=null) { | ||
return MessageDto.builder() | ||
.id(message.getId().getValue().toString()) | ||
.text(message.getText()) | ||
.authorId(message.getAuthorId().toString()) | ||
.createdAt(OffsetDateTime.of(message.getCreatedAt(), ZoneOffset.UTC)) | ||
.build(); | ||
} else { | ||
return null; | ||
} | ||
}; | ||
|
||
private String text; | ||
private String id; | ||
private String authorId; | ||
private Set<String> readByParticipants; | ||
private OffsetDateTime createdAt; | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/net/dancier/chatdancer/adapter/in/web/PostChatMessageRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package net.dancier.chatdancer.adapter.in.web; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
import java.util.UUID; | ||
|
||
@Data | ||
@Builder | ||
public class PostChatMessageRequestDto { | ||
@NotNull(message = "The id of the author of the message must be provided") | ||
private String authorId; | ||
private String text; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/net/dancier/chatdancer/adapter/in/web/PostChatRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package net.dancier.chatdancer.adapter.in.web; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
public class PostChatRequestDto { | ||
private List<String> participantIds; | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/net/dancier/chatdancer/adapter/in/web/controller/ChatMessageController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package net.dancier.chatdancer.adapter.in.web.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import net.dancier.chatdancer.adapter.in.web.MessageDto; | ||
import net.dancier.chatdancer.adapter.in.web.PostChatMessageRequestDto; | ||
import net.dancier.chatdancer.application.domain.model.Chat; | ||
import net.dancier.chatdancer.application.domain.model.Message; | ||
import net.dancier.chatdancer.application.port.in.MessagesByChatUseCase; | ||
import net.dancier.chatdancer.application.port.in.PostChatMessageCommand; | ||
import net.dancier.chatdancer.application.port.in.PostChatMessageUseCase; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
import java.util.stream.Collectors; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
public class ChatMessageController { | ||
|
||
public static final Logger log = LoggerFactory.getLogger(ChatMessageController.class); | ||
|
||
private final PostChatMessageUseCase postChatMessageUseCase; | ||
|
||
private final MessagesByChatUseCase messagesByChatUseCase; | ||
|
||
@GetMapping("/h/chats/{chatId}/messages") | ||
public ResponseEntity<List<MessageDto>> getMessages(@PathVariable UUID chatId) { | ||
log.info("Getting all Messages"); | ||
List<Message> messages = messagesByChatUseCase.byChatId(new Chat.ChatId(chatId)); | ||
List<MessageDto> messageDtos = messages.stream().map(m -> MessageDto.of(m)).collect(Collectors.toList()); | ||
return ResponseEntity.ok(messageDtos); | ||
} | ||
|
||
@PostMapping("/h/chats/{chatId}/messages") | ||
public ResponseEntity postChatMessage(@PathVariable UUID chatId, @Validated @RequestBody PostChatMessageRequestDto postChatMessageRequestDto) { | ||
PostChatMessageCommand postChatMessageCommand = new PostChatMessageCommand( | ||
postChatMessageRequestDto.getText(), | ||
new Message.AuthorId(postChatMessageRequestDto.getAuthorId()), | ||
new Chat.ChatId((chatId))); | ||
postChatMessageUseCase.post(postChatMessageCommand); | ||
return ResponseEntity.status(HttpStatus.CREATED).build(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/net/dancier/chatdancer/adapter/in/web/controller/GetChatController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package net.dancier.chatdancer.adapter.in.web.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import net.dancier.chatdancer.adapter.in.web.GetChatResponseDto; | ||
import net.dancier.chatdancer.application.domain.model.Chat; | ||
import net.dancier.chatdancer.application.port.in.GetChatUseCase; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class GetChatController { | ||
|
||
private final static Logger log = LoggerFactory.getLogger(GetChatController.class); | ||
public static final String GET_ENDPOINT = "/h/chats/{id}"; | ||
|
||
private final GetChatUseCase getChatUseCase; | ||
|
||
@GetMapping(value = GET_ENDPOINT) | ||
public ResponseEntity<GetChatResponseDto> getChat(@PathVariable UUID id) { | ||
Chat chat = getChatUseCase.get(new Chat.ChatId(id)); | ||
GetChatResponseDto getChatResponseDto = GetChatResponseDto.of(chat); | ||
return new ResponseEntity(getChatResponseDto, HttpStatus.OK); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...va/net/dancier/chatdancer/adapter/in/web/controller/GetChatsByParticipantsController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package net.dancier.chatdancer.adapter.in.web.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import net.dancier.chatdancer.adapter.in.web.GetChatResponseDto; | ||
import net.dancier.chatdancer.application.domain.model.Chat; | ||
import net.dancier.chatdancer.application.domain.service.ChatsByParticipantsService; | ||
import net.dancier.chatdancer.application.port.in.ChatsByParticipantQuery; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
public class GetChatsByParticipantsController { | ||
|
||
public static final Logger log = LoggerFactory.getLogger(GetChatsByParticipantsController.class); | ||
|
||
private final ChatsByParticipantsService chatsByParticipantsService; | ||
|
||
@GetMapping("/h/chats") | ||
public ResponseEntity<List<GetChatResponseDto>> getAllChats(@RequestParam String participantId) { | ||
log.info("Getting all Chats for " + participantId); | ||
ChatsByParticipantQuery query = new ChatsByParticipantQuery(new Chat.ParticipantId(participantId.toString())); | ||
List<Chat> chats = chatsByParticipantsService.load(query); | ||
List<GetChatResponseDto> responseList = chats.stream().map(c -> GetChatResponseDto.of(c)).collect(Collectors.toList()); | ||
return new ResponseEntity<>(responseList, HttpStatus.OK); | ||
} | ||
|
||
} |
Oops, something went wrong.