refactoring
This commit is contained in:
@@ -61,7 +61,7 @@ public class AccountController : BaseApiController
|
||||
[HttpGet("~/api/accounts/{id}/motions")]
|
||||
public object AccountMotionsGet(string id, [FromQuery] AccountMotionsGetModel request)
|
||||
{
|
||||
var exec = _accountService.GetAccountMotion(UserId, id!.AsGuid(), request.From.StartOfDay(), request.To.EndOfDay());
|
||||
var exec = _accountService.GetMotions(UserId, id!.AsGuid(), request.From.StartOfDay(), request.To.EndOfDay());
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
@@ -78,17 +78,17 @@ public class AccountController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpPost("~/api/accounts/{id}/motions")]
|
||||
public object AccountsMotionsPost(string id, AccountMotionRequest accountMotion)
|
||||
public object AccountsMotionsPost(string id, MotionRequest motion)
|
||||
{
|
||||
var exec = _accountService.AccountMotionAdd(UserId, id.AsGuid(), accountMotion.FromModel());
|
||||
var exec = _accountService.MotionAdd(UserId, id.AsGuid(), motion.FromModel());
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case AccountMotionAddResult.account_not_found:
|
||||
case MotionAddResult.account_not_found:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
case AccountMotionAddResult.failure:
|
||||
case MotionAddResult.failure:
|
||||
return ProblemBadRequest("Adding motion failed.");
|
||||
case AccountMotionAddResult.success:
|
||||
case MotionAddResult.success:
|
||||
return exec.Result!.ToModel();
|
||||
|
||||
default:
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
namespace MyOffice.Web.Controllers;
|
||||
|
||||
using Data.Repositories.Account;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Models.Motion;
|
||||
using MyOffice.Core.Extensions;
|
||||
using MyOffice.Core;
|
||||
using MyOffice.Data.Repositories.Motion;
|
||||
using MyOffice.Services.Account;
|
||||
using MyOffice.Services.Account.Domain;
|
||||
using Services.Motion;
|
||||
using MyOffice.Data.Models.Motions;
|
||||
using Services.Motion.Domain;
|
||||
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class SettingsMotionController : BaseApiController
|
||||
{
|
||||
private MotionService _motionService;
|
||||
|
||||
public SettingsMotionController(
|
||||
MotionService motionService
|
||||
)
|
||||
{
|
||||
_motionService = motionService;
|
||||
}
|
||||
|
||||
[HttpGet("~/api/settings/motion-categories")]
|
||||
public object MotionCategories()
|
||||
{
|
||||
var list = _motionService.GetAllCategories(UserId);
|
||||
|
||||
return list
|
||||
.Select(x => x.ToModel())
|
||||
.OrderByDescending(x => x.SortOrder)
|
||||
.ThenBy(x => x.Name);
|
||||
}
|
||||
|
||||
[HttpPost("~/api/settings/motion-categories")]
|
||||
public object MotionCategoriesAdd(MotionCategoryViewModel request)
|
||||
{
|
||||
var exec = _motionService.CategoryAdd(UserId, new MotionCategory { Name = request.Name! });
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!.ToModel();
|
||||
|
||||
case GeneralExecStatus.failure:
|
||||
case GeneralExecStatus.not_found:
|
||||
return ProblemBadRequest("Adding motion category failed.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("~/api/settings/motion-categories/{id}")]
|
||||
public object MotionCategoriesEdit(string id, MotionCategoryViewModel request)
|
||||
{
|
||||
var exec = _motionService.CategoryUpdate(UserId, id.AsGuid(), new MotionCategory { Name = request.Name! });
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!.ToModel();
|
||||
|
||||
case GeneralExecStatus.failure:
|
||||
case GeneralExecStatus.not_found:
|
||||
return ProblemBadRequest("Update account category failed.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete("~/api/settings/motion-categories/{id}")]
|
||||
public object MotionCategoriesDelete(string id)
|
||||
{
|
||||
var exec = _motionService.CategoryRemove(UserId, id.AsGuid());
|
||||
switch (exec.Status)
|
||||
{
|
||||
case MotionCategoryRemoveResult.success:
|
||||
return exec.Result!;
|
||||
|
||||
case MotionCategoryRemoveResult.failure:
|
||||
return ProblemBadRequest("Remove motion category failed.");
|
||||
case MotionCategoryRemoveResult.not_found:
|
||||
return ProblemBadRequest("Account motion not found.");
|
||||
case MotionCategoryRemoveResult.accounts_exists:
|
||||
return ProblemBadRequest("Account motion have accounts.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("~/api/settings/motions")]
|
||||
public object Motions(string? category)
|
||||
{
|
||||
var list = category.IsMissing()
|
||||
? _motionService.GetAll(UserId)
|
||||
: _motionService.GetByCategory(UserId, category!.AsGuid());
|
||||
|
||||
return list
|
||||
.OrderBy(x => x.MotionGlobal.Name)
|
||||
.Select(x => x.ToModel());
|
||||
}
|
||||
|
||||
[HttpPut("~/api/settings/motions/{id}")]
|
||||
public object Motions(string id, MotionEditModel request)
|
||||
{
|
||||
var exec = _motionService.Update(UserId, id.AsGuid(), request.Category.AsGuid());
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
return ProblemBadRequest("Motion not found.");
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadRequest("Motion update failed.");
|
||||
case GeneralExecStatus.success:
|
||||
return Ok(exec.Result!.ToModel());
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public class SettingsAccountController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpPost("~/api/settings/account-categories")]
|
||||
public object AccountCategoriesAdd(MotionCategoryViewModel request)
|
||||
public object AccountCategoriesAdd(AccountCategoryViewModel request)
|
||||
{
|
||||
var exec = _accountService.CategoryAdd(UserId, new AccountCategory { Name = request.Name! });
|
||||
switch (exec.Status)
|
||||
@@ -72,7 +72,7 @@ public class SettingsAccountController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpPut("~/api/settings/account-categories/{id}")]
|
||||
public object AccountCategoriesEdit(string id, MotionCategoryViewModel request)
|
||||
public object AccountCategoriesEdit(string id, AccountCategoryViewModel request)
|
||||
{
|
||||
var exec = _accountService.CategoryUpdate(UserId, id.AsGuid(), new AccountCategory { Name = request.Name! });
|
||||
switch (exec.Status)
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
namespace MyOffice.Web.Controllers;
|
||||
|
||||
using Data.Models.Items;
|
||||
using Data.Repositories.Account;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Models.Item;
|
||||
using MyOffice.Core.Extensions;
|
||||
using MyOffice.Core;
|
||||
using MyOffice.Services.Account;
|
||||
using MyOffice.Services.Account.Domain;
|
||||
using Services.Item;
|
||||
using Services.Item.Domain;
|
||||
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class SettingsItemController : BaseApiController
|
||||
{
|
||||
private ItemService _itemService;
|
||||
|
||||
public SettingsItemController(
|
||||
ItemService itemService
|
||||
)
|
||||
{
|
||||
_itemService = itemService;
|
||||
}
|
||||
|
||||
[HttpGet("~/api/settings/item-categories")]
|
||||
public object ItemsCategories()
|
||||
{
|
||||
var list = _itemService.GetAllCategories(UserId);
|
||||
|
||||
return list
|
||||
.Select(x => x.ToModel())
|
||||
.OrderByDescending(x => x.SortOrder)
|
||||
.ThenBy(x => x.Name);
|
||||
}
|
||||
|
||||
[HttpPost("~/api/settings/item-categories")]
|
||||
public object ItemCategoriesAdd(ItemCategoryViewModel request)
|
||||
{
|
||||
var exec = _itemService.CategoryAdd(UserId, new ItemCategory { Name = request.Name! });
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!.ToModel();
|
||||
|
||||
case GeneralExecStatus.failure:
|
||||
case GeneralExecStatus.not_found:
|
||||
return ProblemBadRequest("Adding item category failed.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("~/api/settings/item-categories/{id}")]
|
||||
public object ItemCategoriesEdit(string id, ItemCategoryViewModel request)
|
||||
{
|
||||
var exec = _itemService.CategoryUpdate(UserId, id.AsGuid(), new ItemCategory { Name = request.Name! });
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!.ToModel();
|
||||
|
||||
case GeneralExecStatus.failure:
|
||||
case GeneralExecStatus.not_found:
|
||||
return ProblemBadRequest("Update item category failed.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete("~/api/settings/item-categories/{id}")]
|
||||
public object ItemCategoriesDelete(string id)
|
||||
{
|
||||
var exec = _itemService.CategoryRemove(UserId, id.AsGuid());
|
||||
switch (exec.Status)
|
||||
{
|
||||
case ItemCategoryRemoveResult.success:
|
||||
return exec.Result!;
|
||||
|
||||
case ItemCategoryRemoveResult.failure:
|
||||
return ProblemBadRequest("Remove item category failed.");
|
||||
case ItemCategoryRemoveResult.not_found:
|
||||
return ProblemBadRequest("Account item not found.");
|
||||
case ItemCategoryRemoveResult.accounts_exists:
|
||||
return ProblemBadRequest("Account motion have accounts.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("~/api/settings/items")]
|
||||
public object Items(string? category)
|
||||
{
|
||||
var list = category.IsMissing()
|
||||
? _itemService.GetAll(UserId)
|
||||
: _itemService.GetByCategory(UserId, category!.AsGuid());
|
||||
|
||||
return list
|
||||
.OrderBy(x => x.ItemGlobal.Name)
|
||||
.Select(x => x.ToModel());
|
||||
}
|
||||
|
||||
[HttpPut("~/api/settings/items/{id}")]
|
||||
public object Items(string id, ItemEditModel request)
|
||||
{
|
||||
var exec = _itemService.Update(UserId, id.AsGuid(), request.Category.AsGuid());
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
return ProblemBadRequest("Item not found.");
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadRequest("Item update failed.");
|
||||
case GeneralExecStatus.success:
|
||||
return Ok(exec.Result!.ToModel());
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user