Skip to content

Commit bb5de9a

Browse files
committed
Code refactored and unit-tests updated
1 parent 0f08536 commit bb5de9a

12 files changed

Lines changed: 140 additions & 760 deletions

File tree

MockMe.API/Controllers/MockController.cs

Lines changed: 0 additions & 67 deletions
This file was deleted.
Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.AspNetCore.Mvc;
1+
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Mvc;
23
using MockMe.API.Services;
34
using MockMe.API.ViewModels;
45
using 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
}

MockMe.API/Services/AssetService.cs

Lines changed: 0 additions & 41 deletions
This file was deleted.

MockMe.API/Services/MockService.cs

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)