Aanbod: RESTful routes zonder /admin, één OfferingDto en herordenen via PUT /offerings/order
Admin en bezoeker gebruiken dezelfde resource; alleen GET is anoniem, de rest vereist AdminOnly. OfferingAdminDto vervalt (displayOrder zit nu in OfferingDto), move-up/move-down zijn vervangen door de order-route die een onbekende of onvolledige lijst met 400 afwijst. De admin-frontend en alle tests zijn mee aangepast. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,11 @@ using SlpModularCms.Modules.Offerings.Services;
|
||||
|
||||
namespace SlpModularCms.Modules.Offerings.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// The offerings resource. Reading is public; every write requires the AdminOnly policy.
|
||||
/// There is deliberately no separate "admin" route: an administrator uses the same resource
|
||||
/// and verbs, and access is decided by authorization alone.
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("offerings")]
|
||||
[Authorize(Policy = "AdminOnly")]
|
||||
@@ -18,24 +23,17 @@ public class OfferingsController(IOfferingsService service) : ControllerBase
|
||||
[EnableRateLimiting("offerings-public")]
|
||||
public async Task<IActionResult> GetOfferings()
|
||||
{
|
||||
var offerings = await service.GetPublicOfferingsAsync();
|
||||
var offerings = await service.GetOfferingsAsync();
|
||||
return Ok(offerings);
|
||||
}
|
||||
|
||||
[HttpGet("admin")]
|
||||
public async Task<IActionResult> GetAllForAdmin()
|
||||
{
|
||||
var offerings = await service.GetAllForAdminAsync();
|
||||
return Ok(offerings);
|
||||
}
|
||||
|
||||
[HttpPost("admin")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Create([FromBody] CreateOfferingRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
var dto = await service.CreateAsync(request, GetCallerId());
|
||||
return CreatedAtAction(nameof(GetAllForAdmin), null, dto);
|
||||
return Created($"/api/v1/offerings/{dto.Id}", dto);
|
||||
}
|
||||
catch (OfferingSlugConflictException ex)
|
||||
{
|
||||
@@ -43,7 +41,7 @@ public class OfferingsController(IOfferingsService service) : ControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("admin/{id:guid}")]
|
||||
[HttpPut("{id:guid}")]
|
||||
public async Task<IActionResult> Update(Guid id, [FromBody] UpdateOfferingRequest request)
|
||||
{
|
||||
try
|
||||
@@ -57,32 +55,29 @@ public class OfferingsController(IOfferingsService service) : ControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete("admin/{id:guid}")]
|
||||
[HttpDelete("{id:guid}")]
|
||||
public async Task<IActionResult> Delete(Guid id)
|
||||
{
|
||||
var deleted = await service.DeleteAsync(id, GetCallerId());
|
||||
return deleted ? NoContent() : NotFound();
|
||||
}
|
||||
|
||||
[HttpPut("admin/reorder")]
|
||||
/// <summary>
|
||||
/// Sets the display order of the whole collection. The list must contain every existing
|
||||
/// offering exactly once.
|
||||
/// </summary>
|
||||
[HttpPut("order")]
|
||||
public async Task<IActionResult> Reorder([FromBody] ReorderOfferingsRequest request)
|
||||
{
|
||||
await service.ReorderAsync(request.OrderedIds, GetCallerId());
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpPost("admin/{id:guid}/move-up")]
|
||||
public async Task<IActionResult> MoveUp(Guid id)
|
||||
{
|
||||
await service.MoveUpAsync(id, GetCallerId());
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpPost("admin/{id:guid}/move-down")]
|
||||
public async Task<IActionResult> MoveDown(Guid id)
|
||||
{
|
||||
await service.MoveDownAsync(id, GetCallerId());
|
||||
return NoContent();
|
||||
try
|
||||
{
|
||||
await service.ReorderAsync(request.OrderedIds, GetCallerId());
|
||||
return NoContent();
|
||||
}
|
||||
catch (OfferingOrderInvalidException ex)
|
||||
{
|
||||
return BadRequest(new ProblemDetails { Status = StatusCodes.Status400BadRequest, Title = ex.Message });
|
||||
}
|
||||
}
|
||||
|
||||
private Guid GetCallerId()
|
||||
|
||||
Reference in New Issue
Block a user