feat(db): add attachment content type and status enums

This commit is contained in:
kk10
2026-11-02 21:50:29 +03:00
parent 983bbaa55e
commit 42ddd2cad9
5 changed files with 108 additions and 15 deletions
+90 -2
View File
@@ -5,21 +5,109 @@
package db
import (
"database/sql/driver"
"fmt"
"time"
"github.com/google/uuid"
)
type AttachmentContentType string
const (
AttachmentContentTypeImagePng AttachmentContentType = "image/png"
AttachmentContentTypeImageJpeg AttachmentContentType = "image/jpeg"
)
func (e *AttachmentContentType) Scan(src interface{}) error {
switch s := src.(type) {
case []byte:
*e = AttachmentContentType(s)
case string:
*e = AttachmentContentType(s)
default:
return fmt.Errorf("unsupported scan type for AttachmentContentType: %T", src)
}
return nil
}
type NullAttachmentContentType struct {
AttachmentContentType AttachmentContentType
Valid bool // Valid is true if AttachmentContentType is not NULL
}
// Scan implements the Scanner interface.
func (ns *NullAttachmentContentType) Scan(value interface{}) error {
if value == nil {
ns.AttachmentContentType, ns.Valid = "", false
return nil
}
ns.Valid = true
return ns.AttachmentContentType.Scan(value)
}
// Value implements the driver Valuer interface.
func (ns NullAttachmentContentType) Value() (driver.Value, error) {
if !ns.Valid {
return nil, nil
}
return string(ns.AttachmentContentType), nil
}
type AttachmentStatus string
const (
AttachmentStatusQueued AttachmentStatus = "queued"
AttachmentStatusProcessing AttachmentStatus = "processing"
AttachmentStatusReady AttachmentStatus = "ready"
AttachmentStatusFailed AttachmentStatus = "failed"
)
func (e *AttachmentStatus) Scan(src interface{}) error {
switch s := src.(type) {
case []byte:
*e = AttachmentStatus(s)
case string:
*e = AttachmentStatus(s)
default:
return fmt.Errorf("unsupported scan type for AttachmentStatus: %T", src)
}
return nil
}
type NullAttachmentStatus struct {
AttachmentStatus AttachmentStatus
Valid bool // Valid is true if AttachmentStatus is not NULL
}
// Scan implements the Scanner interface.
func (ns *NullAttachmentStatus) Scan(value interface{}) error {
if value == nil {
ns.AttachmentStatus, ns.Valid = "", false
return nil
}
ns.Valid = true
return ns.AttachmentStatus.Scan(value)
}
// Value implements the driver Valuer interface.
func (ns NullAttachmentStatus) Value() (driver.Value, error) {
if !ns.Valid {
return nil, nil
}
return string(ns.AttachmentStatus), nil
}
type Attachment struct {
ID uuid.UUID
ChatID uuid.UUID
OwnerID uuid.UUID
S3Key string
Filename string
ContentType string
ContentType AttachmentContentType
SizeBytes int
Sha256 string
Status string
Status AttachmentStatus
ErrorCode *string
CreatedAt time.Time
UpdatedAt time.Time