feat(attachments): add attachment metadata and message links

This commit is contained in:
kk10
2026-11-01 23:04:45 +03:00
parent 27af30c903
commit 0c772ebf40
8 changed files with 479 additions and 37 deletions
+35 -1
View File
@@ -68,7 +68,23 @@ func (h *MessageHandler) Create(w http.ResponseWriter, r *http.Request) {
return
}
message, err := h.service.Create(r.Context(), userID, chatID, key, req.Text)
attachmentIDs := make([]uuid.UUID, 0, len(req.AttachmentIDs))
for _, s := range req.AttachmentIDs {
id, err := uuid.Parse(s)
if err != nil {
httpx.WriteError(
w,
http.StatusBadRequest,
dto.ErrorCodeInvalidRequest,
"invalid attachment_id",
requestID,
)
return
}
attachmentIDs = append(attachmentIDs, id)
}
message, err := h.service.Create(r.Context(), userID, chatID, key, req.Text, attachmentIDs)
switch {
case errors.Is(err, service.ErrMessageChatNotFound):
httpx.WriteError(
@@ -79,6 +95,24 @@ func (h *MessageHandler) Create(w http.ResponseWriter, r *http.Request) {
requestID,
)
return
case errors.Is(err, service.ErrAttachmentNotFound):
httpx.WriteError(
w,
http.StatusNotFound,
dto.ErrorCodeNotFound,
"attachment not found",
requestID,
)
return
case errors.Is(err, service.ErrAttachmentNotReady):
httpx.WriteError(
w,
http.StatusConflict,
dto.ErrorCodeConflict,
"attachment not ready",
requestID,
)
return
case errors.Is(err, service.ErrIdempotencyKeyConflict):
httpx.WriteError(
w,