fix
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
namespace MyOffice.Web.Controllers;
|
||||
|
||||
using Core;
|
||||
using Core.Extensions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Models.Account;
|
||||
using Models.Motion;
|
||||
using MyOffice.Data.Models.Accounts;
|
||||
using MyOffice.Web.Models.AccountMotion;
|
||||
using Services.Account;
|
||||
@@ -31,29 +34,62 @@ public class AccountController : BaseApiController
|
||||
{
|
||||
var list = _accountService.GetByCategoryDetailed(UserId, category!.AsGuid());
|
||||
|
||||
return list.Select(x => x.ToModel());
|
||||
return list
|
||||
.OrderBy(x => x.Account.Name)
|
||||
.Select(x => x.ToModel());
|
||||
}
|
||||
|
||||
[HttpGet("~/api/accounts/{id}")]
|
||||
public object AccountGet(string id)
|
||||
{
|
||||
var exec = _accountService.GetByIdDetailed(UserId, id!.AsGuid());
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!.ToModel();
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("~/api/accounts/{id}/motions")]
|
||||
public object AccountsMotionsGet(string category)
|
||||
public object AccountMotionsGet(string id, [FromQuery] AccountMotionsGetModel request)
|
||||
{
|
||||
var list = _accountService.GetByCategoryDetailed(UserId, category!.AsGuid());
|
||||
var exec = _accountService.GetAccountMotion(UserId, id!.AsGuid(), request.From.StartOfDay(), request.To.EndOfDay());
|
||||
|
||||
return list.Select(x => x.ToModel());
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!.Select(x => x.ToModel());
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("~/api/accounts/{id}/motions")]
|
||||
public object AccountsMotionsPost(string id, AccountMotionRequest accountMotion)
|
||||
{
|
||||
var exec = _accountService.AccountMotionAdd(UserId, id.AsGuid(), accountMotion.FromModel());
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case AccountMotionAddResult.account_not_found:
|
||||
return ProblemBadRequest("Account failed.");
|
||||
return ProblemBadRequest("Account not found.");
|
||||
case AccountMotionAddResult.failure:
|
||||
return ProblemBadRequest("Adding motion failed.");
|
||||
case AccountMotionAddResult.success:
|
||||
return exec.Result!;
|
||||
return exec.Result!.ToModel();
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
|
||||
Reference in New Issue
Block a user