Refactor CurrencyPeggingController routes and method signatures for improved clarity and consistency

This commit is contained in:
2025-11-13 21:04:43 +00:00
parent 6fc709a271
commit b81c628f07

View File

@@ -36,7 +36,7 @@ using Microsoft.EntityFrameworkCore;
namespace Marechai.Server.Controllers; namespace Marechai.Server.Controllers;
[Route("/currency-pegging")] [Route("/currencies/pegging")]
[ApiController] [ApiController]
public class CurrencyPeggingController(MarechaiContext context) : ControllerBase public class CurrencyPeggingController(MarechaiContext context) : ControllerBase
{ {
@@ -61,7 +61,7 @@ public class CurrencyPeggingController(MarechaiContext context) : ControllerBase
}) })
.ToListAsync(); .ToListAsync();
[HttpGet] [HttpGet("{id:int}")]
[AllowAnonymous] [AllowAnonymous]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
@@ -79,17 +79,18 @@ public class CurrencyPeggingController(MarechaiContext context) : ControllerBase
}) })
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
[HttpPost] [HttpPut("{id:int}")]
[Authorize(Roles = "Admin,UberAdmin")] [Authorize(Roles = "Admin,UberAdmin")]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status404NotFound)] [ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status401Unauthorized)]
public async Task<ActionResult> UpdateAsync(CurrencyPeggingDto dto) public async Task<ActionResult> UpdateAsync(int id, [FromBody] CurrencyPeggingDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return Unauthorized(); if(userId is null) return Unauthorized();
CurrencyPegging model = await context.CurrenciesPegging.FindAsync(dto.Id); CurrencyPegging model = await context.CurrenciesPegging.FindAsync(dto.Id);
if(model is null) return NotFound(); if(model is null) return NotFound();
@@ -109,7 +110,7 @@ public class CurrencyPeggingController(MarechaiContext context) : ControllerBase
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status401Unauthorized)]
public async Task<ActionResult<int>> CreateAsync(CurrencyPeggingDto dto) public async Task<ActionResult<int>> CreateAsync([FromBody] CurrencyPeggingDto dto)
{ {
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
@@ -130,7 +131,7 @@ public class CurrencyPeggingController(MarechaiContext context) : ControllerBase
return model.Id; return model.Id;
} }
[HttpDelete] [HttpDelete("{id:int}")]
[Authorize(Roles = "Admin,UberAdmin")] [Authorize(Roles = "Admin,UberAdmin")]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status400BadRequest)]
@@ -141,6 +142,7 @@ public class CurrencyPeggingController(MarechaiContext context) : ControllerBase
string userId = User.FindFirstValue(ClaimTypes.Sid); string userId = User.FindFirstValue(ClaimTypes.Sid);
if(userId is null) return Unauthorized(); if(userId is null) return Unauthorized();
CurrencyPegging item = await context.CurrenciesPegging.FindAsync(id); CurrencyPegging item = await context.CurrenciesPegging.FindAsync(id);
if(item is null) return NotFound(); if(item is null) return NotFound();