forked from mtusi2026/mtusi2026lab4
feat(attachments): add attachment metadata and message links
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user