fix
This commit is contained in:
@@ -3,7 +3,6 @@ namespace MyOffice.Web.Controllers;
|
||||
using AutoMapper;
|
||||
using Core;
|
||||
using Core.Extensions;
|
||||
using Data.Models.Accounts;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -38,15 +37,15 @@ public class AccountController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpGet("~/api/accounts")]
|
||||
public List<AccountDetailedViewModel> AccountsGet(string category)
|
||||
public ObjectResult AccountsGet(string category)
|
||||
{
|
||||
var list = _accountService.GetByCategoryDetailed(UserId, category!.AsGuid());
|
||||
|
||||
return _mapper.Map<List<AccountDetailedViewModel>>(list.OrderBy(x => x.Account.Name).ToList());
|
||||
return OkResponse(_mapper.Map<List<AccountDetailedViewModel>>(list.OrderBy(x => x.Account.Name).ToList()));
|
||||
}
|
||||
|
||||
[HttpGet("~/api/accounts/{id}")]
|
||||
public object AccountGet(string id)
|
||||
public ObjectResult AccountGet(string id)
|
||||
{
|
||||
var exec = _accountService.GetByIdDetailed(UserId, id!.AsGuid());
|
||||
|
||||
@@ -54,10 +53,10 @@ public class AccountController : BaseApiController
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
return ProblemBadResponse("Account not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
return _mapper.Map<AccountDetailedViewModel>(exec.Result);
|
||||
return OkResponse(_mapper.Map<AccountDetailedViewModel>(exec.Result));
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -65,7 +64,7 @@ public class AccountController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpGet("~/api/accounts/{id}/motions")]
|
||||
public object MotionsGet(string id, [FromQuery] MotionsGetModel request)
|
||||
public ObjectResult MotionsGet(string id, [FromQuery] MotionsGetRequest request)
|
||||
{
|
||||
var exec = _accountService.GetMotions(UserId, id!.AsGuid(), request.From.StartOfDay(), request.To.EndOfDay());
|
||||
|
||||
@@ -73,11 +72,10 @@ public class AccountController : BaseApiController
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
return ProblemBadResponse("Account not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
//return exec.Result!.Select(x => x.ToModel());
|
||||
return _mapper.Map<MotionViewModel[]>(exec.Result!);
|
||||
return OkResponse(_mapper.Map<List<MotionViewModel>>(exec.Result!));
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -92,30 +90,30 @@ public class AccountController : BaseApiController
|
||||
switch (exec.Status)
|
||||
{
|
||||
case MotionAddStatus.account_not_found:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
return ProblemBadResponse("Account not found.");
|
||||
case MotionAddStatus.failure:
|
||||
return ProblemBadRequest("Adding motion failed.");
|
||||
return ProblemBadResponse("Adding motion failed.");
|
||||
case MotionAddStatus.success:
|
||||
return _mapper.Map<MotionViewModel[]>(exec.Result!);
|
||||
|
||||
default:
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("~/api/accounts/{id}/motions/{motionId}")]
|
||||
public object MotionsPut(string id, string motionId, MotionRequest motion)
|
||||
public ObjectResult MotionsPut(string id, string motionId, MotionRequest motion)
|
||||
{
|
||||
var exec = _accountService.MotionUpdate(UserId, id.AsGuid(), motionId.AsGuid(), _mapper.Map<MotionAddUpdate>(motion));
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case MotionUpdateStatus.not_found:
|
||||
return ProblemBadRequest("Motion not found.");
|
||||
return ProblemBadResponse("Motion not found.");
|
||||
case MotionUpdateStatus.failure:
|
||||
return ProblemBadRequest("Updating motion failed.");
|
||||
return ProblemBadResponse("Updating motion failed.");
|
||||
case MotionUpdateStatus.success:
|
||||
return exec.Result!.ToModel();
|
||||
return OkResponse(_mapper.Map<List<MotionViewModel>>(exec.Result!));
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -123,18 +121,18 @@ public class AccountController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpDelete("~/api/accounts/{id}/motions/{motionId}")]
|
||||
public object MotionsDelete(string id, string motionId)
|
||||
public ObjectResult MotionsDelete(string id, string motionId)
|
||||
{
|
||||
var exec = _accountService.MotionRemove(UserId, id.AsGuid(), motionId.AsGuid());
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case MotionDeleteStatus.not_found:
|
||||
return ProblemBadRequest("Motion not found.");
|
||||
return ProblemBadResponse("Motion not found.");
|
||||
case MotionDeleteStatus.failure:
|
||||
return ProblemBadRequest("Deliting motion failed.");
|
||||
return ProblemBadResponse("Deliting motion failed.");
|
||||
case MotionDeleteStatus.success:
|
||||
return exec.Result!.ToModel();
|
||||
return OkResponse(_mapper.Map<MotionViewModel>(exec.Result!));
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -142,16 +140,18 @@ public class AccountController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpGet("~/api/items")]
|
||||
public object FindItems(string term)
|
||||
public ObjectResult FindItems(string term)
|
||||
{
|
||||
var items = _itemService
|
||||
.FindItems(UserId, term)
|
||||
.Select(x => x.ToModel())
|
||||
.ToList();
|
||||
var itemsDto = _itemService.FindItems(UserId, term);
|
||||
|
||||
var items = _mapper.Map<List<ItemViewModel>>(itemsDto);
|
||||
|
||||
if (term.StartsWith("+") && term.Length > 1)
|
||||
{
|
||||
var accounts = _accountService.FindAccounts(UserId, term.Substring(1));
|
||||
var accounts = _accountService
|
||||
.FindAccounts(UserId, term.Substring(1))
|
||||
.OrderByDescending(x => x.Name);
|
||||
|
||||
foreach (var account in accounts)
|
||||
{
|
||||
var accountName = $"+{account.Name}";
|
||||
@@ -172,8 +172,10 @@ public class AccountController : BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
return items
|
||||
return OkResponse(_mapper
|
||||
.Map<List<ItemViewModel>>(items)
|
||||
.OrderBy(x => x.AccountId)
|
||||
.ThenBy(x => x.Name);
|
||||
.ThenBy(x => x.Name)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user