feat(domain): lab5 add attachment variants and job repository contracts

This commit is contained in:
Голиков Maximillian Антон
2026-11-08 10:19:32 +03:00
parent 4413c43eb5
commit a7c7532622
4 changed files with 64 additions and 0 deletions
+2
View File
@@ -128,6 +128,8 @@ go.mongodb.org/mongo-driver/v2 v2.5.0 h1:yXUhImUjjAInNcpTcAlPHiT7bIXhshCTL3jVBkF
go.mongodb.org/mongo-driver/v2 v2.5.0/go.mod h1:yOI9kBsufol30iFsl1slpdq1I0eHPzybRWdyYUs8K/0=
go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE=
go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
@@ -0,0 +1,25 @@
package domain
import "time"
type AttachmentVariant struct {
AttachmentID string
Name string
ObjectKey string
ContentType string
SizeBytes int64
Width int
Height int
SHA256 []byte
CreatedAt time.Time
}
const (
VariantThumbnail = "thumbnail"
VariantCrop = "crop"
VariantWebP = "webp"
)
func AllVariantNames() []string {
return []string{VariantThumbnail, VariantCrop, VariantWebP}
}
+11
View File
@@ -52,3 +52,14 @@ type OutboxRepository interface {
ClaimBatch(ctx context.Context, limit int) ([]OutboxEntry, error)
MarkPublished(ctx context.Context, ids []string) error
}
type AttachmentJobRepository interface {
ClaimForProcessing(ctx context.Context, id string, lease time.Duration) (*Attachment, error)
CompleteJob(ctx context.Context, id string, pipelineVersion int, variants []AttachmentVariant) (bool, error)
FailJob(ctx context.Context, id string, errorCode string) error
}
type AttachmentVariantRepository interface {
Upsert(ctx context.Context, tx Tx, v *AttachmentVariant) error
ListByAttachment(ctx context.Context, id string) ([]AttachmentVariant, error)
}
+26
View File
@@ -0,0 +1,26 @@
-- +goose Up
-- +goose StatementBegin
CREATE TABLE attachment_variants (
attachment_id UUID NOT NULL REFERENCES attachments(id) ON DELETE CASCADE,
name TEXT NOT NULL,
object_key TEXT NOT NULL,
content_type TEXT NOT NULL,
size_bytes BIGINT NOT NULL,
width INT NOT NULL,
height INT NOT NULL,
sha256 BYTEA NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
CONSTRAINT attachment_variants_pkey PRIMARY KEY (attachment_id, name),
CONSTRAINT attachment_variants_name_chk CHECK (name IN ('thumbnail', 'crop', 'webp')),
CONSTRAINT attachment_variants_size_chk CHECK (size_bytes > 0),
CONSTRAINT attachment_variants_sha256_len CHECK (octet_length(sha256) = 32)
);
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP TABLE IF EXISTS attachment_variants;
-- +goose StatementEnd