Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor/chatroom-lastchat-1: 마지막 채팅을 객체 자체를 return 하도록 수정 #316

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/main/java/com/dife/api/controller/BookmarkController.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ public class BookmarkController implements SwaggerBookmarkController {

private final BookmarkService bookmarkService;

@GetMapping
public ResponseEntity<List<BookmarkResponseDto>> getAllBookmarks(Authentication authentication) {
List<BookmarkResponseDto> bookmarks = bookmarkService.getAllBookmarks(authentication.getName());
return ResponseEntity.ok(bookmarks);
}

@PostMapping
public ResponseEntity<BookmarkResponseDto> createBookmark(
@RequestBody BookmarkCreateRequestDto requestDto, Authentication auth) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@
@Tag(name = "Bookmark API", description = "북마크 서비스 API")
public interface SwaggerBookmarkController {

@Operation(summary = "모든 북마크 조회 API", description = "사용자가 생성한 모든 (채팅/게시글) 북마크를 조회해주는 API입니다.")
@ApiResponse(
responseCode = "200",
description = "단일 북마크 조회 예시",
content = {
@Content(
mediaType = "application/json",
schema = @Schema(implementation = BookmarkResponseDto.class))
})
ResponseEntity<List<BookmarkResponseDto>> getAllBookmarks(Authentication authentication);

@Operation(
summary = "북마크 생성 API",
description = "사용자가 DTO를 작성해 채팅/게시글 북마크를 생성하는 API입니다. 북마크 타입 : CHAT, POST, COMMENT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ public interface ChatroomResponseDto {

Set<MemberRestrictedResponseDto> getMembers();

String getLastChat();
ChatResponseDto getLastChat();
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ public class GroupChatroomResponseDto implements ChatroomResponseDto {

private Boolean isEntered;

private String lastChat;
private ChatResponseDto lastChat;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ public class SingleChatroomResponseDto implements ChatroomResponseDto {

private Long unreadChatsCount = 0L;

private String lastChat;
private ChatResponseDto lastChat;
}
4 changes: 3 additions & 1 deletion src/main/java/com/dife/api/service/BookmarkService.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ public List<BookmarkResponseDto> getChatroomBookmarks(
bookmarks = bookmarkRepository.findBookmarksByMemberAndChatroom(member, chatroomId);
bookmarks.sort(Comparator.comparing(Bookmark::getCreated).reversed());

} else {
} else if (boardType != null) {
bookmarks = bookmarkRepository.findBookmarkByMemberAndPost_BoardCategory(member, boardType);
} else {
return getAllBookmarks(memberEmail);
}

return bookmarks.stream()
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/dife/api/service/ChatroomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ public SingleChatroomResponseDto getSingleChatroom(Long id, String memberEmail)
chatroomModelMapper.map(chatroom, SingleChatroomResponseDto.class);

changeChatroomMemberToMemberSet(chatroom, responseDto);
responseDto.setLastChat(getLastChat(chatroom, member));
Chat chat = getLastChat(chatroom, member);
responseDto.setLastChat(modelMapper.map(chat, ChatResponseDto.class));
responseDto.setUnreadChatsCount(getChatCounts(chatroomMember));
return responseDto;
}
Expand Down Expand Up @@ -459,7 +460,7 @@ public void chatroomReEnter(Long chatroomId, String memberEmail) {
throw new ChatroomReEnterException("채팅방 재입장에 실패했습니다");
}

private String getLastChat(Chatroom chatroom, Member member) {
private Chat getLastChat(Chatroom chatroom, Member member) {

ChatroomMember chatroomMember =
chatroomMemberRepository
Expand All @@ -472,7 +473,7 @@ private String getLastChat(Chatroom chatroom, Member member) {
.filter(chat -> chat.getCreated().isAfter(last_joined_at))
.sorted(Comparator.comparing(Chat::getCreated).reversed())
.toList();
return chats.isEmpty() ? "" : chats.get(0).getMessage();
return chats.isEmpty() ? null : chats.get(0);
}

public GroupChatroomResponseDto getGroupChatroom(Long id, String memberEmail) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ spring:
redis:
host: ${REDIS_HOST}
port: ${REDIS_PORT}

jackson:
time-zone: Asia/Seoul
translation:
api-key: ${DEEPL_TRANSLATE_API_KEY}

Expand Down
Loading