-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
560 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[*.cs] | ||
|
||
# CS1591: Fehledes XML-Kommentar für öffentlich sichtbaren Typ oder Element | ||
dotnet_diagnostic.CS1591.severity = none |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
PlanB.Butler.Admin/PlanB.Butler.Admin/Contracts/IRestaurantService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) PlanB. GmbH. All Rights Reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
using PlanB.Butler.Admin.Models; | ||
|
||
namespace PlanB.Butler.Admin.Contracts | ||
{ | ||
/// <summary> | ||
/// IRestaurantService. | ||
/// </summary> | ||
public interface IRestaurantService | ||
{ | ||
/// <summary> | ||
/// Gets the restaurant. | ||
/// </summary> | ||
/// <returns>Restaurant.</returns> | ||
Task<List<RestaurantViewModel>> GetRestaurant(); | ||
|
||
/// <summary> | ||
/// Creates the meal. | ||
/// </summary> | ||
/// <param name="restaurant">The meal.</param> | ||
/// <returns>True or false.</returns> | ||
Task<bool> CreateRestaurant(RestaurantViewModel restaurant); | ||
|
||
/// <summary> | ||
/// Updates the restaurant. | ||
/// </summary> | ||
/// <param name="restaurant">The restuarant.</param> | ||
/// <returns>Restaurant.</returns> | ||
Task<RestaurantViewModel> UpdateRestaurant(RestaurantViewModel restaurant); | ||
|
||
/// <summary> | ||
/// Gets the restaurant. | ||
/// </summary> | ||
/// <param name="id">The identifier.</param> | ||
/// <returns>Restaurant by Id.</returns> | ||
Task<RestaurantViewModel> GetRestaurant(string id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
PlanB.Butler.Admin/PlanB.Butler.Admin/Services/RestaurantService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
// Copyright (c) PlanB. GmbH. All Rights Reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
using Microsoft.Extensions.Configuration; | ||
using Newtonsoft.Json; | ||
using PlanB.Butler.Admin.Contracts; | ||
using PlanB.Butler.Admin.Models; | ||
|
||
namespace PlanB.Butler.Admin.Services | ||
{ | ||
/// <summary> | ||
/// RestaurantService. | ||
/// </summary> | ||
/// <seealso cref="PlanB.Butler.Admin.Contracts.IRestaurantService" /> | ||
public class RestaurantService : IRestaurantService | ||
{ | ||
/// <summary> | ||
/// The HTTP client. | ||
/// </summary> | ||
private readonly HttpClient httpClient; | ||
|
||
/// <summary> | ||
/// The configuration. | ||
/// </summary> | ||
private readonly IConfiguration config; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="RestaurantService" /> class. | ||
/// </summary> | ||
/// <param name="httpClient">The HTTP client.</param> | ||
/// <param name="configuration">The configuration.</param> | ||
public RestaurantService(HttpClient httpClient, IConfiguration configuration) | ||
{ | ||
this.httpClient = httpClient; | ||
this.config = configuration; | ||
} | ||
|
||
/// <summary> | ||
/// Creates the meal. | ||
/// </summary> | ||
/// <param name="restaurant">The restaurant.</param> | ||
/// <returns> | ||
/// True or false. | ||
/// </returns> | ||
public async Task<bool> CreateRestaurant(RestaurantViewModel restaurant) | ||
{ | ||
Guid correlationId = Guid.NewGuid(); | ||
restaurant.CorrelationId = correlationId; | ||
var json = JsonConvert.SerializeObject(restaurant); | ||
StringContent content = Util.CreateStringContent(json, correlationId, null); | ||
var uri = this.config["RestaurantUri"]; | ||
|
||
HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, uri) | ||
{ | ||
Content = content, | ||
}; | ||
httpRequestMessage.Headers.Clear(); | ||
Util.AddDefaultEsbHeaders(httpRequestMessage, correlationId, this.config["FunctionsKey"]); | ||
var result = await this.httpClient.SendAsync(httpRequestMessage); | ||
result.EnsureSuccessStatusCode(); | ||
var success = result.IsSuccessStatusCode; | ||
return success; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the restaurant. | ||
/// </summary> | ||
/// <param name="id">The identifier.</param> | ||
/// <returns> | ||
/// Restaurant by Id. | ||
/// </returns> | ||
public async Task<RestaurantViewModel> GetRestaurant(string id) | ||
{ | ||
Guid correlationId = Guid.NewGuid(); | ||
var uri = this.config["RestaurantUri"].TrimEnd('/') + "/" + id; | ||
HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, uri); | ||
httpRequestMessage.Headers.Clear(); | ||
Util.AddDefaultEsbHeaders(httpRequestMessage, correlationId, this.config["FunctionsKey"]); | ||
var result = await this.httpClient.SendAsync(httpRequestMessage); | ||
result.EnsureSuccessStatusCode(); | ||
|
||
var body = result.Content.ReadAsStringAsync().Result; | ||
|
||
var restaurant = JsonConvert.DeserializeObject<RestaurantViewModel>(body); | ||
return restaurant; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the restaurant. | ||
/// </summary> | ||
/// <returns> | ||
/// Restaurant. | ||
/// </returns> | ||
public async Task<List<RestaurantViewModel>> GetRestaurant() | ||
{ | ||
var uri = this.config["RestaurantUri"]; | ||
this.httpClient.DefaultRequestHeaders.Add(Constants.FunctionsKeyHeader, this.config["FunctionsKey"]); | ||
var responseString = await this.httpClient.GetStringAsync(uri); | ||
|
||
var restaurant = JsonConvert.DeserializeObject<List<RestaurantViewModel>>(responseString); | ||
return restaurant; | ||
} | ||
|
||
/// <summary> | ||
/// Updates the restaurant. | ||
/// </summary> | ||
/// <param name="restaurant">The restaurant.</param> | ||
/// <returns> | ||
/// Restaurant. | ||
/// </returns> | ||
public async Task<RestaurantViewModel> UpdateRestaurant(RestaurantViewModel restaurant) | ||
{ | ||
Guid correlationId = Guid.NewGuid(); | ||
restaurant.CorrelationId = correlationId; | ||
var json = JsonConvert.SerializeObject(restaurant); | ||
StringContent content = Util.CreateStringContent(json, correlationId, null); | ||
var uri = this.config["RestaurantUri"].TrimEnd('/') + "/" + restaurant.Id; | ||
|
||
HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Put, uri) | ||
{ | ||
Content = content, | ||
}; | ||
httpRequestMessage.Headers.Clear(); | ||
Util.AddDefaultEsbHeaders(httpRequestMessage, correlationId, this.config["FunctionsKey"]); | ||
var result = await this.httpClient.SendAsync(httpRequestMessage); | ||
result.EnsureSuccessStatusCode(); | ||
var responseString = await result.Content.ReadAsStringAsync(); | ||
|
||
var updatedRestaurant = JsonConvert.DeserializeObject<RestaurantViewModel>(responseString); | ||
return updatedRestaurant; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.