Ejemplo n.º 1
0
            public async Task <ImageResponse> Handle(Query query, CancellationToken cancellationToken)
            {
                var validationResult = await _getImageRequestValidator.ValidateAsync(query.Request, cancellationToken);

                if (!validationResult.IsValid)
                {
                    return(ImageResponse.GetResponse(ResponseType.BadRequest, validationResult.ToString()));
                }

                var imageInCache = _imageCachingService.TryGetValue(query.Request, out var imageResponse);

                if (imageInCache)
                {
                    return(imageResponse);
                }

                if (!_imageService.FileExists($"{_appSettings.ProductImagesPath}{query.Request.FileName}"))
                {
                    return(ImageResponse.GetResponse(ResponseType.NotFound));
                }

                imageResponse = await _imageProcessor.GetProcessedImage(query.Request, cancellationToken);

                _imageCachingService.Set(query.Request, imageResponse);

                return(imageResponse);
            }