diff --git a/src/main/java/com/team/cklob/gami/domain/admin/dto/response/AdminReportResponse.java b/src/main/java/com/team/cklob/gami/domain/admin/dto/response/AdminReportResponse.java index 9a38e81e..ca7f0f20 100644 --- a/src/main/java/com/team/cklob/gami/domain/admin/dto/response/AdminReportResponse.java +++ b/src/main/java/com/team/cklob/gami/domain/admin/dto/response/AdminReportResponse.java @@ -1,6 +1,7 @@ package com.team.cklob.gami.domain.admin.dto.response; import com.team.cklob.gami.domain.report.entity.Report; +import com.team.cklob.gami.domain.report.entity.constant.ReportResult; import com.team.cklob.gami.domain.report.entity.constant.ReportType; import lombok.Builder; import lombok.Getter; @@ -11,11 +12,17 @@ public class AdminReportResponse { private final Long id; private final ReportType reportType; + private final ReportResult reportResult; + private final String reporterName; + private final Long reportedPostId; public static AdminReportResponse from(Report report) { return AdminReportResponse.builder() .id(report.getId()) .reportType(report.getReportType()) + .reportResult(report.getResult()) + .reporterName(report.getReporter().getName()) + .reportedPostId(report.getPost().getId()) .build(); } } diff --git a/src/main/java/com/team/cklob/gami/domain/admin/service/impl/AdminReportListServiceImpl.java b/src/main/java/com/team/cklob/gami/domain/admin/service/impl/AdminReportListServiceImpl.java index a70e47d4..236b7be9 100644 --- a/src/main/java/com/team/cklob/gami/domain/admin/service/impl/AdminReportListServiceImpl.java +++ b/src/main/java/com/team/cklob/gami/domain/admin/service/impl/AdminReportListServiceImpl.java @@ -18,7 +18,7 @@ public class AdminReportListServiceImpl implements AdminReportListService { @Override public List getReports() { - return reportRepository.findAll() + return reportRepository.findAllWithReporterAndPost() .stream() .map(AdminReportResponse::from) .toList(); diff --git a/src/main/java/com/team/cklob/gami/domain/chat/entity/ChatRoom.java b/src/main/java/com/team/cklob/gami/domain/chat/entity/ChatRoom.java index 9e2b3720..f8824481 100644 --- a/src/main/java/com/team/cklob/gami/domain/chat/entity/ChatRoom.java +++ b/src/main/java/com/team/cklob/gami/domain/chat/entity/ChatRoom.java @@ -47,6 +47,9 @@ public class ChatRoom { @Column(name = "last_message", nullable = false) private String lastMessage; + @Column(name = "last_message_at") + private LocalDateTime lastMessageAt; + @CreatedDate @Column(name = "created_at", updatable = false, nullable = false) private LocalDateTime createdAt; @@ -103,7 +106,8 @@ public boolean isMember(Member member) { || member.getId().equals(mentee.getId()); } - public void updateLastMessage(String message) { + public void updateLastMessage(String message, LocalDateTime lastMessageAt) { this.lastMessage = message; + this.lastMessageAt = lastMessageAt; } } diff --git a/src/main/java/com/team/cklob/gami/domain/chat/repository/ChatRoomRepository.java b/src/main/java/com/team/cklob/gami/domain/chat/repository/ChatRoomRepository.java index a73e23cf..c84f745f 100644 --- a/src/main/java/com/team/cklob/gami/domain/chat/repository/ChatRoomRepository.java +++ b/src/main/java/com/team/cklob/gami/domain/chat/repository/ChatRoomRepository.java @@ -29,5 +29,12 @@ boolean existsByRoomIdAndMemberId( Optional findOtherMemberInRoom(@Param("roomId") Long roomId, @Param("memberId") Long memberId); - List findAllByMentorIdOrMenteeId(Long mentorId, Long menteeId); + @Query(""" + select cr from ChatRoom cr + where cr.mentor.id = :memberId or cr.mentee.id = :memberId + order by cr.lastMessageAt desc nulls last + """) + List findAllByMentorIdOrMenteeId( + @Param("memberId") Long memberId + ); } diff --git a/src/main/java/com/team/cklob/gami/domain/chat/service/impl/ChatMessageServiceImpl.java b/src/main/java/com/team/cklob/gami/domain/chat/service/impl/ChatMessageServiceImpl.java index 7f668765..847d4cdc 100644 --- a/src/main/java/com/team/cklob/gami/domain/chat/service/impl/ChatMessageServiceImpl.java +++ b/src/main/java/com/team/cklob/gami/domain/chat/service/impl/ChatMessageServiceImpl.java @@ -68,7 +68,7 @@ public void execute(Long roomId, ChatMessageRequest request, Principal principal .build(); chatMessageRepository.save(message); - chatRoom.updateLastMessage(request.message()); + chatRoom.updateLastMessage(request.message(), message.getCreatedAt()); ChatMessageResponse response = new ChatMessageResponse( message.getId(), diff --git a/src/main/java/com/team/cklob/gami/domain/chat/service/impl/GetChatRoomListServiceImpl.java b/src/main/java/com/team/cklob/gami/domain/chat/service/impl/GetChatRoomListServiceImpl.java index 94834d04..0ee5a4a9 100644 --- a/src/main/java/com/team/cklob/gami/domain/chat/service/impl/GetChatRoomListServiceImpl.java +++ b/src/main/java/com/team/cklob/gami/domain/chat/service/impl/GetChatRoomListServiceImpl.java @@ -31,7 +31,7 @@ public List execute() { Member member = memberUtil.getCurrentMember(); List chatRoomList = chatRoomRepository - .findAllByMentorIdOrMenteeId(member.getId(), member.getId()); + .findAllByMentorIdOrMenteeId(member.getId()); List otherMemberIds = chatRoomList.stream() .map(chatRoom -> { diff --git a/src/main/java/com/team/cklob/gami/domain/report/repository/ReportRepository.java b/src/main/java/com/team/cklob/gami/domain/report/repository/ReportRepository.java index 040b584f..d1313f85 100644 --- a/src/main/java/com/team/cklob/gami/domain/report/repository/ReportRepository.java +++ b/src/main/java/com/team/cklob/gami/domain/report/repository/ReportRepository.java @@ -3,6 +3,9 @@ import com.team.cklob.gami.domain.report.entity.Report; import com.team.cklob.gami.domain.report.entity.constant.ReportType; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import java.util.List; public interface ReportRepository extends JpaRepository { @@ -11,4 +14,12 @@ boolean existsByReporterIdAndPostIdAndReportType( Long postId, ReportType reportType ); + + @Query(""" + SELECT r + FROM Report r + JOIN FETCH r.reporter + JOIN FETCH r.post + """) + List findAllWithReporterAndPost(); }