Skip to content

Commit 6a02736

Browse files
committed
new: Added LastMessageResponseDto.messagesId for MessageRepository.java and frontends
1 parent 9f1ca30 commit 6a02736

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

src/main/java/com/chat/yourway/dto/response/notification/LastMessageResponseDto.java

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,22 @@
44
import java.util.UUID;
55

66
import com.fasterxml.jackson.annotation.JsonFormat;
7-
import lombok.Getter;
8-
import lombok.NoArgsConstructor;
9-
import lombok.Setter;
10-
import lombok.ToString;
7+
import io.swagger.v3.oas.annotations.media.Schema;
8+
import jakarta.persistence.GeneratedValue;
9+
import jakarta.persistence.GenerationType;
10+
import jakarta.persistence.Id;
11+
import lombok.*;
1112

1213
@NoArgsConstructor
14+
@AllArgsConstructor
1315
@Getter
1416
@Setter
1517
@ToString
1618
public class LastMessageResponseDto {
17-
19+
private UUID messagesId;
1820
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm")
1921
private LocalDateTime timestamp;
2022
private String sentFrom;
2123
private String lastMessage;
2224
private UUID topicId;
23-
24-
public LastMessageResponseDto(LocalDateTime timestamp,
25-
String sentFrom,
26-
String lastMessage,
27-
UUID topicId) {
28-
this.timestamp = timestamp;
29-
this.sentFrom = sentFrom;
30-
this.lastMessage = lastMessage;
31-
this.topicId = topicId;
32-
}
3325
}

src/main/java/com/chat/yourway/repository/jpa/MessageRepository.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ SELECT COUNT(*)
4949

5050
@Query("""
5151
SELECT new com.chat.yourway.dto.response.notification.LastMessageResponseDto(
52-
tm.timestamp, tm.sender.nickname, tm.content, t.id
53-
) FROM Topic t
52+
tm.id, tm.timestamp, tm.sender.nickname, tm.content, t.id
53+
)
54+
FROM Topic t
5455
LEFT JOIN t.messages tm
5556
WHERE t.scope = :scope
5657
AND (tm.timestamp IN (SELECT MAX(tm2.timestamp) FROM Message tm2 WHERE tm2.topic = t) OR tm IS NULL)
@@ -59,7 +60,7 @@ SELECT COUNT(*)
5960

6061
@Query("""
6162
SELECT new com.chat.yourway.dto.response.notification.LastMessageResponseDto(
62-
tm.timestamp, tm.sender.nickname, tm.content, t.id
63+
tm.id, tm.timestamp, tm.sender.nickname, tm.content, t.id
6364
)
6465
FROM Topic t
6566
LEFT JOIN t.messages tm

0 commit comments

Comments
 (0)