feat(dto):lab4 add AttachmentResponse

This commit is contained in:
Голиков Maximillian Антон
2026-10-21 20:03:10 +03:00
parent d62e74f3ac
commit c912fe437e
@@ -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),
}
}