From 15a2d7aa85f45582182a93a58d0c4d54be5397e3 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: Wed, 21 Oct 2026 18:19:34 +0300 Subject: [PATCH] feat(service):lab4 add AttachmentService.Download via ObjectStorage --- backend/internal/service/attachment.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/backend/internal/service/attachment.go b/backend/internal/service/attachment.go index 762c59b..5dd0295 100644 --- a/backend/internal/service/attachment.go +++ b/backend/internal/service/attachment.go @@ -2,6 +2,7 @@ package service import ( "context" + "io" "strings" "unicode" "unicode/utf8" @@ -43,6 +44,20 @@ func (s *AttachmentService) Get(ctx context.Context, userID, attachmentID string return a, nil } +func (s *AttachmentService) Download( + ctx context.Context, + userID, attachmentID string, +) (io.ReadCloser, int64, string, error) { + a, err := s.Get(ctx, userID, attachmentID) + if err != nil { + return nil, 0, "", err + } + if a.Status != domain.AttachmentStatusReady { + return nil, 0, "", &domain.ConflictError{Reason: "вложение не готово"} + } + return s.storage.Get(ctx, a.ObjectKey) +} + func (s *AttachmentService) ensureMember(ctx context.Context, userID, chatID string) error { c, err := s.chats.GetByID(ctx, chatID) if err != nil {