public async Task <IActionResult> GetAllMusic() { // RestClient returns three values, or a Tuple type: // value 1: payload // vaule 2: optional error text message // vaule 3: http status code for response var correlationToken = CorrelationTokenManager.GenerateToken(); // Call backend microservice var response = await _restClient.GetAsync <List <MusicDto> >(ServiceEnum.Catalog, "api/Catalog/Music", correlationToken); // Build return response if (response.Data == null || response.Data.Count < 1) { // Build error response _logger.LogError(LoggingEvents.GetAllMusic, $"No product found for request:{correlationToken}"); return(StatusCode((int)response.HttpStatusCode, response.ErrorMessage)); } // Build success response _logger.LogInformation(LoggingEvents.GetAllMusic, $"Fetched all products for request: {correlationToken}"); return(new ObjectResult(response.Data)); }
public async Task <IActionResult> Put([FromBody] MusicDtoUpdate musicDto) { // See GetAllMusic() action method above for explanation var correlationToken = CorrelationTokenManager.GenerateToken(); if (!ModelState.IsValid) { _logger.LogError(LoggingEvents.CatalogPut, $"ModelState invalid for product update. Request:{correlationToken}. Error:{ModelState.Values}"); return(BadRequest(ModelState)); } var response = await _restClient.PutAsync <MusicDtoUpdate>(ServiceEnum.Catalog, "api/Catalog", correlationToken, musicDto); if (response.Data == null) { _logger.LogError(LoggingEvents.CatalogPut, $"Could not update product:{response.ErrorMessage} for correlationToken: {correlationToken}"); return(StatusCode((int)response.HttpStatusCode, response.ErrorMessage)); } _logger.LogInformation(LoggingEvents.CatalogPut, $"Updated product for request:{correlationToken}"); return(new ObjectResult(response.Data)); }
public async Task <IActionResult> AddItemToBasket(string basketId, int productId) { var correlationToken = CorrelationTokenManager.GenerateToken(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Send product information and basketId to the Basket microservice // Note: Sending querystring parameters in the post. var response = await _restClient.PostAsync <dynamic>(ServiceEnum.Basket, $"api/Basket/?productId={productId}&basketId={basketId}", correlationToken, null); if (response == null || response.Data == null) { _logger.LogError(LoggingEvents.AddItemToBasket, $"ProductId:{productId} not found for request:{correlationToken} - Is Catalog ReadModel populated?"); return(StatusCode((int)response.HttpStatusCode, $"{response.ErrorMessage} - Is the Catalog ReadModel populated?")); } _logger.LogInformation(LoggingEvents.AddItemToBasket, $"Basket: Added Item to Basket for correlationToken: {correlationToken}"); //return CreatedAtRoute("NewBasketLineItemGatewayRoute", response); return(CreatedAtRoute("NewBasketLineItemGatewayRoute", response.Data)); }
public async Task <IActionResult> CheckOut([FromBody] CheckOutDto checkOutDto) { var correlationToken = CorrelationTokenManager.GenerateToken(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Note: Sending querystring parameters in the post. //var response = await _restClient.PostAsync<CheckOutDto>(EnumLookup.Basket, // $"api/Basket/CheckOut/?_correlationToken={_correlationToken}", checkOutDto); var response = await _restClient.PostAsync <dynamic>(ServiceEnum.Basket, "api/Basket/CheckOut/", correlationToken, checkOutDto); //var response = await _restClient.PostAsync<CheckOutDto>(ServiceEnum.Basket, // "api/Basket/CheckOut/", correlationToken, checkOutDto); if (response == null || response.Data == null) { _logger.LogInformation(LoggingEvents.Checkout, $"Basket: Basket could not be found for correlationToken: {correlationToken}"); return(BadRequest($"Shopping Basket with Id {checkOutDto.BasketId} could not be found")); } _logger.LogInformation(LoggingEvents.Checkout, $"Basket: Item added to Basket for correlationToken: {correlationToken}"); return(Accepted(response.Data)); }
public async Task <IActionResult> GetAllMusic() { List <MusicDto> music; // Generate correlationToken var correlationToken = CorrelationTokenManager.GenerateToken(); _logger.LogInformation(LoggingEvents.GetAllMusic, $"Gateway: Getting All Music for {correlationToken}"); _logger.LogInformation("Fetching all music for {token}", correlationToken); // Get music //TODO: Add ex handling music = await _restClient.GetAsync <List <MusicDto> >(ServiceEnum.Catalog, $"api/Catalog/Music/{correlationToken}"); if (music == null || music.Count < 1) { _logger.LogWarning(LoggingEvents.GetAllMusic, $"Gateway: No music found for {correlationToken}"); return(BadRequest("No Products were found")); } _logger.LogInformation(LoggingEvents.GetAllMusic, $"Gateway: Retrieved All Music for {correlationToken}"); return(new ObjectResult(music)); }
public async Task <IActionResult> PostReadModel() { // See GetAllMusic() action method above for explanation var correlationToken = CorrelationTokenManager.GenerateToken(); if (!ModelState.IsValid) { _logger.LogError(LoggingEvents.CatalogPostReadModel, $"ModelState invalid for ReadModel Post. Request:{correlationToken}. Error:{ModelState.Values}"); return(BadRequest(ModelState)); } var response = await _restClient.PostAsync <MusicDtoUpdate>(ServiceEnum.Catalog, "api/Catalog/CreateBasketReadModel", correlationToken); if (response.Data == null) { _logger.LogError(LoggingEvents.CatalogPost, $"Error propagating catalog read model:{response.ErrorMessage} for request:{correlationToken}"); return(StatusCode((int)response.HttpStatusCode, response.ErrorMessage)); } _logger.LogInformation(LoggingEvents.CatalogPost, $"Read model propagated for request:{correlationToken}"); return(new ObjectResult(response)); }
public async Task <IActionResult> SimulateError() { // Generate correlationToken var correlationToken = CorrelationTokenManager.GenerateToken(); var result = await _restClient.GetAsync <List <OrderFlatDto> >(ServiceEnum.Ordering, $"api/Ordering/Orders/SimulateError/{correlationToken}"); return(new ObjectResult(result)); }
public async Task <IActionResult> SimulateError() { var correlationToken = CorrelationTokenManager.GenerateToken(); var response = await _restClient.GetAsync <List <OrdersDto> >(ServiceEnum.Ordering, $"api/Ordering/Orders/SimulateError", correlationToken); return(StatusCode((int)response.HttpStatusCode, response.ErrorMessage)); }
public async Task <IActionResult> Delete(string basketId) { Guard.ForNullOrEmpty("basketId", "Must include BasketID value"); var correlationToken = CorrelationTokenManager.GenerateToken(); // Note: Sending querystring parameters in the post. var response = await client.DeleteAsync(ServiceEnum.Basket, $"api/Basket/?basketId={basketId}&correlationToken={correlationToken}"); return(NoContent()); }
public async Task <IActionResult> GetAllOrders() { // Generate correlationToken var correlationToken = CorrelationTokenManager.GenerateToken(); var result = await _restClient.GetAsync <List <OrderFlatDto> >(ServiceEnum.Ordering, $"api/Ordering/v1.0/Orders/{correlationToken}"); if (result.Count < 1) { return(BadRequest("No orders exist")); } return(new ObjectResult(result)); }
public async Task <IActionResult> Put([FromBody] MusicDtoUpdate musicDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // Generate correlationToken var correlationToken = CorrelationTokenManager.GenerateToken(); var updatedAlbum = await _restClient.PutAsync <MusicDtoUpdate>(ServiceEnum.Catalog, $"api/Catalog/?correlationToken={correlationToken}", musicDto); return(new ObjectResult(updatedAlbum)); }
public async Task <IActionResult> GetOrderv2(string orderId, string version) { // Generate correlationToken var correlationToken = CorrelationTokenManager.GenerateToken(); var result = await _restClient.GetAsync <dynamic>(ServiceEnum.Ordering, $"api/ordering/v{version}/Order/{orderId}/{correlationToken}"); if (result == null) { return(BadRequest($"Order with Id {orderId} does not exist")); } return(new ObjectResult(result)); }
public async Task <IActionResult> GetBasket(string basketId) { // Generate correlationToken var correlationToken = CorrelationTokenManager.GenerateToken(); // Get music var response = await client.GetAsync <List <BasketDto> >(ServiceEnum.Basket, $"api/Basket/Basket/{basketId}/{correlationToken}"); if (response == null || response.Count < 1) { return(BadRequest($"Shopping Basket for Id {basketId} does not exist")); } return(new ObjectResult(response)); }
public async Task <IActionResult> GetAllBaskets() { // Generate correlationToken var correlationToken = CorrelationTokenManager.GenerateToken(); // Get music var result = await client.GetAsync <List <BasketDto> >(ServiceEnum.Basket, $"api/Basket/Baskets/{correlationToken}"); if (result == null || result.Count < 1) { return(BadRequest("No Shopping Baskets exist")); } return(new ObjectResult(result)); }
public async Task <IActionResult> GetGenre(int id, [FromQuery] bool includeAlbums) { // Generate correlationToken var correlationToken = CorrelationTokenManager.GenerateToken(); // Get music //TODO: Add ex handling var genre = await _restClient.GetAsync <GenreDto>(ServiceEnum.Catalog, $"api/Catalog/Genre/{correlationToken}/{id}?includeAlbums={includeAlbums}"); if (genre == null) { return(BadRequest($"Genres with Id {id} could not be found")); } return(new ObjectResult(genre)); }
public async Task <IActionResult> GetBasket(string basketId) { var correlationToken = CorrelationTokenManager.GenerateToken(); var response = await _restClient.GetAsync <BasketDto>(ServiceEnum.Basket, $"api/Basket/Basket/{basketId}", correlationToken); if (response == null || response.Data == null) { _logger.LogError(LoggingEvents.GetBasket, $"Basket: No baskets found for correlationToken:{correlationToken}"); return(StatusCode((int)response.HttpStatusCode, response.ErrorMessage)); } _logger.LogInformation(LoggingEvents.GetBasket, $"Basket: Baskets found for correlationToken: {correlationToken}"); return(new ObjectResult(response.Data)); }
//[HttpGet("Order/{orderId}", Name = "GetOrderGatewayRoute")] public async Task <IActionResult> GetOrder(string orderId, string version) { var correlationToken = CorrelationTokenManager.GenerateToken(); var response = await _restClient.GetAsync <dynamic>(ServiceEnum.Ordering, $"api/ordering/v{version}/Order/{orderId}", correlationToken); if (response.Data == null) { _logger.LogError(LoggingEvents.GetOrder, $"Ordering: No order found for {correlationToken}"); return(StatusCode((int)response.HttpStatusCode, response.ErrorMessage)); } _logger.LogInformation(LoggingEvents.GetOrder, $"Ordering: Order Found for {correlationToken}"); return(new ObjectResult(response.Data)); }
public async Task <IActionResult> GetOrders() { var correlationToken = CorrelationTokenManager.GenerateToken(); var response = await _restClient.GetAsync <List <OrdersDto> >(ServiceEnum.Ordering, $"api/Ordering/Orders", correlationToken); if (response.Data == null || response.Data.Count < 1) { _logger.LogError(LoggingEvents.GetOrders, $"Ordering: No order found for{correlationToken}"); return(StatusCode((int)response.HttpStatusCode, response.ErrorMessage)); } _logger.LogInformation(LoggingEvents.GetOrders, $"Ordering: Order Found for {correlationToken}"); return(new ObjectResult(response.Data)); }
public async Task <IActionResult> GetMusic(int id) { // Generate correlationToken var correlationToken = CorrelationTokenManager.GenerateToken(); // Get music //TODO: Add ex handling var music = await _restClient.GetAsync <MusicDto>(ServiceEnum.Catalog, $"api/Catalog/Music/{correlationToken}/{id}"); if (music == null) { return(BadRequest($"Product with Id {id} does not exist")); } return(new ObjectResult(music)); }
public async Task <IActionResult> GetMusic(int id) { // See GetAllMusic() action method above for explanation var correlationToken = CorrelationTokenManager.GenerateToken(); var response = await _restClient.GetAsync <MusicDto>(ServiceEnum.Catalog, $"api/Catalog/Music/{id}", correlationToken); if (response.Data == null) { _logger.LogError(LoggingEvents.GetMusic, $"ProductId:{id} not found for request:{correlationToken}"); return(StatusCode((int)response.HttpStatusCode, response.ErrorMessage)); } _logger.LogInformation(LoggingEvents.GetMusic, $"ProductId:{id} found for music for request:{correlationToken}"); return(new ObjectResult(response.Data)); }
public async Task <IActionResult> AddItemToBasket(string basketId, int productId) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var correlationToken = CorrelationTokenManager.GenerateToken(); Product product = null; // Send product information and basketId to the Basket microservice // Note: Sending querystring parameters in the post. var response = await client.PostAsync <dynamic>(ServiceEnum.Basket, $"api/Basket/?productId={productId}&correlationToken={correlationToken}&basketId={basketId}", product); return(CreatedAtRoute("NewBasketLineItemGatewayRoute", response)); }
public async Task <IActionResult> GetTopSellingItems(int count) { List <MusicDto> music; // Generate correlationToken var correlationToken = CorrelationTokenManager.GenerateToken(); // Get music //TODO: Add ex handling music = await _restClient.GetAsync <List <MusicDto> >(ServiceEnum.Catalog, $"api/Catalog/TopSellingMusic/{correlationToken}/{count}"); if (music == null || music.Count < 1) { return(BadRequest("No Products were found")); } return(new ObjectResult(music)); }
public async Task <IActionResult> GetBasketSummary(string basketId) { var correlationToken = CorrelationTokenManager.GenerateToken(); var response = await _restClient.GetAsync <BasketSummaryDto>(ServiceEnum.Basket, $"api/Basket/BasketSummary/{basketId}", correlationToken); if (response == null || response.Data == null) { _logger.LogError(LoggingEvents.GetBasket, $"Basket: No baskets found for correlationToken:{correlationToken}"); // This is a system hack. Return 200 status code to the CartSummaryComponent. // We don't show error, but do not show the summary icon. return(StatusCode(200)); } _logger.LogInformation(LoggingEvents.GetBasket, $"Basket: Baskets found for correlationToken: {correlationToken}"); return(new ObjectResult(response.Data)); }
public async Task <IActionResult> GetAllArtists() { List <ArtistDto> artists; // Generate correlationToken var correlationToken = CorrelationTokenManager.GenerateToken(); // Get music //TODO: Add ex handling artists = await _restClient.GetAsync <List <ArtistDto> >(ServiceEnum.Catalog, $"api/Catalog/Artists/{correlationToken}"); if (artists == null || artists.Count < 1) { return(BadRequest("No Artists were found")); } return(new ObjectResult(artists)); }
public async Task <IActionResult> GetAllGenres([FromQuery] bool includeAlbums) { List <GenreDto> genres; // Generate correlationToken var correlationToken = CorrelationTokenManager.GenerateToken(); // Get music //TODO: Add ex handling genres = await _restClient.GetAsync <List <GenreDto> >(ServiceEnum.Catalog, $"api/Catalog/Genres/{correlationToken}?includeAlbums={includeAlbums}"); if (genres == null || genres.Count < 1) { return(BadRequest("No Genres were found")); } return(new ObjectResult(genres)); }
public async Task <IActionResult> CheckOut([FromBody] NewOrderDto newOrderDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var correlationToken = CorrelationTokenManager.GenerateToken(); // Note: Sending querystring parameters in the post. var response = await client.PostAsync <NewOrderDto>(ServiceEnum.Basket, $"api/Basket/CheckOut/?correlationToken={correlationToken}", newOrderDto); if (response == null) { return(BadRequest($"Shopping Basket with Id {newOrderDto.BasketId} could not be found")); } return(Accepted("Order Being Created")); }
public async Task <IActionResult> Delete(string basketId) { var correlationToken = CorrelationTokenManager.GenerateToken(); Guard.ForNullOrEmpty("basketId", "Must include BasketID value"); // Note: Sending querystring parameters in the post. var response = await _restClient.DeleteAsync(ServiceEnum.Basket, $"api/Basket/?basketId={basketId}", correlationToken); if (!response) { _logger.LogError(LoggingEvents.Checkout, $"Could not delete Basket {basketId} for Request {correlationToken}"); return(BadRequest($"Could not delete Basket {basketId} for Request {correlationToken}")); } _logger.LogInformation(LoggingEvents.DeleteLineItem, $"Basket: Removed shopping basket for correlationToken: {correlationToken}"); return(NoContent()); }
public async Task <IActionResult> GetAllGenres([FromQuery] bool includeAlbums) { // See GetAllMusic() action method above for explanation var correlationToken = CorrelationTokenManager.GenerateToken(); var response = await _restClient.GetAsync <List <GenreDto> >(ServiceEnum.Catalog, $"api/Catalog/Genres/?includeAlbums={includeAlbums}", correlationToken); if (response.Data == null) { _logger.LogError(LoggingEvents.GetAllGenres, $"Genres not found:{response.ErrorMessage} for request:{correlationToken}"); return(StatusCode((int)response.HttpStatusCode, response.ErrorMessage)); } _logger.LogInformation(LoggingEvents.GetAllGenres, $"Genres found for request:{correlationToken}"); return(new ObjectResult(response.Data)); }
public async Task <IActionResult> DeleteLineItem(string basketId, int productId) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var correlationToken = CorrelationTokenManager.GenerateToken(); // Note: Sending querystring parameters in the post. var success = await client.DeleteAsync(ServiceEnum.Basket, $"api/basket/{basketId}/lineitem/{productId}?correlationToken={correlationToken}"); if (success) { return(NoContent()); } return(NotFound()); }
public async Task <IActionResult> GetAllArtists() { // See GetAllMusic() action method above for explanation var correlationToken = CorrelationTokenManager.GenerateToken(); var response = await _restClient.GetAsync <List <ArtistDto> >(ServiceEnum.Catalog, "api/Catalog/Artists", correlationToken); if (response.Data == null) { _logger.LogError(LoggingEvents.GetAllArtists, $"Artist not found:{response.ErrorMessage} for request: {correlationToken}"); return(StatusCode((int)response.HttpStatusCode, response.ErrorMessage)); } _logger.LogInformation(LoggingEvents.GetAllArtists, $"Artists found for request:{correlationToken}"); return(new ObjectResult(response.Data)); }