Feature/Auth: implement user authentication #3

Merged
homeburger merged 48 commits from feature/auth into main 2026-03-22 20:52:22 -05:00
2 changed files with 11 additions and 15 deletions
Showing only changes of commit da6ffa8167 - Show all commits

View File

@@ -56,18 +56,7 @@ public class ItemsController : ControllerBase {
[HttpPut("{id}")]
public async Task<ActionResult<Item>> updateItem(int id, ItemDto item) {
Item? oldItem = await service_.Get(id);
if(oldItem == null) return NotFound();
Item updatedItem = new Item {
Id = id,
Name = item.Name,
Description = item.Description,
CreatedAt = oldItem.CreatedAt,
LastEditedAt = DateTime.UtcNow
};
var updated = await service_.Update(updatedItem);
var updated = await service_.Update(id, item);
if (updated == null) return NotFound();

View File

@@ -31,10 +31,17 @@ public class ItemService {
return item;
}
public async Task<Item> Update(Item item) {
db_.Items.Update(item);
public async Task<Item?> Update(int id, ItemDto item) {
Item? oldItem = await db_.Items.FindAsync(id);
if(oldItem == null) return oldItem;
oldItem.Name = item.Name;
oldItem.Description = item.Description;
oldItem.LastEditedAt = DateTime.UtcNow;
await db_.SaveChangesAsync();
return item;
return oldItem;
}
public async Task<bool> Delete(int id) {