diff --git a/src/main/java/com/memesphere/domain/chat/controller/ChatController.java b/src/main/java/com/memesphere/domain/chat/controller/ChatController.java index e315d4e2..f30231f0 100644 --- a/src/main/java/com/memesphere/domain/chat/controller/ChatController.java +++ b/src/main/java/com/memesphere/domain/chat/controller/ChatController.java @@ -3,6 +3,7 @@ import com.memesphere.domain.chat.dto.request.ChatRequest; import com.memesphere.domain.chat.dto.response.ChatResponse; import com.memesphere.domain.chat.service.ChatService; +import com.memesphere.domain.user.entity.User; import com.memesphere.global.apipayload.ApiResponse; import com.memesphere.global.jwt.CustomUserDetails; import io.swagger.v3.oas.annotations.Operation; @@ -36,20 +37,22 @@ public ChatResponse chat(@DestinationVariable("coin_id") Long coin_id, @Operation(summary = "코인별 채팅 전체 메시지 조회 API", description = "특정 코인의 채팅방의 전체 메시지를 보여줍니다.") public ApiResponse> getChatList(@PathVariable("coin_id") Long coin_id, - Pageable pageable) { + Pageable pageable, + @AuthenticationPrincipal CustomUserDetails customUserDetails) { + User user = (customUserDetails != null) ? customUserDetails.getUser() : null; - return ApiResponse.onSuccess(chatService.getChatList(coin_id, pageable)); + return ApiResponse.onSuccess(chatService.getChatList(coin_id, pageable, user)); } //최신 댓글 조회 Api @GetMapping("/chat/{coin_id}/latest") @Operation(summary = "코인별 최신 댓글 조회 API", description = "특정 코인에 대한 최신 댓글을 반환합니다. 요청 시 최신 댓글 하나만 가져옵니다.") - public ApiResponse getLatestMessages( - @PathVariable("coin_id") Long coin_id) { - + public ApiResponse getLatestMessages(@PathVariable("coin_id") Long coin_id, + @AuthenticationPrincipal CustomUserDetails customUserDetails) { + User user = customUserDetails.getUser(); // 최신 댓글을 가져오는 서비스 메서드 호출 - ChatResponse latestMessage = chatService.getLatestMessages(coin_id); + ChatResponse latestMessage = chatService.getLatestMessages(coin_id, user); return ApiResponse.onSuccess(latestMessage); } diff --git a/src/main/java/com/memesphere/domain/chat/converter/ChatConverter.java b/src/main/java/com/memesphere/domain/chat/converter/ChatConverter.java index 6ab763aa..ba43db24 100644 --- a/src/main/java/com/memesphere/domain/chat/converter/ChatConverter.java +++ b/src/main/java/com/memesphere/domain/chat/converter/ChatConverter.java @@ -7,6 +7,9 @@ import com.memesphere.domain.chat.dto.response.ChatResponse; import com.memesphere.domain.user.entity.User; +import java.util.Objects; +import java.util.stream.Collectors; + public class ChatConverter { public static Chat toChat(MemeCoin memeCoin, ChatRequest chatRequest, User user) { @@ -18,7 +21,9 @@ public static Chat toChat(MemeCoin memeCoin, ChatRequest chatRequest, User user) .build(); } - public static ChatResponse toChatResponse(Chat chat) { + public static ChatResponse toChatResponse(Chat chat, User user) { + boolean isLiked = user != null && chat.getChatLikeList().stream() + .anyMatch(chatLike -> Objects.equals(chatLike.getUser().getId(), user.getId())); return ChatResponse.builder() .id(chat.getId()) @@ -27,6 +32,7 @@ public static ChatResponse toChatResponse(Chat chat) { .likes(chat.getChatLikeList().size()) .createdAt(chat.getCreatedAt()) .nickname(chat.getUser().getNickname()) + .isLiked(isLiked) .build(); } diff --git a/src/main/java/com/memesphere/domain/chat/dto/response/ChatResponse.java b/src/main/java/com/memesphere/domain/chat/dto/response/ChatResponse.java index 336c3fb8..6374cebb 100644 --- a/src/main/java/com/memesphere/domain/chat/dto/response/ChatResponse.java +++ b/src/main/java/com/memesphere/domain/chat/dto/response/ChatResponse.java @@ -25,6 +25,9 @@ public class ChatResponse { @Schema(description = "좋아요 수", example = "17") private int likes; + @Schema(description = "좋아요 여부", example = "True") + private boolean isLiked; + @Schema(description = "전송 시간", example = "2025-01-01T00:00:00") private LocalDateTime createdAt; } diff --git a/src/main/java/com/memesphere/domain/chat/service/ChatService.java b/src/main/java/com/memesphere/domain/chat/service/ChatService.java index e2d93afd..c09ba1a7 100644 --- a/src/main/java/com/memesphere/domain/chat/service/ChatService.java +++ b/src/main/java/com/memesphere/domain/chat/service/ChatService.java @@ -41,19 +41,20 @@ public ChatResponse saveMessage(Long coin_id, ChatRequest chatRequest) { Chat chat = ChatConverter.toChat(memeCoin, chatRequest, user); Chat savedChat = chatRepository.save(chat); - return ChatConverter.toChatResponse(savedChat); + return ChatConverter.toChatResponse(savedChat, user); } @Transactional - public Page getChatList(Long coin_id, Pageable pageable) { + public Page getChatList(Long coin_id, Pageable pageable, User user) { Page chatPage = chatRepository.findAllByMemeCoin_Id(coin_id, pageable); - return chatPage.map(ChatConverter::toChatResponse); + + return chatPage.map(chat -> ChatConverter.toChatResponse(chat, user)); } // 최신 댓글을 가져오는 메서드 @Transactional - public ChatResponse getLatestMessages(Long coin_id) { + public ChatResponse getLatestMessages(Long coin_id, User user) { MemeCoin memeCoin = memeCoinRepository.findById(coin_id) //id에 해당하는 밈코인 없을 때 @@ -68,7 +69,7 @@ public ChatResponse getLatestMessages(Long coin_id) { } // 최신 댓글을 ChatResponse로 변환하여 반환 - return ChatConverter.toChatResponse(latestChat); + return ChatConverter.toChatResponse(latestChat, user); } @Transactional diff --git a/src/main/java/com/memesphere/domain/collection/service/CollectionQueryServiceImpl.java b/src/main/java/com/memesphere/domain/collection/service/CollectionQueryServiceImpl.java index ad3ef60a..f9c89ebe 100644 --- a/src/main/java/com/memesphere/domain/collection/service/CollectionQueryServiceImpl.java +++ b/src/main/java/com/memesphere/domain/collection/service/CollectionQueryServiceImpl.java @@ -28,7 +28,7 @@ public class CollectionQueryServiceImpl implements CollectionQueryService { public Page getCollectionPage(Long userId, Integer pageNumber, ViewType viewType, SortType sortType) { int pageSize = switch (viewType) { - case GRID -> 9; + case GRID -> 12; case LIST -> 20; default -> throw new GeneralException(ErrorStatus.UNSUPPORTED_VIEW_TYPE); }; diff --git a/src/main/java/com/memesphere/domain/dashboard/service/DashboardQueryServiceImpl.java b/src/main/java/com/memesphere/domain/dashboard/service/DashboardQueryServiceImpl.java index cabed42c..13f9ee55 100644 --- a/src/main/java/com/memesphere/domain/dashboard/service/DashboardQueryServiceImpl.java +++ b/src/main/java/com/memesphere/domain/dashboard/service/DashboardQueryServiceImpl.java @@ -77,7 +77,7 @@ public SearchPageResponse getChartPage(Long userId, ViewType viewType, SortType Collections.emptyList() : collectionQueryService.getUserCollectionIds(userId); int pageSize = switch (viewType) { - case GRID -> 9; + case GRID -> 12; case LIST -> 20; default -> throw new GeneralException(ErrorStatus.UNSUPPORTED_VIEW_TYPE); }; diff --git a/src/main/java/com/memesphere/domain/notification/converter/NotificationConverter.java b/src/main/java/com/memesphere/domain/notification/converter/NotificationConverter.java index fb1f53c9..72cbf33f 100644 --- a/src/main/java/com/memesphere/domain/notification/converter/NotificationConverter.java +++ b/src/main/java/com/memesphere/domain/notification/converter/NotificationConverter.java @@ -31,6 +31,7 @@ public static NotificationResponse toNotificationCreateResponse(Notification not .stTime(notification.getStTime()) .isRising(notification.getIsRising()) .isOn(notification.getIsOn()) + .coinId(memeCoin.getId()) .build(); } diff --git a/src/main/java/com/memesphere/domain/notification/dto/response/NotificationResponse.java b/src/main/java/com/memesphere/domain/notification/dto/response/NotificationResponse.java index 10f59e61..3abe288d 100644 --- a/src/main/java/com/memesphere/domain/notification/dto/response/NotificationResponse.java +++ b/src/main/java/com/memesphere/domain/notification/dto/response/NotificationResponse.java @@ -28,4 +28,7 @@ public class NotificationResponse { @Schema(description = "알림 켜기/끄기", example = "True") private Boolean isOn; + + @Schema(description = "코인 아이디", example = "1") + private Long coinId; } diff --git a/src/main/java/com/memesphere/domain/search/service/SearchQueryServiceImpl.java b/src/main/java/com/memesphere/domain/search/service/SearchQueryServiceImpl.java index 28a46a5f..bd9267a2 100644 --- a/src/main/java/com/memesphere/domain/search/service/SearchQueryServiceImpl.java +++ b/src/main/java/com/memesphere/domain/search/service/SearchQueryServiceImpl.java @@ -26,7 +26,7 @@ public Page getSearchPage(String searchWord, ViewType viewType, SortTy // sortType --> MKT_CAP, VOLUME_24H, PRICE int pageSize = switch (viewType) { - case GRID -> 9; + case GRID -> 12; case LIST -> 20; default -> throw new GeneralException(ErrorStatus.UNSUPPORTED_VIEW_TYPE); };