fixed sending message with attachments

This commit is contained in:
Alex
2026-04-09 18:55:12 -06:00
parent f3932b226d
commit 9b4aad0c36
10 changed files with 90 additions and 52 deletions

View File

@@ -95,9 +95,10 @@ public class ChatController {
@PreAuthorize("hasAnyRole('CUSTOMER', 'STAFF', 'ADMIN')")
public ResponseEntity<MessageResponse> sendMessageWithAttachment(
@PathVariable Long id,
@RequestParam("file") MultipartFile file) {
@RequestParam("file") MultipartFile file,
@RequestParam(value = "content", required = false) String content) {
User user = getCurrentUser();
MessageResponse message = chatService.sendMessageWithAttachment(id, user.getId(), user.getRole(), file);
MessageResponse message = chatService.sendMessageWithAttachment(id, user.getId(), user.getRole(), file, content);
chatRealtimeService.publishMessage(id, message);
chatRealtimeService.publishConversationUpdate(id);
return ResponseEntity.status(HttpStatus.CREATED).body(message);

View File

@@ -151,7 +151,7 @@ public class ChatService {
}
@Transactional
public MessageResponse sendMessageWithAttachment(Long conversationId, Long userId, User.Role role, MultipartFile file) {
public MessageResponse sendMessageWithAttachment(Long conversationId, Long userId, User.Role role, MultipartFile file, String content) {
Conversation conversation = conversationRepository.findById(conversationId)
.orElseThrow(() -> new ResourceNotFoundException("Conversation not found"));
@@ -173,6 +173,7 @@ public class ChatService {
Message message = new Message();
message.setConversationId(conversationId);
message.setSenderId(userId);
message.setContent(content);
message.setAttachmentUrl(attachmentUrl);
message.setAttachmentName(file.getOriginalFilename());
message.setAttachmentMimeType(file.getContentType());

View File

@@ -55,3 +55,9 @@ logging:
com.petshop: ${LOG_LEVEL:INFO}
org.springframework.security: ${LOG_LEVEL_SECURITY:WARN}
org.springdoc.core.events.SpringDocAppInitializer: ERROR
jackson:
serialization:
write-dates-as-timestamps: false
deserialization:
fail-on-unknown-properties: false