public async Task <Response <AddShelfResponse> > Add(AddShelfRequest roomRequest) { try { var response = await client.PostAsJsonAsync("shelf", roomRequest); response.EnsureSuccessStatusCode(); using var responseStream = await response.Content.ReadAsStreamAsync(); var result = await JsonSerializerWrapper.DeserializeAsync <AddShelfResponse>(responseStream); return(Response <AddShelfResponse> .Success(result)); } catch (System.Exception e) { return(Response <AddShelfResponse> .Fail("ADD_SHELF_ERROR", e)); } }
public async Task <Response <AddProductInstanceResponse> > Add(long productId, AddProductInstanceRequest addProductInstanceRequest) { try { var response = await client.PostAsJsonAsync($"product/{productId}/instances", addProductInstanceRequest); response.EnsureSuccessStatusCode(); using var responseStream = await response.Content.ReadAsStreamAsync(); var result = await JsonSerializerWrapper.DeserializeAsync <AddProductInstanceResponse>(responseStream); return(Response <AddProductInstanceResponse> .Success(result)); } catch (System.Exception e) { return(Response <AddProductInstanceResponse> .Fail("ADD_PRODUCT_INSTANCE_ERROR", e)); } }
public async Task <Response <Empty> > Consume(long productInstanceId) { try { var response = await client.PostAsJsonAsync($"/instances/{productInstanceId}/consume", ""); response.EnsureSuccessStatusCode(); using var responseStream = await response.Content.ReadAsStreamAsync(); var result = await JsonSerializerWrapper.DeserializeAsync <Empty>(responseStream); return(Response <Empty> .Success(result)); } catch (Exception e) { logger.LogError(e, $"Cannot consume {productInstanceId}"); return(Response <Empty> .Fail("PRODUCT_INSTANCE_CONSUME_ERROR", e)); } }
public async Task <Response <AddProductResponse> > Add(AddProductRequest roomRequest) { try { var response = await client.PostAsJsonAsync("product", roomRequest); response.EnsureSuccessStatusCode(); using var responseStream = await response.Content.ReadAsStreamAsync(); var result = await JsonSerializerWrapper.DeserializeAsync <AddProductResponse>(responseStream); return(Response <AddProductResponse> .Success(result)); } catch (System.Exception e) { logger.LogError(e.Message); return(Response <AddProductResponse> .Fail("ADD_PRODUCT_ERROR", e)); } }
public async Task <Response <SearchProductResponse> > Search(string name, int limit = 5) { try { var response = await client.GetAsync($"product?partName={name}&limit={limit}"); response.EnsureSuccessStatusCode(); using var responseStream = await response.Content.ReadAsStreamAsync(); var result = await JsonSerializerWrapper.DeserializeAsync <SearchProductResponse>(responseStream); logger.LogDebug($"result.Products.Count = {result.Products.Count}"); return(Response <SearchProductResponse> .Success(result)); } catch (System.Exception e) { logger.LogError($"error = {e.Message}"); return(Response <SearchProductResponse> .Fail("SEARCH_PRODUCT_ERROR", e)); } }
public async Task <Response <GetInventoryResponse> > GetInventory() { ///product/all/instances try { var response = await client.GetAsync($"product/all/instances"); response.EnsureSuccessStatusCode(); using var responseStream = await response.Content.ReadAsStreamAsync(); var result = await JsonSerializerWrapper.DeserializeAsync <GetInventoryResponse>(responseStream); logger.LogDebug($"result.Items.Count = {result.Items.Count}"); return(Response <GetInventoryResponse> .Success(result)); } catch (System.Exception e) { logger.LogError($"error = {e.Message}"); return(Response <GetInventoryResponse> .Fail("GET_INVENTORY_ERROR", e)); } }