De CMS-admin toonde het nieuwe Slug-veld nog niet — dat bestond alleen in de API-respons. Voegt een read-only slugweergave onder het titelveld toe met een potlood-icoon om 'm inline te bewerken. Backend: Create/UpdateOfferingRequest accepteren nu een optionele Slug-override. Zonder expliciete waarde blijft het bestaande gedrag (auto-genereren uit titel, regenereren bij titelwijziging). Met een expliciete waarde wordt die genormaliseerd en op uniekheid gecontroleerd; een botsing geeft 409 Conflict (RFC 9457 ProblemDetails, naar het patroon van MasterControlledAvailabilityException). Frontend: de slug wordt alleen meegestuurd als de admin 'm daadwerkelijk bewerkt heeft (dirtyFields.slug), zodat een ongemoeide slug bij een titelwijziging gewoon blijft auto-regenereren. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
94 lines
2.8 KiB
C#
94 lines
2.8 KiB
C#
using System.Security.Claims;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.RateLimiting;
|
|
using SlpModularCms.Modules.Offerings.Models;
|
|
using SlpModularCms.Modules.Offerings.Services;
|
|
|
|
namespace SlpModularCms.Modules.Offerings.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("offerings")]
|
|
[Authorize(Policy = "AdminOnly")]
|
|
public class OfferingsController(IOfferingsService service) : ControllerBase
|
|
{
|
|
[HttpGet]
|
|
[AllowAnonymous]
|
|
[EnableRateLimiting("offerings-public")]
|
|
public async Task<IActionResult> GetOfferings()
|
|
{
|
|
var offerings = await service.GetPublicOfferingsAsync();
|
|
return Ok(offerings);
|
|
}
|
|
|
|
[HttpGet("admin")]
|
|
public async Task<IActionResult> GetAllForAdmin()
|
|
{
|
|
var offerings = await service.GetAllForAdminAsync();
|
|
return Ok(offerings);
|
|
}
|
|
|
|
[HttpPost("admin")]
|
|
public async Task<IActionResult> Create([FromBody] CreateOfferingRequest request)
|
|
{
|
|
try
|
|
{
|
|
var dto = await service.CreateAsync(request, GetCallerId());
|
|
return CreatedAtAction(nameof(GetAllForAdmin), null, dto);
|
|
}
|
|
catch (OfferingSlugConflictException ex)
|
|
{
|
|
return Conflict(new ProblemDetails { Status = StatusCodes.Status409Conflict, Title = ex.Message });
|
|
}
|
|
}
|
|
|
|
[HttpPut("admin/{id:guid}")]
|
|
public async Task<IActionResult> Update(Guid id, [FromBody] UpdateOfferingRequest request)
|
|
{
|
|
try
|
|
{
|
|
var dto = await service.UpdateAsync(id, request, GetCallerId());
|
|
return dto is null ? NotFound() : Ok(dto);
|
|
}
|
|
catch (OfferingSlugConflictException ex)
|
|
{
|
|
return Conflict(new ProblemDetails { Status = StatusCodes.Status409Conflict, Title = ex.Message });
|
|
}
|
|
}
|
|
|
|
[HttpDelete("admin/{id:guid}")]
|
|
public async Task<IActionResult> Delete(Guid id)
|
|
{
|
|
var deleted = await service.DeleteAsync(id, GetCallerId());
|
|
return deleted ? NoContent() : NotFound();
|
|
}
|
|
|
|
[HttpPut("admin/reorder")]
|
|
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();
|
|
}
|
|
|
|
private Guid GetCallerId()
|
|
{
|
|
var claim = User.FindFirstValue(ClaimTypes.NameIdentifier) ?? User.FindFirstValue("sub");
|
|
return Guid.TryParse(claim, out var id) ? id : Guid.Empty;
|
|
}
|
|
}
|