1- using Microsoft . AspNetCore . Mvc ;
1+ using Microsoft . AspNetCore . Authorization ;
2+ using Microsoft . AspNetCore . Mvc ;
23using MockMe . API . Services ;
34using MockMe . API . ViewModels ;
45using System ;
@@ -11,27 +12,27 @@ namespace MockMe.API.Controllers
1112 [ Route ( "api/[controller]" ) ]
1213 public class TradeController : ControllerBase
1314 {
14- private readonly ITradeService tradeService ;
15- private readonly IAssetService assetService ;
15+ readonly ITradeService _tradeService ;
16+ readonly ICountryService _countryService ;
1617
17- public TradeController ( ITradeService tradeService , IAssetService assetService )
18+ public TradeController ( ITradeService tradeService , ICountryService countryService )
1819 {
19- this . tradeService = tradeService ;
20- this . assetService = assetService ;
20+ _tradeService = tradeService ;
21+ _countryService = countryService ;
2122 }
2223
2324 [ HttpGet ]
2425 public async Task < IActionResult > GetAll ( )
2526 {
26- return Ok ( await tradeService . GetAllAsync ( ) ) ;
27+ return Ok ( await _tradeService . GetAllAsync ( ) ) ;
2728 }
2829
2930 [ HttpGet ( "{id}" ) ]
3031 public async Task < IActionResult > GetById ( Guid id )
3132 {
3233 if ( id == Guid . Empty ) return BadRequest ( "Id can't be empty" ) ;
3334
34- var item = await tradeService . GetAsync ( id ) ;
35+ var item = await _tradeService . GetAsync ( id ) ;
3536
3637 if ( item == null )
3738 {
@@ -41,42 +42,44 @@ public async Task<IActionResult> GetById(Guid id)
4142 return new ObjectResult ( item ) ;
4243 }
4344
44- [ HttpPost ( "[action]" ) ]
45+ [ HttpGet ( "[action]" ) ]
4546 public async Task < IActionResult > Generate ( )
4647 {
47- var item = await tradeService . GenerateAsync ( ) ;
48+ var item = await _tradeService . GenerateAsync ( ) ;
4849 return CreatedAtAction ( "Generate" , new { id = item . Id } , item ) ;
4950 }
5051
5152 [ HttpPost ]
5253 public async Task < IActionResult > Post ( AssetTradeViewModel trade )
5354 {
54- var item = await tradeService . SaveAsync ( trade ) ;
55+ var item = await _tradeService . SaveAsync ( trade ) ;
5556 return CreatedAtAction ( "Post" , new { id = item . Id } , item ) ;
5657 }
5758
5859 [ HttpPut ( "{id}" ) ]
5960 public async Task < IActionResult > Update ( Guid id , [ FromBody ] AssetTradeViewModel trade )
6061 {
61- if ( await tradeService . GetAsync ( id ) == null ) return NotFound ( id ) ;
62+ if ( await _tradeService . GetAsync ( id ) == null ) return NotFound ( id ) ;
6263
63- var item = await tradeService . UpdateAsync ( id , trade ) ;
64+ var item = await _tradeService . UpdateAsync ( id , trade ) ;
6465 return new OkObjectResult ( item ) ;
6566 }
6667
6768 [ HttpDelete ( "{id}" ) ]
6869 public async Task < IActionResult > Delete ( Guid id )
6970 {
70- if ( await tradeService . GetAsync ( id ) == null ) return NotFound ( id ) ;
71+ if ( await _tradeService . GetAsync ( id ) == null ) return NotFound ( id ) ;
7172
72- var item = await tradeService . DeleteAsync ( id ) ;
73+ var item = await _tradeService . DeleteAsync ( id ) ;
7374 return new OkObjectResult ( item ) ;
7475 }
7576
76- [ HttpGet ( "Assets" ) ]
77- public async Task < IActionResult > Assets ( )
77+ [ Authorize ]
78+ [ HttpGet ( "Countries" ) ]
79+ public IActionResult Countries ( )
7880 {
79- return Ok ( await assetService . GetAllAsync ( ) ) ;
81+ var items = _countryService . GetCountries ( ) ;
82+ return new OkObjectResult ( items ) ;
8083 }
8184 }
8285}
0 commit comments