Prevent CatTitle changes in catalog update endpoint
The Update method now checks if CatTitle is being changed and returns a 400 Bad Request if so. It also returns 404 Not Found if the catalog does not exist before attempting an update. This ensures CatTitle remains immutable during updates.
This commit is contained in:
@@ -46,6 +46,16 @@ public class CatalogsController : ControllerBase
|
||||
[HttpPut("{id:int}")]
|
||||
public async Task<ActionResult<CatalogReadDto>> Update(int id, CatalogWriteDto dto, CancellationToken cancellationToken)
|
||||
{
|
||||
var current = await _service.GetByIdAsync(id, cancellationToken);
|
||||
if (current == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
if (!string.Equals(current.CatTitle, dto.CatTitle, StringComparison.Ordinal))
|
||||
{
|
||||
return BadRequest("CatTitle cannot be changed.");
|
||||
}
|
||||
|
||||
var updated = await _service.UpdateAsync(id, dto, cancellationToken);
|
||||
if (updated == null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user