Skip to content

Commit

Permalink
Merge pull request #23 from iayti/feature/CAS-7_SampleService
Browse files Browse the repository at this point in the history
Feature/cas 7 sample service
  • Loading branch information
iayti committed Dec 20, 2020
2 parents c76707b + af84ecc commit 5856484
Show file tree
Hide file tree
Showing 100 changed files with 1,393 additions and 388 deletions.
5 changes: 3 additions & 2 deletions src/Apps/Client.WorkerService/Client/SwaggerClientBase.cs
@@ -1,8 +1,9 @@
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;

namespace Client.WorkerService
namespace Client.WorkerService.Client
{
public abstract class SwaggerClientBase
{
Expand All @@ -18,7 +19,7 @@ protected Task<HttpRequestMessage> CreateHttpRequestMessageAsync(CancellationTok
{
var msg = new HttpRequestMessage();
// SET THE BEARER AUTH TOKEN
msg.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", BearerToken);
msg.Headers.Authorization = new AuthenticationHeaderValue("Bearer", BearerToken);
return Task.FromResult(msg);
}
}
Expand Down
359 changes: 358 additions & 1 deletion src/Apps/Client.WorkerService/Client/WebApiClient.cs

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/Apps/Client.WorkerService/Worker.cs
@@ -1,8 +1,9 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
using Client.WorkerService.Client;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace Client.WorkerService
{
Expand Down
6 changes: 3 additions & 3 deletions src/Apps/WebApi/Controllers/BaseApiController.cs
Expand Up @@ -8,8 +8,8 @@ namespace WebApi.Controllers
[Route("api/[controller]")]
public abstract class BaseApiController : ControllerBase
{
private IMediator _mediator;
private ISender _mediator;

protected IMediator Mediator => _mediator ??= HttpContext.RequestServices.GetService<IMediator>();
protected ISender Mediator => _mediator ??= HttpContext.RequestServices.GetService<ISender>();
}
}
}
8 changes: 4 additions & 4 deletions src/Apps/WebApi/Controllers/CitiesController.cs
@@ -1,4 +1,7 @@
using Application.Cities.Commands.Create;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Application.Cities.Commands.Create;
using Application.Cities.Commands.Delete;
using Application.Cities.Commands.Update;
using Application.Cities.Queries.GetCities;
Expand All @@ -7,9 +10,6 @@
using Application.Dto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace WebApi.Controllers
{
Expand Down
4 changes: 2 additions & 2 deletions src/Apps/WebApi/Controllers/DistrictsController.cs
@@ -1,10 +1,10 @@
using Application.Cities.Commands.Create;
using System.Threading.Tasks;
using Application.Common.Models;
using Application.Districts.Commands.Create;
using Application.Districts.Queries;
using Application.Dto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace WebApi.Controllers
{
Expand Down
4 changes: 2 additions & 2 deletions src/Apps/WebApi/Controllers/LoginController.cs
@@ -1,7 +1,7 @@
using Application.ApplicationUser.Queries.GetToken;
using System.Threading.Tasks;
using Application.ApplicationUser.Queries.GetToken;
using Application.Common.Models;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace WebApi.Controllers
{
Expand Down
4 changes: 2 additions & 2 deletions src/Apps/WebApi/Controllers/VillagesController.cs
@@ -1,9 +1,9 @@
using Application.Common.Models;
using System.Threading.Tasks;
using Application.Common.Models;
using Application.Dto;
using Application.Villages.Queries.GetVillagesWithPagination;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace WebApi.Controllers
{
Expand Down
15 changes: 12 additions & 3 deletions src/Apps/WebApi/Controllers/WeatherForecastController.cs
@@ -1,7 +1,10 @@
using Application.WeatherForecasts.Queries;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
using Application.Common.Models;
using Application.Dto;
using Application.WeatherForecasts.Queries;
using Application.WeatherForecasts.Queries.GetCurrentWeatherForecastQuery;
using Microsoft.AspNetCore.Mvc;

namespace WebApi.Controllers
{
Expand All @@ -12,5 +15,11 @@ public async Task<IEnumerable<WeatherForecast>> Get()
{
return await Mediator.Send(new GetWeatherForecastsQuery());
}

[HttpGet("current")]
public async Task<ActionResult<ServiceResult<CurrentWeatherForecastDto>>> GetCurrentWeather([FromQuery] GetCurrentWeatherForecastQuery query)
{
return await Mediator.Send(query);
}
}
}
6 changes: 3 additions & 3 deletions src/Apps/WebApi/Filters/ApiExceptionFilterAttribute.cs
@@ -1,10 +1,10 @@
using Application.Common.Exceptions;
using System;
using System.Collections.Generic;
using Application.Common.Exceptions;
using Application.Common.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;

namespace WebApi.Filters
{
Expand Down
6 changes: 3 additions & 3 deletions src/Apps/WebApi/Program.cs
@@ -1,3 +1,5 @@
using System;
using System.Threading.Tasks;
using Infrastructure.Identity;
using Infrastructure.Persistence;
using Microsoft.AspNetCore.Hosting;
Expand All @@ -8,8 +10,6 @@
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Sinks.Elasticsearch;
using System;
using System.Threading.Tasks;

namespace WebApi
{
Expand All @@ -29,7 +29,7 @@ public static async Task Main(string[] args)

if (context.Database.IsSqlServer())
{
context.Database.Migrate();
await context.Database.MigrateAsync();
}

var userManager = services.GetRequiredService<UserManager<ApplicationUser>>();
Expand Down
4 changes: 2 additions & 2 deletions src/Apps/WebApi/Services/CurrentUserService.cs
@@ -1,6 +1,6 @@
using Application.Common.Interfaces;
using System.Security.Claims;
using Application.Common.Interfaces;
using Microsoft.AspNetCore.Http;
using System.Security.Claims;

namespace WebApi.Services
{
Expand Down
7 changes: 5 additions & 2 deletions src/Apps/WebApi/Startup.cs
@@ -1,5 +1,7 @@
using System.Linq;
using Application;
using Application.Common.Interfaces;
using FluentValidation.AspNetCore;
using Infrastructure;
using Infrastructure.Persistence;
using Microsoft.AspNetCore.Builder;
Expand All @@ -10,8 +12,6 @@
using Microsoft.Extensions.Hosting;
using NSwag;
using NSwag.Generation.Processors.Security;
using System.Linq;
using FluentValidation.AspNetCore;
using WebApi.Filters;
using WebApi.Services;

Expand All @@ -36,6 +36,8 @@ public void ConfigureServices(IServiceCollection services)
services.AddSingleton<ICurrentUserService, CurrentUserService>();

services.AddHttpContextAccessor();

services.AddDatabaseDeveloperPageExceptionFilter();

services.AddHealthChecks()
.AddDbContextCheck<ApplicationDbContext>();
Expand Down Expand Up @@ -71,6 +73,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseMigrationsEndPoint();
}
else
{
Expand Down
10 changes: 5 additions & 5 deletions src/Apps/WebApi/WebApi.csproj
Expand Up @@ -13,14 +13,14 @@

<ItemGroup>
<PackageReference Include="FluentValidation.AspNetCore" Version="9.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.0">
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="5.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.9" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.1" />
<PackageReference Include="NSwag.AspNetCore" Version="13.9.4" />
<PackageReference Include="NSwag.MSBuild" Version="13.9.4">
<PrivateAssets>all</PrivateAssets>
Expand All @@ -38,7 +38,7 @@

<Target Name="NSwag" AfterTargets="Build" Condition="'$(Configuration)' == 'Debug'">
<Copy SourceFiles="@(Reference)" DestinationFolder="$(OutDir)References" />
<Exec Command="$(NSwagExe_Core31) run /variables:Configuration=$(Configuration)" />
<Exec Command="$(NSwagExe_Net50) run /variables:Configuration=$(Configuration)" />
<RemoveDir Directories="$(OutDir)References" />
</Target>

Expand Down
12 changes: 12 additions & 0 deletions src/Apps/WebApi/appsettings.json
Expand Up @@ -4,6 +4,18 @@
"DefaultConnection": "Server=localhost,11433; Database=CleanArchitectureDB; User Id = SA; Password=Kurabiyem_1850; MultipleActiveResultSets=true;",
"DefaultConnection_Postgres": "User ID=postgres;Password=Matech_1850;Server=localhost;Port=5433;Database=CleanArchitectureDB;Integrated Security=true;Pooling=true;"
},
"OpenWeatherApi": {
"Url": "https://community-open-weather-map.p.rapidapi.com",
"Key": {
"Key": "x-rapidapi-key",
"Value": "3369e32b2amsh0bba2750892f097p19eebajsn320eb2369f6c"
},
"Host": {
"Key": "x-rapidapi-host",
"Value": "community-open-weather-map.p.rapidapi.com"
}

},
"ApplicationName": "elastic-search-web-api",
"Serilog": {
"MinimumLevel": {
Expand Down
6 changes: 3 additions & 3 deletions src/Apps/WebApi/nswag.json
@@ -1,5 +1,5 @@
{
"runtime": "NetCore31",
"runtime": "Net50",
"defaultVariables": null,
"documentGenerator": {
"aspNetCoreToOpenApi": {
Expand Down Expand Up @@ -90,7 +90,7 @@
"wrapResponses": false,
"generateResponseClasses": true,
"responseClass": "SwaggerResponse",
"namespace": "Client.WorkerService",
"namespace": "Client.WorkerService.Client",
"requiredPropertiesMustBeDefined": true,
"dateType": "System.DateTime",
"dateTimeType": "System.DateTime",
Expand All @@ -110,4 +110,4 @@
"output": "../Client.WorkerService/Client/WebApiClient.cs"
}
}
}
}

0 comments on commit 5856484

Please sign in to comment.