51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
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),
|
|
}
|
|
}
|