Esempio n. 1
0
        public async Task <GetObjectAttachmentsQueryResult> Ask(GetObjectAttachmentsQueryArgs queryArgs)
        {
            var attachments = await _repository.AsQueryable <MapObject>()
                              .WithId(queryArgs.ObjectId)
                              .OfMap(queryArgs.MapId, queryArgs.ActionExecutorId)
                              .SelectMany(mapObject => mapObject.FileReferencesBindings)
                              .Select(binding => binding.FileReference)
                              .AsNoTracking()
                              .ToListAsync();

            var result = new GetObjectAttachmentsQueryResult
            {
                Attachments = attachments.Select(attachment => new GetObjectAttachmentsQueryResultItem
                {
                    Id              = attachment.Id,
                    AccessUrl       = _fileStorageClient.GenerateGetPreSignedUrl(attachment.ObjectKey),
                    MimeType        = attachment.MimeType,
                    PreviewTemplate = MimeTypesHelper.IsPreviewSupporting(attachment.MimeType)
                        ? _endpointsBuilder.BuildImagePreviewUrl(attachment.ObjectKey)
                        : null,
                    SourceFileName = attachment.SourceFileName
                }).ToList()
            };

            return(result);
        }