This commit is contained in:
2023-12-16 21:18:01 +02:00
parent 775146ee86
commit 2feaf50802
46 changed files with 641 additions and 429 deletions
@@ -1,7 +1,6 @@
namespace MyOffice.Web.Controllers;
using AutoMapper;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Core;
@@ -11,10 +10,10 @@ using Services.Account;
using Services.Account.Domain;
using Infrastructure.Attributes;
using Services.Identity;
using Microsoft.AspNetCore.Mvc;
[Authorize]
[ApiController]
[Route("api/[controller]")]
[DefaultFromBody]
public class SettingsAccountCategoryController : BaseApiController
{
private readonly ILogger<SettingsAccountController> _logger;
@@ -35,16 +34,14 @@ public class SettingsAccountCategoryController : BaseApiController
_contextProvider = contextProvider;
}
[HttpGet("~/api/settings/account-categories")]
public object AccountCategories()
public ObjectResult AccountCategories()
{
var list = _accountService.GetAllCategories(UserId);
return OkResponse(_mapper.Map<List<AccountCategoryViewModel>>(list).OrderBy(x => x.Name));
}
[HttpGet("~/api/settings/account-categories/{id}")]
public object AccountCategory([AsGuid] string id)
public ObjectResult AccountCategory([AsGuid] string id)
{
var exec = _accountService.GetCategory(UserId, id.AsGuid());
@@ -55,21 +52,20 @@ public class SettingsAccountCategoryController : BaseApiController
return ProblemBadResponse("Account category not found.");
case GeneralExecStatus.success:
return _mapper.Map<AccountCategoryViewModel>(exec.Result!);
return OkResponse(_mapper.Map<AccountCategoryViewModel>(exec.Result!));
default:
throw new NotSupportedException(exec.Status.ToString());
}
}
[HttpPost("~/api/settings/account-categories")]
public object AccountCategoriesAdd(AccountCategoryViewModel request)
public ObjectResult AccountCategoriesAdd(AccountCategoryViewModel request)
{
var exec = _accountService.CategoryAdd(UserId, new AccountCategoryDto { Name = request.Name! });
switch (exec.Status)
{
case GeneralExecStatus.success:
return exec.Result!;
return OkResponse(_mapper.Map<AccountCategoryViewModel>(exec.Result!));
case GeneralExecStatus.failure:
case GeneralExecStatus.not_found:
@@ -80,14 +76,13 @@ public class SettingsAccountCategoryController : BaseApiController
}
}
[HttpPut("~/api/settings/account-categories/{id}")]
public object AccountCategoriesEdit([AsGuid] string id, AccountCategoryViewModel request)
public ObjectResult AccountCategoriesUpdate([AsGuid] string id, AccountCategoryViewModel request)
{
var exec = _accountService.CategoryUpdate(UserId, id.AsGuid(), new AccountCategoryDto { Name = request.Name! });
switch (exec.Status)
{
case GeneralExecStatus.success:
return exec.Result!;
return OkResponse(_mapper.Map<AccountCategoryViewModel>(exec.Result!));
case GeneralExecStatus.failure:
case GeneralExecStatus.not_found:
@@ -98,14 +93,13 @@ public class SettingsAccountCategoryController : BaseApiController
}
}
[HttpDelete("~/api/settings/account-categories/{id}")]
public object AccountCategoriesDelete([AsGuid] string id)
public ObjectResult AccountCategoriesDelete([AsGuid] string id)
{
var exec = _accountService.CategoryRemove(UserId, id.AsGuid());
switch (exec.Status)
{
case AccountCategoryRemoveResult.success:
return exec.Result!;
return OkResponse(_mapper.Map<AccountCategoryViewModel>(exec.Result!));
case AccountCategoryRemoveResult.failure:
return ProblemBadResponse("Remove account category failed.");