22using Microsoft . AspNetCore . Authorization ;
33using Microsoft . AspNetCore . Http ;
44using Microsoft . AspNetCore . Mvc ;
5- using StarWars . Interface ;
5+ using StarWars . Api . Services ;
66using StarWars . Model ;
77using StarWars . Model . ViewModels ;
88using System ;
@@ -14,18 +14,18 @@ namespace StarWars.Api.Controllers
1414 [ Route ( "api/[controller]" ) ]
1515 public class MoviesController : ControllerBase
1616 {
17- private readonly IMovieService service ;
17+ private readonly IMovieService _movieService ;
1818
19- public MoviesController ( IMovieService service )
19+ public MoviesController ( IMovieService movieService )
2020 {
21- this . service = service ;
21+ _movieService = movieService ;
2222 }
2323
2424 [ HttpGet ]
2525 [ ProducesResponseType ( StatusCodes . Status200OK ) ]
2626 public async Task < IActionResult > AllAsync ( )
2727 {
28- var items = await service . All ( ) ;
28+ var items = await _movieService . AllAsync ( ) ;
2929 return new OkObjectResult ( items ) ;
3030 }
3131
@@ -35,7 +35,7 @@ public async Task<IActionResult> AllAsync()
3535 [ ProducesResponseType ( StatusCodes . Status401Unauthorized ) ]
3636 public async Task < IActionResult > AllProtectedAsync ( )
3737 {
38- var items = await service . All ( ) ;
38+ var items = await _movieService . AllAsync ( ) ;
3939 return new OkObjectResult ( items ) ;
4040 }
4141
@@ -72,45 +72,45 @@ public async Task<IActionResult> AllSecuredAsync()
7272 }
7373
7474 [ HttpGet ( "{id}" ) ]
75- public async Task < IActionResult > Get ( [ FromRoute ] string id )
75+ public async Task < IActionResult > GetAsync ( [ FromRoute ] string id )
7676 {
77- var item = await service . Get ( id ) ;
77+ var item = await _movieService . GetAsync ( id ) ;
7878 if ( item == null ) return new NotFoundObjectResult ( id ) ;
7979
8080 return new OkObjectResult ( item ) ;
8181 }
8282
8383 [ Authorize ]
8484 [ HttpPost ( ) ]
85- public async Task < IActionResult > Create ( [ FromBody ] MovieView movieView )
85+ public async Task < IActionResult > CreateAsync ( [ FromBody ] MovieView movieView )
8686 {
8787 var movie = Mapper . Map < Movie > ( movieView ) ;
88- var item = await service . Create ( movie ) ;
88+ var item = await _movieService . CreateAsync ( movie ) ;
8989 if ( item == null ) return new BadRequestObjectResult ( $ "Movie with ID '{ movieView . ID } ' already exists in DB") ;
9090
9191 return new OkObjectResult ( item ) ;
9292 }
9393
9494 [ Authorize ]
9595 [ HttpPut ( "{id}" ) ]
96- public async Task < IActionResult > Update ( [ FromRoute ] string id , [ FromBody ] MovieView movieView )
96+ public async Task < IActionResult > UpdateAsync ( [ FromRoute ] string id , [ FromBody ] MovieView movieView )
9797 {
98- var existingItem = await service . Get ( id ) ;
98+ var existingItem = await _movieService . GetAsync ( id ) ;
9999 if ( existingItem == null ) return new NotFoundObjectResult ( id ) ;
100100 var movie = Mapper . Map < Movie > ( movieView ) ;
101- var item = await service . Update ( id , movie ) ;
101+ var item = await _movieService . UpdateAsync ( id , movie ) ;
102102 if ( item == null ) return new BadRequestObjectResult ( $ "Movie with ID '{ id } ' could not be updated") ;
103103 return new OkObjectResult ( item ) ;
104104 }
105105
106106 [ Authorize ]
107107 [ HttpDelete ( "{id}" ) ]
108- public async Task < IActionResult > Delete ( [ FromRoute ] string id )
108+ public async Task < IActionResult > DeleteAsync ( [ FromRoute ] string id )
109109 {
110- var item = await service . Get ( id ) ;
110+ var item = await _movieService . GetAsync ( id ) ;
111111 if ( item == null ) return new NotFoundObjectResult ( id ) ;
112112
113- item = await service . Delete ( id ) ;
113+ item = await _movieService . DeleteAsync ( id ) ;
114114
115115 if ( item == null ) return new BadRequestObjectResult ( $ "Movie with ID '{ id } ' could not be deleted") ;
116116
0 commit comments