mirror of
https://github.com/QuotifyTeam/QuotifyBE.git
synced 2025-12-16 16:00:06 +01:00
edycja kategorii
This commit is contained in:
@@ -155,6 +155,29 @@ public class CategoryController : ControllerBase
|
|||||||
return Ok(new { Status = "ok" });
|
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
|
// TODO: Update category
|
||||||
// PATCH /api/v1/categories/1
|
// PATCH /api/v1/categories/1
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user