edycja kategorii

This commit is contained in:
2025-07-22 11:45:48 +02:00
parent 468d502827
commit 3a82e4291e

View File

@@ -155,6 +155,29 @@ public class CategoryController : ControllerBase
return Ok(new { Status = "ok" });
}
[HttpPatch("{id}")]
[Authorize]
[EnableCors]
[ProducesResponseType(typeof(QuoteShortDTO), 200)]
[ProducesResponseType(typeof(ErrorDTO), 400)]
[ProducesResponseType(typeof(ErrorDTO), 404)]
public async Task<IActionResult> EditCategory(int id, [FromBody] CategoryShortDTO updatedCategory)
{
Category? cat= await _db.Categories.FirstOrDefaultAsync(c => c.Id == id);
if (cat == null)
return NotFound(new { status = "error", error_msg = "Category not found" });
if (string.IsNullOrWhiteSpace(updatedCategory.Name) || string.IsNullOrWhiteSpace(updatedCategory.Description))
return BadRequest(new ErrorDTO { Status = "error", Error_msg = "Text and author are required." });
cat.Name=updatedCategory.Name;
cat.Description=updatedCategory.Description;
await _db.SaveChangesAsync();
return Ok(cat.ToCategoryShortDTO());
}
// TODO: Update category
// PATCH /api/v1/categories/1