feat: implement lab4 MinIO attachments
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package com.example.mtusi_messenger.dto;
|
||||
|
||||
import com.example.mtusi_messenger.model.Attachment;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public record AttachmentResponse(UUID id,
|
||||
UUID chat_id,
|
||||
UUID owner_id,
|
||||
String filename,
|
||||
String content_type,
|
||||
long size_bytes,
|
||||
String sha256,
|
||||
String status,
|
||||
List<Object> variants,
|
||||
String error_code,
|
||||
Instant created_at,
|
||||
Instant updated_at) {
|
||||
public static AttachmentResponse from(Attachment attachment) {
|
||||
return new AttachmentResponse(
|
||||
attachment.id(),
|
||||
attachment.chatId(),
|
||||
attachment.ownerId(),
|
||||
attachment.filename(),
|
||||
attachment.contentType(),
|
||||
attachment.sizeBytes(),
|
||||
attachment.sha256(),
|
||||
"ready",
|
||||
List.of(),
|
||||
null,
|
||||
attachment.createdAt(),
|
||||
attachment.updatedAt());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.example.mtusi_messenger.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record ChatPageResponse(
|
||||
List<ChatResponse> items,
|
||||
String next_cursor
|
||||
) {}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.example.mtusi_messenger.dto;
|
||||
|
||||
import com.example.mtusi_messenger.model.Chat;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public record ChatResponse(UUID id,
|
||||
String title,
|
||||
List<UUID> member_ids,
|
||||
Instant created_at) {
|
||||
public static ChatResponse from(Chat c) {
|
||||
return new ChatResponse(
|
||||
c.id(),
|
||||
c.title(),
|
||||
c.memberIds(),
|
||||
c.createdAt()); }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.example.mtusi_messenger.dto;
|
||||
|
||||
import com.example.mtusi_messenger.web.NotUnicodeBlank;
|
||||
import com.example.mtusi_messenger.web.UnicodeSize;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public record CreateChatRequest(
|
||||
@NotUnicodeBlank
|
||||
@UnicodeSize(min = 1, max = 100)
|
||||
String title,
|
||||
|
||||
@NotEmpty
|
||||
@Size(min = 1, max = 100)
|
||||
List<UUID> member_ids
|
||||
) {}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.example.mtusi_messenger.dto;
|
||||
|
||||
import com.example.mtusi_messenger.web.UnicodeSize;
|
||||
import jakarta.validation.constraints.AssertTrue;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public record CreateMessageRequest(
|
||||
@NotNull @UnicodeSize(max = 4000) String text,
|
||||
@Size(max = 10) List<UUID> attachment_ids
|
||||
) {
|
||||
public CreateMessageRequest {
|
||||
attachment_ids = attachment_ids == null ? List.of() : List.copyOf(attachment_ids);
|
||||
}
|
||||
|
||||
@AssertTrue(message = "text or attachment_ids must be present")
|
||||
public boolean isContentPresent() {
|
||||
return text != null && (!text.isBlank() || !attachment_ids.isEmpty());
|
||||
}
|
||||
|
||||
@AssertTrue(message = "attachment_ids must be unique and non-null")
|
||||
public boolean areAttachmentIdsValid() {
|
||||
return attachment_ids != null
|
||||
&& attachment_ids.stream().noneMatch(java.util.Objects::isNull)
|
||||
&& new HashSet<>(attachment_ids).size() == attachment_ids.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.example.mtusi_messenger.dto;
|
||||
|
||||
import com.example.mtusi_messenger.web.NotUnicodeBlank;
|
||||
import com.example.mtusi_messenger.web.UnicodeSize;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
|
||||
public record CreateUserRequest(
|
||||
@NotBlank
|
||||
@Pattern(regexp = "[a-z0-9_]{3,32}")
|
||||
String username,
|
||||
|
||||
@NotUnicodeBlank
|
||||
@UnicodeSize(min = 1, max = 100)
|
||||
String display_name,
|
||||
|
||||
@NotUnicodeBlank
|
||||
@UnicodeSize(min = 12, max = 128)
|
||||
String password
|
||||
) {}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.example.mtusi_messenger.dto;
|
||||
|
||||
public record ErrorResponse(ErrorBody error) {
|
||||
public record ErrorBody(String code,
|
||||
String message,
|
||||
String request_id)
|
||||
{}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package com.example.mtusi_messenger.dto;
|
||||
|
||||
public record HealthResponse(String status) {}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.example.mtusi_messenger.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record MessagePageResponse(
|
||||
List<MessageResponse> items,
|
||||
String next_cursor
|
||||
) {}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.example.mtusi_messenger.dto;
|
||||
|
||||
import com.example.mtusi_messenger.model.Message;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public record MessageResponse(UUID id,
|
||||
UUID chat_id,
|
||||
UUID sender_id,
|
||||
String text,
|
||||
Instant created_at,
|
||||
List<UUID> attachment_ids) {
|
||||
public static MessageResponse from(Message m) {
|
||||
return new MessageResponse(m.id(),
|
||||
m.chatId(),
|
||||
m.senderId(),
|
||||
m.text(),
|
||||
m.createdAt(),
|
||||
m.attachmentIds());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.example.mtusi_messenger.dto;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
public record SessionResponse(
|
||||
String token,
|
||||
String token_type,
|
||||
Instant expires_at,
|
||||
UserResponse user
|
||||
) {}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.example.mtusi_messenger.dto;
|
||||
|
||||
import com.example.mtusi_messenger.model.User;
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public record UserResponse(UUID id,
|
||||
String username,
|
||||
String display_name,
|
||||
Instant created_at) {
|
||||
public static UserResponse from(User u) {
|
||||
return new UserResponse(
|
||||
u.id(),
|
||||
u.username(),
|
||||
u.displayName(),
|
||||
u.createdAt());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user