Added style guidance and performed enforcement
This commit is contained in:
@ -118,14 +118,14 @@ namespace IO.Swagger.Controllers
|
||||
[ProducesResponseType(typeof(IEnumerable<string>), 400)]
|
||||
public virtual async Task<IActionResult> CreateCurrency([FromBody] CurrencyCreateBody body)
|
||||
{
|
||||
var userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
string 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)));
|
||||
|
||||
var createdCurr = await repo.CreateCurrency(body, userId);
|
||||
bool createdCurr = await repo.CreateCurrency(body, userId);
|
||||
return createdCurr ? StatusCode(201) : StatusCode(422);
|
||||
}
|
||||
|
||||
@ -145,13 +145,13 @@ namespace IO.Swagger.Controllers
|
||||
[ProducesResponseType(typeof(IEnumerable<string>), 400)]
|
||||
public virtual async Task<IActionResult> MintCurrency([FromBody] CurrencyMintBody body)
|
||||
{
|
||||
var userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
string 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)));
|
||||
|
||||
var minted = await repo.MintCurrency(body, userId);
|
||||
bool minted = await repo.MintCurrency(body, userId);
|
||||
return minted ? Ok() : StatusCode(409);
|
||||
}
|
||||
|
||||
@ -168,18 +168,19 @@ namespace IO.Swagger.Controllers
|
||||
[ProducesResponseType(typeof(IEnumerable<CurrencyInfoDto>), 200)]
|
||||
public virtual async Task<IActionResult> GetAllCurrencies()
|
||||
{
|
||||
var userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
string userIdString = HttpContext.User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
if (!int.TryParse(userIdString, out int userId))
|
||||
return Unauthorized();
|
||||
|
||||
var rawCurrencies = await repo.GetAllCurrencies();
|
||||
var res = new List<CurrencyInfoDto>();
|
||||
foreach (var raw in rawCurrencies)
|
||||
List<Models.db.Currency> rawCurrencies = await repo.GetAllCurrencies();
|
||||
List<CurrencyInfoDto> res = new();
|
||||
foreach (Models.db.Currency raw in rawCurrencies)
|
||||
{
|
||||
var c = mapper.Map<CurrencyInfoDto>(raw);
|
||||
CurrencyInfoDto c = mapper.Map<CurrencyInfoDto>(raw);
|
||||
c.IsOwner = raw.UserId == userId;
|
||||
res.Add(c);
|
||||
}
|
||||
|
||||
return Ok(res);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user