feat(postgres):lab4 add AttachmentRepo.GetByID
This commit is contained in:
@@ -49,3 +49,23 @@ func (r *AttachmentRepo) Create(ctx context.Context, a *domain.Attachment) error
|
|||||||
}
|
}
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user