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:
OlgunR
2026-01-16 13:55:43 +01:00
parent 904e6e20f0
commit 1fd776bc29

View File

@@ -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)
{