WIP: Update morefiles #152

Closed
RecentRunner wants to merge 183 commits from main into morefiles
4 changed files with 132 additions and 12 deletions
Showing only changes of commit 6bde4f4e47 - Show all commits

View File

@@ -1,18 +1,15 @@
package com.petshop.backend.dto.chat;
import jakarta.validation.constraints.NotBlank;
public class MessageRequest {
@NotBlank(message = "Message content is required")
private String content;
private String attachmentUrl;
private String attachmentName;
private String attachmentMimeType;
private Long attachmentSizeBytes;
public MessageRequest() {
}
public MessageRequest(String content) {
this.content = content;
}
public String getContent() {
return content;
}
@@ -20,4 +17,36 @@ public class MessageRequest {
public void setContent(String content) {
this.content = content;
}
public String getAttachmentUrl() {
return attachmentUrl;
}
public void setAttachmentUrl(String attachmentUrl) {
this.attachmentUrl = attachmentUrl;
}
public String getAttachmentName() {
return attachmentName;
}
public void setAttachmentName(String attachmentName) {
this.attachmentName = attachmentName;
}
public String getAttachmentMimeType() {
return attachmentMimeType;
}
public void setAttachmentMimeType(String attachmentMimeType) {
this.attachmentMimeType = attachmentMimeType;
}
public Long getAttachmentSizeBytes() {
return attachmentSizeBytes;
}
public void setAttachmentSizeBytes(Long attachmentSizeBytes) {
this.attachmentSizeBytes = attachmentSizeBytes;
}
}

View File

@@ -11,6 +11,10 @@ public class MessageResponse {
private String content;
private LocalDateTime timestamp;
private Boolean isRead;
private String attachmentUrl;
private String attachmentName;
private String attachmentMimeType;
private Long attachmentSizeBytes;
public MessageResponse() {
}
@@ -32,6 +36,10 @@ public class MessageResponse {
response.setContent(message.getContent());
response.setTimestamp(message.getTimestamp());
response.setIsRead(message.getIsRead());
response.setAttachmentUrl(message.getAttachmentUrl());
response.setAttachmentName(message.getAttachmentName());
response.setAttachmentMimeType(message.getAttachmentMimeType());
response.setAttachmentSizeBytes(message.getAttachmentSizeBytes());
return response;
}
@@ -82,4 +90,36 @@ public class MessageResponse {
public void setIsRead(Boolean isRead) {
this.isRead = isRead;
}
public String getAttachmentUrl() {
return attachmentUrl;
}
public void setAttachmentUrl(String attachmentUrl) {
this.attachmentUrl = attachmentUrl;
}
public String getAttachmentName() {
return attachmentName;
}
public void setAttachmentName(String attachmentName) {
this.attachmentName = attachmentName;
}
public String getAttachmentMimeType() {
return attachmentMimeType;
}
public void setAttachmentMimeType(String attachmentMimeType) {
this.attachmentMimeType = attachmentMimeType;
}
public Long getAttachmentSizeBytes() {
return attachmentSizeBytes;
}
public void setAttachmentSizeBytes(Long attachmentSizeBytes) {
this.attachmentSizeBytes = attachmentSizeBytes;
}
}

View File

@@ -19,9 +19,20 @@ public class Message {
@Column(nullable = false)
private Long senderId;
@Column(nullable = false, columnDefinition = "TEXT")
@Column(columnDefinition = "TEXT")
private String content;
@Column(length = 255)
private String attachmentUrl;
@Column(length = 255)
private String attachmentName;
@Column(length = 100)
private String attachmentMimeType;
private Long attachmentSizeBytes;
@CreationTimestamp
@Column(nullable = false, updatable = false)
private LocalDateTime timestamp;
@@ -88,4 +99,36 @@ public class Message {
public void setIsRead(Boolean isRead) {
this.isRead = isRead;
}
public String getAttachmentUrl() {
return attachmentUrl;
}
public void setAttachmentUrl(String attachmentUrl) {
this.attachmentUrl = attachmentUrl;
}
public String getAttachmentName() {
return attachmentName;
}
public void setAttachmentName(String attachmentName) {
this.attachmentName = attachmentName;
}
public String getAttachmentMimeType() {
return attachmentMimeType;
}
public void setAttachmentMimeType(String attachmentMimeType) {
this.attachmentMimeType = attachmentMimeType;
}
public Long getAttachmentSizeBytes() {
return attachmentSizeBytes;
}
public void setAttachmentSizeBytes(Long attachmentSizeBytes) {
this.attachmentSizeBytes = attachmentSizeBytes;
}
}

View File

@@ -77,7 +77,8 @@ public class ChatService {
return conversations.stream()
.map(conv -> {
List<Message> messages = messageRepository.findByConversationIdOrderByTimestampAsc(conv.getId());
String lastMessage = messages.isEmpty() ? "" : messages.get(messages.size() - 1).getContent();
Message last = messages.isEmpty() ? null : messages.get(messages.size() - 1);
String lastMessage = last != null && last.getContent() != null ? last.getContent() : "";
return ConversationResponse.fromEntity(conv, lastMessage);
})
.collect(Collectors.toList());
@@ -97,7 +98,8 @@ public class ChatService {
}
List<Message> messages = messageRepository.findByConversationIdOrderByTimestampAsc(conversationId);
String lastMessage = messages.isEmpty() ? "" : messages.get(messages.size() - 1).getContent();
Message last = messages.isEmpty() ? null : messages.get(messages.size() - 1);
String lastMessage = last != null && last.getContent() != null ? last.getContent() : "";
return ConversationResponse.fromEntity(conversation, lastMessage);
}
@@ -124,6 +126,10 @@ public class ChatService {
message.setConversationId(conversationId);
message.setSenderId(userId);
message.setContent(request.getContent());
message.setAttachmentUrl(request.getAttachmentUrl());
message.setAttachmentName(request.getAttachmentName());
message.setAttachmentMimeType(request.getAttachmentMimeType());
message.setAttachmentSizeBytes(request.getAttachmentSizeBytes());
message.setIsRead(false);
message = messageRepository.save(message);
@@ -158,7 +164,8 @@ public class ChatService {
conversationRepository.save(conversation);
List<Message> messages = messageRepository.findByConversationIdOrderByTimestampAsc(conversationId);
String lastMessage = messages.isEmpty() ? "" : messages.get(messages.size() - 1).getContent();
Message last = messages.isEmpty() ? null : messages.get(messages.size() - 1);
String lastMessage = last != null && last.getContent() != null ? last.getContent() : "";
return ConversationResponse.fromEntity(conversation, lastMessage);
}
@@ -180,7 +187,8 @@ public class ChatService {
conversation = conversationRepository.save(conversation);
List<Message> messages = messageRepository.findByConversationIdOrderByTimestampAsc(conversationId);
String lastMessage = messages.isEmpty() ? "" : messages.get(messages.size() - 1).getContent();
Message last = messages.isEmpty() ? null : messages.get(messages.size() - 1);
String lastMessage = last != null && last.getContent() != null ? last.getContent() : "";
return ConversationResponse.fromEntity(conversation, lastMessage);
}