public async Task PostImage()

in Source/ApiGWs/Tailwind.Traders.WebBff/Controllers/ProductsController.cs [155:190]


        public async Task<IActionResult> PostImage(IFormFile file)
        {
            ClassificationResult result = null;
            if (_settings.UseMlNetClassifier)
            {
                _logger.LogInformation($"Beginning a ML.NET based classification");
                result = await DoMlNetClassifierAction(file);
            }
     
            if (result == null || !result.IsOk)
            {
                var resultCode = (int)HttpStatusCode.NotImplemented;
                if (result != null) resultCode = (int)result.Code;
                _logger.LogInformation($"Classification failed due to HTTP CODE {resultCode}");
                return StatusCode(resultCode, "Request to inner container returned HTTP " + resultCode);
            }

            _logger.LogInformation($"Classification ended up with tag {result.Label} with a prob (0-1) of {result.Probability}");

            var client = _httpClientFactory.CreateClient(HttpClients.ApiGW);
            // Need to query products API for tag
            var ptagsResponse = await client.GetAsync(API.Products.GetByTag(_settings.ProductsApiUrl, VERSION_API, result.Label));

            if (ptagsResponse.StatusCode == HttpStatusCode.NotFound)
            {
                _logger.LogInformation($"Tag {result.Label} do not have any object associated");
                return Ok(Enumerable.Empty<ClassifiedProductItem>());
            }

            ptagsResponse.EnsureSuccessStatusCode();

            var suggestedProductsJson = await ptagsResponse.Content.ReadAsStringAsync();
            var suggestedProducts = JsonConvert.DeserializeObject<IEnumerable<ClassifiedProductItem>>(suggestedProductsJson);

            return Ok(suggestedProducts);
        }