This commit is contained in:
2023-08-10 21:57:55 +03:00
parent 25184e9edc
commit a09fc7ece3
19 changed files with 230 additions and 68 deletions
@@ -101,11 +101,13 @@ public class SettingsItemController : BaseApiController
}
[HttpGet("~/api/settings/items")]
public ObjectResult Items([AsGuid] string? category)
public ObjectResult Items([AsGuid] string category)
{
var list = category.IsMissing()
? _itemService.GetAll(UserId)
: _itemService.GetByCategory(UserId, category!.AsGuid());
var categoryId = category.AsGuid();
var list = categoryId != UserId
? _itemService.GetByCategory(UserId, categoryId)
: _itemService.GetByUncategorized(UserId);
return Ok(_mapper.Map<List<ItemViewModel>>(list.OrderBy(x => x.Name)));
}
@@ -128,4 +130,23 @@ public class SettingsItemController : BaseApiController
throw new NotSupportedException(exec.Status.ToString());
}
}
[HttpPost("~/api/settings/items")]
public ObjectResult Items(ItemChangeCategoryModel request)
{
var exec = _itemService.UpdateItemsCategory(UserId, request.category.AsGuid(), request.Items.Select(x => x.AsGuid()).ToList());
switch (exec)
{
case GeneralExecStatus.not_found:
return ProblemBadResponse("Category not found.");
case GeneralExecStatus.failure:
return ProblemBadResponse("Update failed.");
case GeneralExecStatus.success:
return Ok(new {});
default:
throw new NotSupportedException(exec.ToString());
}
}
}