From 21363f5b916b3f6c3c33d4a3ff07ec1afdc1d8f4 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 17:52:07 +0300 Subject: [PATCH] feat(service):lab4 add AttachmentService.Get with member check --- backend/internal/service/attachment.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/backend/internal/service/attachment.go b/backend/internal/service/attachment.go index 9f7ebba..762c59b 100644 --- a/backend/internal/service/attachment.go +++ b/backend/internal/service/attachment.go @@ -32,6 +32,17 @@ func NewAttachmentService( } } +func (s *AttachmentService) Get(ctx context.Context, userID, attachmentID string) (*domain.Attachment, error) { + a, err := s.attachments.GetByID(ctx, attachmentID) + if err != nil { + return nil, err + } + if err := s.ensureMember(ctx, userID, a.ChatID); err != nil { + return nil, err + } + return a, nil +} + func (s *AttachmentService) ensureMember(ctx context.Context, userID, chatID string) error { c, err := s.chats.GetByID(ctx, chatID) if err != nil {