File tree Expand file tree Collapse file tree
src/main/java/com/next/intune/chat Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111@ AllArgsConstructor
1212public class MatchResponseDto {
1313 private Long matchId ;
14- private Long requesterId ;
15- private Long responderId ;
14+ private String name ;
15+ private String lastMessage ;
1616 private boolean approved ;
1717 private boolean valid ;
1818 private Instant createdAt ;
Original file line number Diff line number Diff line change 1111public interface MatchRepository extends JpaRepository <Match ,Long > {
1212 @ Query (value = """
1313 SELECT m.`match_id` AS matchId,
14- m.`requester_id` AS requesterId,
15- m.`responder_id` AS responderId,
14+ CASE
15+ WHEN m.`requester_id` = :userId THEN u2.`name`
16+ WHEN m.`responder_id` = :userId THEN u1.`name`
17+ END AS `name`,
18+ (
19+ SELECT ch.`chat`
20+ FROM `intune-chat`.`chats_history` ch
21+ WHERE ch.`match_id` = m.`match_id`
22+ ORDER BY ch.`created_at` DESC
23+ LIMIT 1
24+ ) AS `lastMessage`,
1625 m.`is_approved` AS approved,
1726 m.`is_valid` AS valid,
1827 m.`created_at` AS createdAt,
1928 m.`updated_at` AS updatedAt
2029 FROM `intune-chat`.`matches` m
30+ JOIN `intune-member`.`users` u1
31+ ON m.`requester_id` = u1.`user_id`
32+ JOIN `intune-member`.`users` u2
33+ ON m.`responder_id` = u2.`user_id`
2134 WHERE (m.`requester_id` = :userId OR m.`responder_id` = :userId)
2235 AND m.`is_valid` = 1
2336 ORDER BY m.`updated_at` DESC
Original file line number Diff line number Diff line change 44
55public interface MatchRow {
66 Long getMatchId ();
7- Long getRequesterId ();
8- Long getResponderId ();
7+ String getName ();
8+ String getLastMessage ();
99 boolean isApproved ();
1010 boolean isValid ();
1111 Instant getCreatedAt ();
Original file line number Diff line number Diff line change @@ -109,8 +109,8 @@ public List<MatchResponseDto> getMatches(HttpServletRequest request) {
109109 return matchRepository .findAllValidRowsByUser (user .getUserId ()).stream ()
110110 .map (r -> MatchResponseDto .builder ()
111111 .matchId (r .getMatchId ())
112- .requesterId (r .getRequesterId ())
113- .responderId (r .getResponderId ())
112+ .name (r .getName ())
113+ .lastMessage (r .getLastMessage ())
114114 .approved (r .isApproved ())
115115 .valid (r .isValid ())
116116 .createdAt (r .getCreatedAt ())
You can’t perform that action at this time.
0 commit comments