feat: attachments over S3 (grade 3)

This commit is contained in:
2026-11-20 03:55:39 +03:00
parent 083d0d80cc
commit 89e9e7b4d4
44 changed files with 1468 additions and 67 deletions
+64 -11
View File
@@ -2,6 +2,7 @@ package handler
import (
"time"
"uuid"
"messenger/internal/domain"
)
@@ -18,7 +19,8 @@ type createChatRequest struct {
}
type createMessageRequest struct {
Text *string `json:"text"`
Text *string `json:"text"`
AttachmentIDs *[]string `json:"attachment_ids"`
}
type userResponse struct {
@@ -36,11 +38,36 @@ type chatResponse struct {
}
type messageResponse struct {
ID string `json:"id"`
ChatID string `json:"chat_id"`
SenderID string `json:"sender_id"`
Text string `json:"text"`
CreatedAt string `json:"created_at"`
ID string `json:"id"`
ChatID string `json:"chat_id"`
SenderID string `json:"sender_id"`
Text string `json:"text"`
CreatedAt string `json:"created_at"`
AttachmentIDs []string `json:"attachment_ids"`
}
type variantResponse struct {
Name string `json:"name"`
ContentType string `json:"content_type"`
SizeBytes int64 `json:"size_bytes"`
Width int `json:"width"`
Height int `json:"height"`
SHA256 string `json:"sha256"`
}
type attachmentResponse struct {
ID string `json:"id"`
ChatID string `json:"chat_id"`
OwnerID string `json:"owner_id"`
Filename string `json:"filename"`
ContentType string `json:"content_type"`
SizeBytes int64 `json:"size_bytes"`
SHA256 string `json:"sha256"`
Status string `json:"status"`
Variants []variantResponse `json:"variants"`
ErrorCode *string `json:"error_code"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
type pageResponse[T any] struct {
@@ -106,14 +133,40 @@ func toChatResponse(c domain.Chat) chatResponse {
func toMessageResponse(m domain.Message) messageResponse {
return messageResponse{
ID: m.ID.String(),
ChatID: m.ChatID.String(),
SenderID: m.SenderID.String(),
Text: m.Text,
CreatedAt: formatTime(m.CreatedAt),
ID: m.ID.String(),
ChatID: m.ChatID.String(),
SenderID: m.SenderID.String(),
Text: m.Text,
CreatedAt: formatTime(m.CreatedAt),
AttachmentIDs: toIDStrings(m.AttachmentIDs),
}
}
func toAttachmentResponse(a domain.Attachment) attachmentResponse {
return attachmentResponse{
ID: a.ID.String(),
ChatID: a.ChatID.String(),
OwnerID: a.OwnerID.String(),
Filename: a.Filename,
ContentType: a.ContentType,
SizeBytes: a.SizeBytes,
SHA256: a.SHA256,
Status: a.Status,
Variants: []variantResponse{},
ErrorCode: a.ErrorCode,
CreatedAt: formatTime(a.CreatedAt),
UpdatedAt: formatTime(a.UpdatedAt),
}
}
func toIDStrings(ids []uuid.UUID) []string {
result := make([]string, len(ids))
for i, id := range ids {
result[i] = id.String()
}
return result
}
func toPageResponse[D, R any](p domain.Page[D], conv func(D) R) pageResponse[R] {
items := make([]R, len(p.Items))
for i, it := range p.Items {