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
@@ -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;
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class AdminReportListServiceImpl implements AdminReportListService {

@Override
public List<AdminReportResponse> getReports() {
return reportRepository.findAll()
return reportRepository.findAllWithReporterAndPost()
.stream()
.map(AdminReportResponse::from)
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,12 @@ boolean existsByRoomIdAndMemberId(
Optional<MemberDetail> findOtherMemberInRoom(@Param("roomId") Long roomId,
@Param("memberId") Long memberId);

List<ChatRoom> 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<ChatRoom> findAllByMentorIdOrMenteeId(
@Param("memberId") Long memberId
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public List<GetChatRoomListResponse> execute() {
Member member = memberUtil.getCurrentMember();

List<ChatRoom> chatRoomList = chatRoomRepository
.findAllByMentorIdOrMenteeId(member.getId(), member.getId());
.findAllByMentorIdOrMenteeId(member.getId());

List<Long> otherMemberIds = chatRoomList.stream()
.map(chatRoom -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Report, Long> {

Expand All @@ -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<Report> findAllWithReporterAndPost();
}