public async Task <BaseOutput <string> > GetAddictive([FromRoute] string parameter) { if (string.IsNullOrWhiteSpace(parameter)) { return(new BaseOutput <string> { IsSuccessful = false, Message = "Error", Payload = "test" }); } //get all var url = $"{_appSettings.Service.ProductApi}/{parameter}.json"; var getAddictive = await _webServiceInvoker.Get(url); var addictiveStr = await getAddictive.Content.ReadAsStringAsync(); var savedAddictive = await _foodFactsAppService.CreateAddictived(addictiveStr); return(savedAddictive); }
public async Task <BaseOutput <object> > Post([FromBody] BarcodeInput input) { if (!ModelState.IsValid) { return(new BaseOutput <object> { IsSuccessful = false, Message = "Error", Payload = "test" }); } var checkProduct = await _productAppService.ProductExists(input.Barcode); if (!checkProduct.Payload) { //get product from openfood var url = $"{_appSettings.Service.ProductApi}/api/v0/product/{input.Barcode}.json"; var getProductInfo = await _webServiceInvoker.Get(url); var productStr = await getProductInfo.Content.ReadAsStringAsync(); var saveProduct = await _productAppService.CreateProduct(productStr); if (!saveProduct.IsSuccessful) { return(saveProduct); } } //first check for product in db if (string.IsNullOrWhiteSpace(input.UserUid)) { var getProduct = await _productAppService.GetProductByBarcode(input.Barcode); return(getProduct); } var getUserProduct = await _productAppService.GetProductByBarcodeAndUserUid(input.UserUid, input.Barcode); return(getUserProduct); }
public async Task <BaseOutput <object> > Post([FromBody] NewsInput input) { if (!ModelState.IsValid) { return(new BaseOutput <object> { IsSuccessful = false, Message = "Error", Payload = "test" }); } //get product from openfood var url = $"{_appSettings.Service.Newspi}/top-headlines?country={input.Country}&apiKey={_appSettings.ApiKeys.HealthNews}&category=health"; var getNewsInfo = await _webServiceInvoker.Get(url); var newsStr = await getNewsInfo.Content.ReadAsStringAsync(); var saveNews = await _newsAppService.CreateNews(newsStr); return(saveNews); }