This repository was archived by the owner on Oct 16, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 10 files changed +78
-15
lines changed
Expand file tree Collapse file tree 10 files changed +78
-15
lines changed Original file line number Diff line number Diff line change 1+ using MediatR ;
2+ using Microsoft . AspNetCore . Mvc ;
3+ using Microsoft . Extensions . DependencyInjection ;
4+
5+ namespace Exam . Clients . WebApi . Controllers
6+ {
7+ [ ApiController ]
8+ [ Route ( "api/[controller]/[action]" ) ]
9+ public abstract class BaseController : ControllerBase
10+ {
11+ private IMediator _mediator ;
12+
13+ protected IMediator Mediator => _mediator ??= HttpContext . RequestServices . GetService < IMediator > ( ) ;
14+ }
15+ }
Original file line number Diff line number Diff line change 1+ using System . Threading . Tasks ;
2+ using Exam . Application . Storage . Films . Queries . Get . AsList ;
3+ using Microsoft . AspNetCore . Http ;
4+ using Microsoft . AspNetCore . Mvc ;
5+
6+ namespace Exam . Clients . WebApi . Controllers
7+ {
8+ public class FilmsController : BaseController
9+ {
10+ [ HttpGet ]
11+ [ ProducesResponseType ( StatusCodes . Status200OK ) ]
12+ public async Task < ActionResult < FilmsListViewModel > > GetAll ( )
13+ {
14+ return Ok ( await Mediator . Send ( new GetFilmsAsListQuery ( ) ) ) ;
15+ }
16+ }
17+ }
Original file line number Diff line number Diff line change 44 <TargetFramework >netcoreapp3.1</TargetFramework >
55 </PropertyGroup >
66
7- <ItemGroup >
8- <Folder Include =" Controllers\" />
9- </ItemGroup >
10-
117 <ItemGroup >
128 <PackageReference Include =" FluentValidation.AspNetCore" Version =" 8.6.2" />
139 <PackageReference Include =" Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version =" 3.1.3" />
10+ <PackageReference Include =" Microsoft.Extensions.DependencyInjection.Abstractions" Version =" 3.1.3" />
1411 <PackageReference Include =" Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version =" 3.1.3" />
12+ <PackageReference Include =" Microsoft.VisualStudio.Web.CodeGeneration.Design" Version =" 3.1.1" />
1513 </ItemGroup >
1614
1715 <ItemGroup >
Original file line number Diff line number Diff line change 1- {
2- "$schema" : " http://json.schemastore.org/launchsettings.json" ,
1+ {
32 "iisSettings" : {
43 "windowsAuthentication" : false ,
54 "anonymousAuthentication" : true ,
87 "sslPort" : 44306
98 }
109 },
10+ "$schema" : " http://json.schemastore.org/launchsettings.json" ,
1111 "profiles" : {
1212 "IIS Express" : {
1313 "commandName" : " IISExpress" ,
1414 "launchBrowser" : true ,
15- "launchUrl" : " weatherforecast" ,
1615 "environmentVariables" : {
1716 "ASPNETCORE_ENVIRONMENT" : " Development"
1817 }
2120 "commandName" : " Project" ,
2221 "launchBrowser" : true ,
2322 "launchUrl" : " weatherforecast" ,
24- "applicationUrl" : " https://localhost:5001;http://localhost:5000" ,
2523 "environmentVariables" : {
2624 "ASPNETCORE_ENVIRONMENT" : " Development"
27- }
25+ },
26+ "applicationUrl" : " https://localhost:5001;http://localhost:5000"
2827 }
2928 }
3029}
Original file line number Diff line number Diff line change 1- namespace Exam . Application
1+ using System . IO ;
2+
3+ namespace Exam . Application
24{
35 public static class Consts
46 {
5- public static string PathMockFilms => "" ;
7+ public static string FilmsMockPath
8+ {
9+ get
10+ {
11+ var split = Path . DirectorySeparatorChar ;
12+ var up = $ "{ split } ..";
13+ return $ "{ Directory . GetCurrentDirectory ( ) } { up } { up } { up } { split } mocks{ split } seeding{ split } mock-films.json";
14+ }
15+ }
616 }
717}
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ public async Task SeedAllAsync(CancellationToken cancellationToken)
2121 {
2222 if ( _context . Films . Any ( ) ) return ;
2323
24- await SeedMocksAsync ( Consts . PathMockFilms , cancellationToken ) ;
24+ await SeedMocksAsync ( Consts . FilmsMockPath , cancellationToken ) ;
2525 }
2626
2727 private async Task SeedMocksAsync ( string filePath , CancellationToken cancellationToken )
Original file line number Diff line number Diff line change @@ -7,9 +7,10 @@ namespace Exam.Infrastructure
77{
88 public static class DependencyInjection
99 {
10+ // ReSharper disable once UnusedMethodReturnValue.Global
1011 public static IServiceCollection AddInfrastructure ( this IServiceCollection self )
1112 {
12- self . AddTransient < IJsonMocksReader < Film > , JsonMocksReader < Film > > ( ) ;
13+ self . AddTransient < IJsonMocksReader < Film > , JsonFilmsMockReader > ( ) ;
1314
1415 return self ;
1516 }
Original file line number Diff line number Diff line change 1+ using System . Collections . Generic ;
2+ using System . Linq ;
3+ using System . Threading ;
4+ using System . Threading . Tasks ;
5+ using Exam . Domain . Entities ;
6+
7+ namespace Exam . Infrastructure . MockReaders
8+ {
9+ public class JsonFilmsMockReader : JsonMockReader < Film >
10+ {
11+ public override async Task < IEnumerable < Film > > ReadAsync ( string filePath , CancellationToken cancellationToken )
12+ {
13+ return await await Task . Factory . StartNew (
14+ async ( ) => ( await DeserializeAsync ( filePath , cancellationToken ) )
15+ . GroupBy ( x => x . Title )
16+ . Select ( x => x . FirstOrDefault ( ) ) , cancellationToken ) ;
17+ }
18+ }
19+ }
Original file line number Diff line number Diff line change 77
88namespace Exam . Infrastructure . MockReaders
99{
10- public class JsonMocksReader < TEntity > : IJsonMocksReader < TEntity > where TEntity : class , new ( )
10+ public abstract class JsonMockReader < TEntity > : IJsonMocksReader < TEntity > where TEntity : class , new ( )
1111 {
12- public async Task < IEnumerable < TEntity > > ReadAsync ( string filePath , CancellationToken cancellationToken )
12+ public abstract Task < IEnumerable < TEntity > > ReadAsync ( string filePath , CancellationToken cancellationToken ) ;
13+
14+ protected async Task < IEnumerable < TEntity > > DeserializeAsync ( string filePath ,
15+ CancellationToken cancellationToken )
1316 {
1417 return await await Task . Factory . StartNew (
1518 async ( ) => JsonConvert . DeserializeObject < IEnumerable < TEntity > > (
Load Diff Large diffs are not rendered by default.
You can’t perform that action at this time.
0 commit comments