1- using System . Threading . Tasks ;
1+ using System ;
2+ using System . Threading . Tasks ;
3+ using Exam . Application . Storage . Films ;
4+ using Exam . Application . Storage . Films . Commands . Create ;
5+ using Exam . Application . Storage . Films . Commands . Delete ;
6+ using Exam . Application . Storage . Films . Commands . Update ;
7+ using Exam . Application . Storage . Films . Queries . Get ;
28using Exam . Application . Storage . Films . Queries . Get . AsList ;
9+ using Exam . Application . Storage . Films . Queries . Get . AsList . ByActor ;
10+ using FluentValidation ;
311using Microsoft . AspNetCore . Http ;
412using Microsoft . AspNetCore . Mvc ;
513
@@ -9,9 +17,79 @@ public class FilmsController : BaseController
917 {
1018 [ HttpGet ]
1119 [ ProducesResponseType ( StatusCodes . Status200OK ) ]
20+ [ ProducesDefaultResponseType ]
1221 public async Task < ActionResult < FilmsListViewModel > > GetAll ( )
1322 {
1423 return Ok ( await Mediator . Send ( new GetFilmsAsListQuery ( ) ) ) ;
1524 }
25+
26+ [ HttpGet ( "{id}" ) ]
27+ [ ProducesResponseType ( StatusCodes . Status200OK ) ]
28+ [ ProducesDefaultResponseType ]
29+ public async Task < ActionResult < FilmLookupDto > > Get ( int id )
30+ {
31+ return Ok ( await Mediator . Send ( new GetFilmQuery { Id = id } ) ) ;
32+ }
33+
34+ [ HttpGet ( "{id}" ) ]
35+ [ ProducesResponseType ( StatusCodes . Status200OK ) ]
36+ [ ProducesDefaultResponseType ]
37+ public async Task < ActionResult < FilmsListViewModel > > GetAllByActor ( int id )
38+ {
39+ return Ok ( await Mediator . Send ( new GetFilmsByActorAsListQuery { ActorId = id } ) ) ;
40+ }
41+
42+ [ HttpPost ]
43+ [ ProducesResponseType ( StatusCodes . Status200OK ) ]
44+ [ ProducesResponseType ( StatusCodes . Status400BadRequest ) ]
45+ public async Task < IActionResult > Create ( CreateFilmCommand command )
46+ {
47+ try
48+ {
49+ return Ok ( await Mediator . Send ( command ) ) ;
50+ }
51+ catch ( ValidationException e )
52+ {
53+ return BadRequest ( e . Message ) ;
54+ }
55+ }
56+
57+ [ HttpPost ]
58+ [ ProducesResponseType ( StatusCodes . Status200OK ) ]
59+ [ ProducesResponseType ( StatusCodes . Status400BadRequest ) ]
60+ public async Task < IActionResult > Update ( UpdateFilmCommand command )
61+ {
62+ try
63+ {
64+ return Ok ( await Mediator . Send ( command ) ) ;
65+ }
66+ catch ( ValidationException e )
67+ {
68+ return BadRequest ( e . Message ) ;
69+ }
70+ catch ( ArgumentNullException )
71+ {
72+ return BadRequest ( "No entities with this primary key were found in the database." ) ;
73+ }
74+ }
75+
76+ [ HttpDelete ( "{id}" ) ]
77+ [ ProducesResponseType ( StatusCodes . Status200OK ) ]
78+ [ ProducesResponseType ( StatusCodes . Status400BadRequest ) ]
79+ public async Task < IActionResult > Delete ( int id )
80+ {
81+ try
82+ {
83+ return Ok ( await Mediator . Send ( new DeleteFilmCommand { FilmId = id } ) ) ;
84+ }
85+ catch ( ValidationException e )
86+ {
87+ return BadRequest ( e . Message ) ;
88+ }
89+ catch ( ArgumentNullException )
90+ {
91+ return BadRequest ( "No entities with this primary key were found in the database." ) ;
92+ }
93+ }
1694 }
1795}
0 commit comments