Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,20 +37,22 @@ public ChatResponse chat(@DestinationVariable("coin_id") Long coin_id,
@Operation(summary = "코인별 채팅 전체 메시지 조회 API",
description = "특정 코인의 채팅방의 전체 메시지를 보여줍니다.")
public ApiResponse<Page<ChatResponse>> 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<ChatResponse> getLatestMessages(
@PathVariable("coin_id") Long coin_id) {

public ApiResponse<ChatResponse> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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())
Expand All @@ -27,6 +32,7 @@ public static ChatResponse toChatResponse(Chat chat) {
.likes(chat.getChatLikeList().size())
.createdAt(chat.getCreatedAt())
.nickname(chat.getUser().getNickname())
.isLiked(isLiked)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChatResponse> getChatList(Long coin_id, Pageable pageable) {
public Page<ChatResponse> getChatList(Long coin_id, Pageable pageable, User user) {

Page<Chat> 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에 해당하는 밈코인 없을 때
Expand All @@ -68,7 +69,7 @@ public ChatResponse getLatestMessages(Long coin_id) {
}

// 최신 댓글을 ChatResponse로 변환하여 반환
return ChatConverter.toChatResponse(latestChat);
return ChatConverter.toChatResponse(latestChat, user);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class CollectionQueryServiceImpl implements CollectionQueryService {
public Page<Collection> 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);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static NotificationResponse toNotificationCreateResponse(Notification not
.stTime(notification.getStTime())
.isRising(notification.getIsRising())
.isOn(notification.getIsOn())
.coinId(memeCoin.getId())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ public class NotificationResponse {

@Schema(description = "알림 켜기/끄기", example = "True")
private Boolean isOn;

@Schema(description = "코인 아이디", example = "1")
private Long coinId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public Page<MemeCoin> 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);
};
Expand Down