-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from FitIW/feature/Lecture_12
Feature/lecture 12
- Loading branch information
Showing
227 changed files
with
26,907 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Git LFS file not shown
Git LFS file not shown
41 changes: 41 additions & 0 deletions
41
Lectures/Lecture_12/sln/CookBook.Api/Controllers/v1/IngredientController.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,41 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using NSwag.Annotations; | ||
using System; | ||
|
||
namespace CookBook.Api.Controllers.v1 | ||
{ | ||
[ApiController] | ||
[Route("api/[controller]")] | ||
[ApiVersion("1.0")] | ||
public class IngredientController : ControllerBase | ||
{ | ||
[HttpGet] | ||
[OpenApiOperation("Ingredient" + nameof(GetAll))] | ||
public IActionResult GetAll() | ||
{ | ||
var ingredients = new[] | ||
{ | ||
new { Id = new Guid("df935095-8709-4040-a2bb-b6f97cb416dc"), Name = "Vejce", Description = "Popis vajec" }, | ||
new { Id = new Guid("23b3902d-7d4f-4213-9cf0-112348f56238"), Name = "Name 2", Description = "Description 2" } | ||
}; | ||
return Ok(ingredients); | ||
} | ||
|
||
[HttpGet("{id}")] | ||
public IActionResult GetById(Guid id) | ||
{ | ||
if (id == new Guid("df935095-8709-4040-a2bb-b6f97cb416dc")) | ||
{ | ||
return Ok(new | ||
{ | ||
Id = new Guid("df935095-8709-4040-a2bb-b6f97cb416dc"), | ||
Name = "Vejce" | ||
}); | ||
} | ||
else | ||
{ | ||
return NotFound(); | ||
} | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
Lectures/Lecture_12/sln/CookBook.Api/Controllers/v2/IngredientController.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,36 @@ | ||
using CookBook.DAL.Entities; | ||
using CookBook.DAL.Repositories; | ||
using Microsoft.AspNetCore.Mvc; | ||
using NSwag.Annotations; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace CookBook.Api.Controllers.v2 | ||
{ | ||
[ApiController] | ||
[Route("api/[controller]")] | ||
[ApiVersion("2.0")] | ||
public class IngredientController : ControllerBase | ||
{ | ||
private readonly IngredientRepository ingredientRepository; | ||
|
||
public IngredientController(IngredientRepository ingredientRepository) | ||
{ | ||
this.ingredientRepository = ingredientRepository; | ||
} | ||
|
||
[HttpGet] | ||
[OpenApiOperation("Ingredient" + nameof(GetAll))] | ||
public IList<IngredientEntity> GetAll() | ||
{ | ||
return ingredientRepository.GetAll(); | ||
} | ||
|
||
[HttpGet("{id}")] | ||
[OpenApiOperation("Ingredient" + nameof(GetById))] | ||
public IngredientEntity GetById(Guid id) | ||
{ | ||
return ingredientRepository.GetById(id); | ||
} | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
Lectures/Lecture_12/sln/CookBook.Api/Controllers/v3/IngredientController.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,72 @@ | ||
using CookBook.BL.Api.Facades; | ||
using CookBook.Common.Resources; | ||
using CookBook.Models; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Localization; | ||
using NSwag.Annotations; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace CookBook.Api.Controllers.v3 | ||
{ | ||
[ApiController] | ||
[Route("api/[controller]")] | ||
[ApiVersion("3.0")] | ||
public class IngredientController : ControllerBase | ||
{ | ||
private const string ApiOperationBaseName = "Ingredient"; | ||
private readonly IngredientFacade ingredientFacade; | ||
private readonly IStringLocalizer<IngredientControllerResources> ingredientControllerLocalizer; | ||
|
||
public IngredientController( | ||
IngredientFacade ingredientFacade, | ||
IStringLocalizer<IngredientControllerResources> ingredientControllerLocalizer) | ||
{ | ||
this.ingredientFacade = ingredientFacade; | ||
this.ingredientControllerLocalizer = ingredientControllerLocalizer; | ||
} | ||
|
||
[HttpGet] | ||
[OpenApiOperation(ApiOperationBaseName + nameof(GetAll))] | ||
public ActionResult<List<IngredientListModel>> GetAll() | ||
{ | ||
return ingredientFacade.GetAll().ToList(); | ||
} | ||
|
||
[HttpGet("{id}")] | ||
[OpenApiOperation(ApiOperationBaseName + nameof(GetById))] | ||
public ActionResult<IngredientDetailModel> GetById(Guid id) | ||
{ | ||
var ingredient = ingredientFacade.GetById(id); | ||
if (ingredient == null) | ||
{ | ||
return NotFound(ingredientControllerLocalizer[nameof(IngredientControllerResources.GetById_NotFound), id].Value); | ||
} | ||
|
||
return ingredient; | ||
} | ||
|
||
[HttpPost] | ||
[OpenApiOperation(ApiOperationBaseName + nameof(Create))] | ||
public ActionResult<Guid> Create(IngredientDetailModel ingredient) | ||
{ | ||
return ingredientFacade.Create(ingredient); | ||
} | ||
|
||
[HttpPut] | ||
[OpenApiOperation(ApiOperationBaseName + nameof(Update))] | ||
public ActionResult<Guid> Update(IngredientDetailModel ingredient) | ||
{ | ||
return ingredientFacade.Update(ingredient); | ||
} | ||
|
||
[HttpDelete("{id}")] | ||
[OpenApiOperation(ApiOperationBaseName + nameof(Delete))] | ||
public IActionResult Delete(Guid id) | ||
{ | ||
ingredientFacade.Delete(id); | ||
return Ok(); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Lectures/Lecture_12/sln/CookBook.Api/Controllers/v3/LoggingController.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,29 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
using NSwag.Annotations; | ||
using System; | ||
|
||
namespace CookBook.Api.Controllers.v3 | ||
{ | ||
[ApiController] | ||
[Route("api/[controller]")] | ||
[ApiVersion("3.0")] | ||
public class LoggingController : ControllerBase | ||
{ | ||
private const string ApiOperationBaseName = "Logging"; | ||
private readonly ILogger<LoggingController> logger; | ||
|
||
public LoggingController(ILogger<LoggingController> logger) | ||
{ | ||
this.logger = logger; | ||
} | ||
|
||
[HttpGet] | ||
[OpenApiOperation(ApiOperationBaseName + nameof(LogSomething))] | ||
public void LogSomething() | ||
{ | ||
logger.LogInformation("Something"); | ||
logger.LogWarning("Log something called in {0}", DateTime.Now); | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
Lectures/Lecture_12/sln/CookBook.Api/Controllers/v3/RecipeController.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,59 @@ | ||
using CookBook.BL.Api.Facades; | ||
using Microsoft.AspNetCore.Mvc; | ||
using NSwag.Annotations; | ||
using System; | ||
using System.Collections.Generic; | ||
using CookBook.Models; | ||
|
||
namespace CookBook.Api.Controllers.v3 | ||
{ | ||
[ApiController] | ||
[Route("api/[controller]")] | ||
[ApiVersion("3.0")] | ||
public class RecipeController : ControllerBase | ||
{ | ||
private const string ApiOperationBaseName = "Recipe"; | ||
private readonly RecipeFacade recipeFacade; | ||
|
||
public RecipeController(RecipeFacade recipeFacade) | ||
{ | ||
this.recipeFacade = recipeFacade; | ||
} | ||
|
||
[HttpGet] | ||
[OpenApiOperation(ApiOperationBaseName + nameof(GetAll))] | ||
public ActionResult<List<RecipeListModel>> GetAll() | ||
{ | ||
return recipeFacade.GetAll(); | ||
} | ||
|
||
[HttpGet("{id}")] | ||
[OpenApiOperation(ApiOperationBaseName + nameof(GetById))] | ||
public ActionResult<RecipeDetailModel> GetById(Guid id) | ||
{ | ||
return recipeFacade.GetById(id); | ||
} | ||
|
||
[HttpPost] | ||
[OpenApiOperation(ApiOperationBaseName + nameof(Create))] | ||
public ActionResult<Guid> Create(RecipeDetailModel recipe) | ||
{ | ||
return recipeFacade.Create(recipe); | ||
} | ||
|
||
[HttpPut] | ||
[OpenApiOperation(ApiOperationBaseName + nameof(Update))] | ||
public ActionResult<Guid?> Update(RecipeDetailModel recipe) | ||
{ | ||
return recipeFacade.Update(recipe); | ||
} | ||
|
||
[HttpDelete("{id}")] | ||
[OpenApiOperation(ApiOperationBaseName + nameof(Delete))] | ||
public IActionResult Delete(Guid id) | ||
{ | ||
recipeFacade.Delete(id); | ||
return Ok(); | ||
} | ||
} | ||
} |
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,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp3.1</TargetFramework> | ||
<UserSecretsId>70e22f70-c609-4d6a-9be8-b462915b90e5</UserSecretsId> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" /> | ||
<PackageReference Include="FluentValidation.AspNetCore" Version="8.6.1" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.1" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="4.1.1" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="4.1.1" /> | ||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.1" /> | ||
<PackageReference Include="NSwag.AspNetCore" Version="13.2.2" /> | ||
<PackageReference Include="Scrutor" Version="3.2.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\CookBook.BL.Api\CookBook.BL.Api.csproj" /> | ||
</ItemGroup> | ||
|
||
|
||
</Project> |
13 changes: 13 additions & 0 deletions
13
Lectures/Lecture_12/sln/CookBook.Api/Extensions/ApplicationBuilderExtensions.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,13 @@ | ||
using CookBook.Api.Middlewares; | ||
using Microsoft.AspNetCore.Builder; | ||
|
||
namespace CookBook.Api.Extensions | ||
{ | ||
public static class ApplicationBuilderExtensions | ||
{ | ||
public static IApplicationBuilder UseRequestCulture(this IApplicationBuilder builder) | ||
{ | ||
return builder.UseMiddleware<RequestCultureMiddleware>(); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
Lectures/Lecture_12/sln/CookBook.Api/Middlewares/RequestCultureMiddleware.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,29 @@ | ||
using Microsoft.AspNetCore.Http; | ||
using System.Globalization; | ||
using System.Threading.Tasks; | ||
|
||
namespace CookBook.Api.Middlewares | ||
{ | ||
public class RequestCultureMiddleware | ||
{ | ||
private readonly RequestDelegate next; | ||
|
||
public RequestCultureMiddleware(RequestDelegate next) | ||
{ | ||
this.next = next; | ||
} | ||
|
||
public async Task InvokeAsync(HttpContext context) | ||
{ | ||
var culture = context.Request.Query["culture"]; | ||
if (!string.IsNullOrWhiteSpace(culture)) | ||
{ | ||
var cultureInfo = new CultureInfo(culture); | ||
CultureInfo.CurrentCulture = cultureInfo; | ||
CultureInfo.CurrentUICulture = cultureInfo; | ||
} | ||
|
||
await next(context); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Lectures/Lecture_12/sln/CookBook.Api/Processors/RequestCultureOperationProcessor.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,23 @@ | ||
using NJsonSchema; | ||
using NSwag; | ||
using NSwag.Generation.Processors; | ||
using NSwag.Generation.Processors.Contexts; | ||
|
||
namespace CookBook.Api.Processors | ||
{ | ||
public class RequestCultureOperationProcessor : IOperationProcessor | ||
{ | ||
public bool Process(OperationProcessorContext context) | ||
{ | ||
context.OperationDescription.Operation.Parameters.Add(new OpenApiParameter | ||
{ | ||
Name = "culture", | ||
Kind = OpenApiParameterKind.Query, | ||
Type = JsonObjectType.String, | ||
IsRequired = false | ||
}); | ||
|
||
return true; | ||
} | ||
} | ||
} |
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,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace CookBook.Api | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
CreateHostBuilder(args).Build().Run(); | ||
} | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.ConfigureLogging(builder => | ||
{ | ||
builder.ClearProviders() | ||
.AddConsole() | ||
.AddFilter("System", LogLevel.Debug) | ||
.SetMinimumLevel(LogLevel.Warning); | ||
}) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
}); | ||
} | ||
} |
Oops, something went wrong.