61 lines
1.7 KiB
Go
61 lines
1.7 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, len(a.Variants))
|
|
for i, v := range a.Variants {
|
|
variants[i] = VariantResponse{
|
|
Name: v.Name,
|
|
ContentType: v.ContentType,
|
|
SizeBytes: v.SizeBytes,
|
|
Width: v.Width,
|
|
Height: v.Height,
|
|
SHA256: hex.EncodeToString(v.SHA256),
|
|
}
|
|
}
|
|
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),
|
|
}
|
|
}
|