feat(service):lab4 add AttachmentService.Get with member check
This commit is contained in:
@@ -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 {
|
func (s *AttachmentService) ensureMember(ctx context.Context, userID, chatID string) error {
|
||||||
c, err := s.chats.GetByID(ctx, chatID)
|
c, err := s.chats.GetByID(ctx, chatID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user