Currency creation and minting with basis of transactions
This commit is contained in:
@ -18,6 +18,10 @@ using IO.Swagger.Attributes;
|
||||
using IO.Swagger.Security;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using IO.Swagger.Models.dto;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using IO.Swagger.Repositories;
|
||||
|
||||
namespace IO.Swagger.Controllers
|
||||
{
|
||||
@ -26,7 +30,14 @@ namespace IO.Swagger.Controllers
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
public class CurrencyApiController : ControllerBase
|
||||
{
|
||||
{
|
||||
private readonly ICurrencyRepository repo;
|
||||
|
||||
public CurrencyApiController(ICurrencyRepository repo)
|
||||
{
|
||||
this.repo = repo ?? throw new ArgumentNullException(nameof(repo));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a digital asset to the user's collection
|
||||
/// </summary>
|
||||
@ -86,23 +97,23 @@ namespace IO.Swagger.Controllers
|
||||
/// <response code="201">Currency type created successfully</response>
|
||||
/// <response code="400">Bad Request</response>
|
||||
/// <response code="401">Unauthorized</response>
|
||||
/// <response code="422">Unprocessable Content</response>
|
||||
[HttpPost]
|
||||
[Route("/v1/api/currency/create")]
|
||||
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
|
||||
[ValidateModelState]
|
||||
[SwaggerOperation("CreateCurrency")]
|
||||
public virtual IActionResult CreateCurrency([FromBody]CurrencyCreateBody body)
|
||||
{
|
||||
//TODO: Uncomment the next line to return response 201 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
|
||||
// return StatusCode(201);
|
||||
public virtual async Task<IActionResult> CreateCurrency([FromBody]CurrencyCreateBody body)
|
||||
{
|
||||
var userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
if (!int.TryParse(userIdString, out int userId))
|
||||
return Unauthorized();
|
||||
|
||||
//TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
|
||||
// return StatusCode(400);
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState.Values.SelectMany(v => v.Errors.Select(e => e.ErrorMessage)));
|
||||
|
||||
//TODO: Uncomment the next line to return response 401 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
|
||||
// return StatusCode(401);
|
||||
|
||||
throw new NotImplementedException();
|
||||
var createdCurr = await repo.CreateCurrency(body, userId);
|
||||
return createdCurr ? StatusCode(201) : StatusCode(422);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -112,23 +123,22 @@ namespace IO.Swagger.Controllers
|
||||
/// <response code="200">Successful minting</response>
|
||||
/// <response code="400">Bad Request</response>
|
||||
/// <response code="401">Unauthorized</response>
|
||||
/// <response code="409">Conflict - User is not owner or currency does not exist</response>
|
||||
[HttpPost]
|
||||
[Route("/v1/api/currency/mint")]
|
||||
[Authorize(AuthenticationSchemes = BearerAuthenticationHandler.SchemeName)]
|
||||
[ValidateModelState]
|
||||
[SwaggerOperation("MintCurrency")]
|
||||
public virtual IActionResult MintCurrency([FromBody]CurrencyMintBody body)
|
||||
{
|
||||
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
|
||||
// return StatusCode(200);
|
||||
public virtual async Task<IActionResult> MintCurrency([FromBody]CurrencyMintBody body)
|
||||
{
|
||||
var userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
if (!int.TryParse(userIdString, out int userId))
|
||||
return Unauthorized();
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(ModelState.Values.SelectMany(v => v.Errors.Select(e => e.ErrorMessage)));
|
||||
|
||||
//TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
|
||||
// return StatusCode(400);
|
||||
|
||||
//TODO: Uncomment the next line to return response 401 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
|
||||
// return StatusCode(401);
|
||||
|
||||
throw new NotImplementedException();
|
||||
var minted = await repo.MintCurrency(body, userId);
|
||||
return minted ? Ok() : StatusCode(409);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user