From c912fe437ea3b150891ee6c28dcd39cf8e888dea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BE=D0=BB=D0=B8=D0=BA=D0=BE=D0=B2=20Maximillian?= =?UTF-8?q?=20=D0=90=D0=BD=D1=82=D0=BE=D0=BD?= Date: Wed, 21 Oct 2026 20:03:10 +0300 Subject: [PATCH] feat(dto):lab4 add AttachmentResponse --- backend/internal/httpapi/dto/attachment.go | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 backend/internal/httpapi/dto/attachment.go diff --git a/backend/internal/httpapi/dto/attachment.go b/backend/internal/httpapi/dto/attachment.go new file mode 100644 index 0000000..b608954 --- /dev/null +++ b/backend/internal/httpapi/dto/attachment.go @@ -0,0 +1,50 @@ +package dto + +import ( + "encoding/hex" + + "high-loud-apps-labs/internal/domain" +) + +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"` +} + +func AttachmentFromDomain(a *domain.Attachment) AttachmentResponse { + variants := make([]VariantResponse, 0) + errCode := a.ErrorCode + return AttachmentResponse{ + ID: a.ID, + ChatID: a.ChatID, + OwnerID: a.OwnerID, + Filename: a.Filename, + ContentType: a.ContentType, + SizeBytes: a.SizeBytes, + SHA256: hex.EncodeToString(a.SHA256), + Status: string(a.Status), + Variants: variants, + ErrorCode: errCode, + CreatedAt: a.CreatedAt.UTC().Format(timeFormat), + UpdatedAt: a.UpdatedAt.UTC().Format(timeFormat), + } +}