From d208a7bef32ebd56391d5920027004ebe2a80777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BE=D0=BB=D0=B8=D0=BA=D0=BE=D0=B2=20Maximillian?= =?UTF-8?q?=20=D0=90=D0=BD=D1=82=D0=BE=D0=BD?= Date: Mon, 19 Oct 2026 12:41:08 +0300 Subject: [PATCH] feat(postgres):lab4 add AttachmentRepo.GetByID --- .../internal/storage/postgres/attachments.go | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/backend/internal/storage/postgres/attachments.go b/backend/internal/storage/postgres/attachments.go index b3098e2..9ea3180 100644 --- a/backend/internal/storage/postgres/attachments.go +++ b/backend/internal/storage/postgres/attachments.go @@ -49,3 +49,23 @@ func (r *AttachmentRepo) Create(ctx context.Context, a *domain.Attachment) error } return nil } + +func (r *AttachmentRepo) GetByID(ctx context.Context, id string) (*domain.Attachment, error) { + const q = ` + SELECT id, chat_id, owner_id, filename, content_type, size_bytes, sha256, + object_key, status, error_code, created_at, updated_at + FROM attachments + WHERE id = $1::uuid + ` + a := &domain.Attachment{} + var status string + err := r.pool.QueryRow(ctx, q, id). + Scan(&a.ID, &a.ChatID, &a.OwnerID, &a.Filename, &a.ContentType, + &a.SizeBytes, &a.SHA256, &a.ObjectKey, &status, &a.ErrorCode, + &a.CreatedAt, &a.UpdatedAt) + if err != nil { + return nil, notFound(err, "attachment", id) + } + a.Status = domain.AttachmentStatus(status) + return a, nil +}