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)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using System.Security.Authentication;
|
||||
using Core.Extensions;
|
||||
using IdentityModel;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MyOffice.Web.Models;
|
||||
using static IdentityServer4.Models.IdentityResources;
|
||||
|
||||
public class BaseApiController : ControllerBase
|
||||
@@ -19,8 +20,18 @@ public class BaseApiController : ControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
public ObjectResult ProblemBadRequest(string? detail = null)
|
||||
public ObjectResult ProblemBadResponse(string? detail = null)
|
||||
{
|
||||
return Problem(detail, statusCode: StatusCodes.Status400BadRequest);
|
||||
}
|
||||
|
||||
public ObjectResult OkResponse(IResponseModel response)
|
||||
{
|
||||
return Ok(response);
|
||||
}
|
||||
|
||||
public ObjectResult OkResponse<T>(IEnumerable<T> response) where T : IResponseModel
|
||||
{
|
||||
return Ok(response);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,13 @@
|
||||
namespace MyOffice.Web.Controllers;
|
||||
|
||||
using AutoMapper;
|
||||
using Core.Extensions;
|
||||
using Data.Models.Currencies;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Data.Repositories.Currency;
|
||||
using Models.Currency;
|
||||
using Services.Currency;
|
||||
using Services.Currency.Domain;
|
||||
using MyOffice.Core;
|
||||
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
@@ -17,30 +16,31 @@ public class CurrencyController : BaseApiController
|
||||
{
|
||||
private readonly CurrencyService _currencyService;
|
||||
private readonly ILogger<CurrencyController> _logger;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public CurrencyController(
|
||||
CurrencyService currencyService,
|
||||
ILogger<CurrencyController> logger
|
||||
ILogger<CurrencyController> logger,
|
||||
IMapper mapper
|
||||
)
|
||||
{
|
||||
_currencyService = currencyService;
|
||||
_logger = logger;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
[HttpGet("~/api/settings/currencies")]
|
||||
public object Get()
|
||||
public ObjectResult Get()
|
||||
{
|
||||
var list = _currencyService.GetAllWithRates(UserId);
|
||||
|
||||
return list
|
||||
.OrderBy(x => x.Key.CurrencyGlobalId)
|
||||
.Select(x => x.Key.ToModel(x.Value));
|
||||
return OkResponse(_mapper.Map<List<CurrencyViewModel>>(list).OrderBy(x => x.Id));
|
||||
}
|
||||
|
||||
[HttpPost("~/api/settings/currencies")]
|
||||
public object Post(CurrencyAddModel currency)
|
||||
public ObjectResult Post(CurrencyAddModel currency)
|
||||
{
|
||||
var exec = _currencyService.CurrencyAdd(UserId, new Currency
|
||||
var exec = _currencyService.CurrencyAdd(UserId, new CurrencyDto
|
||||
{
|
||||
UserId = UserId,
|
||||
CurrencyGlobalId = currency.Id,
|
||||
@@ -52,17 +52,17 @@ public class CurrencyController : BaseApiController
|
||||
{
|
||||
case CurrencyAddStatus.success:
|
||||
case CurrencyAddStatus.exists:
|
||||
_currencyService.CurrencyRateAdd(UserId, exec.Result!.Id, new CurrencyRate()
|
||||
_currencyService.CurrencyRateAdd(UserId, exec.Result!.Id, new CurrencyRateDto
|
||||
{
|
||||
CurrencyId = exec.Result!.Id,
|
||||
Rate = currency.Rate,
|
||||
Quantity = currency.Quantity,
|
||||
DateTime = currency.RateDate.Date,
|
||||
});
|
||||
return currency;
|
||||
return OkResponse(_mapper.Map<CurrencyViewModel>(exec.Result!));
|
||||
|
||||
case CurrencyAddStatus.failed:
|
||||
return ProblemBadRequest("Adding currency failed.");
|
||||
return ProblemBadResponse("Adding currency failed.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -70,7 +70,7 @@ public class CurrencyController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpPut("~/api/settings/currencies/{id}")]
|
||||
public object Put(string id, CurrencyEditModel currency)
|
||||
public ObjectResult Update(string id, CurrencyEditModel currency)
|
||||
{
|
||||
var exec = _currencyService.CurrencyUpdate(
|
||||
UserId,
|
||||
@@ -81,11 +81,11 @@ public class CurrencyController : BaseApiController
|
||||
switch (exec.Status)
|
||||
{
|
||||
case CurrencyEditStatus.success:
|
||||
return exec.Result!.ToModel();
|
||||
return OkResponse(_mapper.Map<CurrencyViewModel>(exec.Result!));
|
||||
|
||||
case CurrencyEditStatus.not_found:
|
||||
case CurrencyEditStatus.failed:
|
||||
return ProblemBadRequest("Currency not found.");
|
||||
return ProblemBadResponse("Currency not found.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -93,9 +93,9 @@ public class CurrencyController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpPost("~/api/settings/currencies/{id}/rate")]
|
||||
public object Post(string id, CurrencyRateModel currencyRate)
|
||||
public ObjectResult Add(string id, CurrencyRateModel currencyRate)
|
||||
{
|
||||
var exec = _currencyService.CurrencyRateAdd(UserId, id.AsGuid(), new CurrencyRate()
|
||||
var exec = _currencyService.CurrencyRateAdd(UserId, id.AsGuid(), new CurrencyRateDto
|
||||
{
|
||||
CurrencyId = id.AsGuid(),
|
||||
Quantity = currencyRate.Quantity,
|
||||
@@ -106,12 +106,12 @@ public class CurrencyController : BaseApiController
|
||||
switch (exec.Status)
|
||||
{
|
||||
case CurrencyAddRateStatus.failed:
|
||||
return ProblemBadRequest("Adding currency rate failed.");
|
||||
return ProblemBadResponse("Adding currency rate failed.");
|
||||
case CurrencyAddRateStatus.not_found:
|
||||
return ProblemBadRequest("Currency not found.");
|
||||
return ProblemBadResponse("Currency not found.");
|
||||
|
||||
case CurrencyAddRateStatus.success:
|
||||
return exec.Result!;
|
||||
return OkResponse(_mapper.Map<CurrencyRateViewModel>(exec.Result!));
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
namespace MyOffice.Web.Controllers;
|
||||
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Data.Repositories.Currency;
|
||||
using Models.Currency;
|
||||
using Services.Currency;
|
||||
|
||||
@@ -12,19 +12,22 @@ using Services.Currency;
|
||||
public class GeneralController : BaseApiController
|
||||
{
|
||||
private readonly CurrencyService _currencyService;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public GeneralController(
|
||||
CurrencyService currencyService
|
||||
CurrencyService currencyService,
|
||||
IMapper mapper
|
||||
)
|
||||
{
|
||||
_currencyService = currencyService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
[HttpGet("~/api/general/currencies")]
|
||||
public object Get()
|
||||
public ObjectResult Get()
|
||||
{
|
||||
var list = _currencyService.GetGlobalAll();
|
||||
|
||||
return list.Select(x => x.ToModel());
|
||||
return Ok(_mapper.Map<List<CurrencyGlobalViewModel>>(list));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
namespace MyOffice.Web.Controllers;
|
||||
|
||||
using AutoMapper;
|
||||
using Core;
|
||||
using Core.Extensions;
|
||||
using Data.Models.Accounts;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
using Core;
|
||||
using Core.Extensions;
|
||||
using Models.Account;
|
||||
using Services.Account;
|
||||
using Services.Account.Domain;
|
||||
using MyOffice.Web.Infrastructure.Attributes;
|
||||
using Infrastructure.Attributes;
|
||||
using Services.Identity;
|
||||
|
||||
[Authorize]
|
||||
@@ -52,7 +52,7 @@ public class SettingsAccountController : BaseApiController
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadRequest("Account category not found.");
|
||||
return ProblemBadResponse("Account category not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
return _mapper.Map<AccountCategoryViewModel>(exec.Result!);
|
||||
@@ -65,7 +65,7 @@ public class SettingsAccountController : BaseApiController
|
||||
[HttpPost("~/api/settings/account-categories")]
|
||||
public object AccountCategoriesAdd(AccountCategoryViewModel request)
|
||||
{
|
||||
var exec = _accountService.CategoryAdd(UserId, new AccountCategory { Name = request.Name! });
|
||||
var exec = _accountService.CategoryAdd(UserId, new AccountCategoryDto { Name = request.Name! });
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.success:
|
||||
@@ -73,7 +73,7 @@ public class SettingsAccountController : BaseApiController
|
||||
|
||||
case GeneralExecStatus.failure:
|
||||
case GeneralExecStatus.not_found:
|
||||
return ProblemBadRequest("Adding account category failed.");
|
||||
return ProblemBadResponse("Adding account category failed.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -83,7 +83,7 @@ public class SettingsAccountController : BaseApiController
|
||||
[HttpPut("~/api/settings/account-categories/{id}")]
|
||||
public object AccountCategoriesEdit([AsGuid] string id, AccountCategoryViewModel request)
|
||||
{
|
||||
var exec = _accountService.CategoryUpdate(UserId, id.AsGuid(), new AccountCategory { Name = request.Name! });
|
||||
var exec = _accountService.CategoryUpdate(UserId, id.AsGuid(), new AccountCategoryDto { Name = request.Name! });
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.success:
|
||||
@@ -91,7 +91,7 @@ public class SettingsAccountController : BaseApiController
|
||||
|
||||
case GeneralExecStatus.failure:
|
||||
case GeneralExecStatus.not_found:
|
||||
return ProblemBadRequest("Update account category failed.");
|
||||
return ProblemBadResponse("Update account category failed.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -108,11 +108,11 @@ public class SettingsAccountController : BaseApiController
|
||||
return exec.Result!;
|
||||
|
||||
case AccountCategoryRemoveResult.failure:
|
||||
return ProblemBadRequest("Remove account category failed.");
|
||||
return ProblemBadResponse("Remove account category failed.");
|
||||
case AccountCategoryRemoveResult.not_found:
|
||||
return ProblemBadRequest("Account category not found.");
|
||||
return ProblemBadResponse("Account category not found.");
|
||||
case AccountCategoryRemoveResult.accounts_exists:
|
||||
return ProblemBadRequest("Account category have accounts.");
|
||||
return ProblemBadResponse("Account category have accounts.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -143,11 +143,11 @@ public class SettingsAccountController : BaseApiController
|
||||
switch (exec.Status)
|
||||
{
|
||||
case AccountAddStatus.category_not_found:
|
||||
return ProblemBadRequest("Category not found.");
|
||||
return ProblemBadResponse("Category not found.");
|
||||
case AccountAddStatus.currency_not_found:
|
||||
return ProblemBadRequest("Currency not found.");
|
||||
return ProblemBadResponse("Currency not found.");
|
||||
case AccountAddStatus.failure:
|
||||
return ProblemBadRequest("Adding account failed.");
|
||||
return ProblemBadResponse("Adding account failed.");
|
||||
case AccountAddStatus.success:
|
||||
return exec.Result!;
|
||||
|
||||
@@ -172,13 +172,13 @@ public class SettingsAccountController : BaseApiController
|
||||
switch (exec.Status)
|
||||
{
|
||||
case AccountEditStatus.not_found:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
return ProblemBadResponse("Account not found.");
|
||||
case AccountEditStatus.category_not_found:
|
||||
return ProblemBadRequest("Category not found.");
|
||||
return ProblemBadResponse("Category not found.");
|
||||
case AccountEditStatus.currency_not_found:
|
||||
return ProblemBadRequest("Currency not found.");
|
||||
return ProblemBadResponse("Currency not found.");
|
||||
case AccountEditStatus.failure:
|
||||
return ProblemBadRequest("Adding account failed.");
|
||||
return ProblemBadResponse("Adding account failed.");
|
||||
case AccountEditStatus.success:
|
||||
return exec.Result!;
|
||||
|
||||
@@ -194,7 +194,7 @@ public class SettingsAccountController : BaseApiController
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
return ProblemBadResponse("Account not found.");
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!;
|
||||
|
||||
@@ -212,7 +212,7 @@ public class SettingsAccountController : BaseApiController
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadRequest("Category not found.");
|
||||
return ProblemBadResponse("Category not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!;
|
||||
@@ -233,7 +233,7 @@ public class SettingsAccountController : BaseApiController
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
return ProblemBadResponse("Account not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
break;
|
||||
@@ -252,7 +252,7 @@ public class SettingsAccountController : BaseApiController
|
||||
switch (inviteExec.Status)
|
||||
{
|
||||
case AccessInviteStatus.account_not_found:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
return ProblemBadResponse("Account not found.");
|
||||
|
||||
case AccessInviteStatus.access_exists:
|
||||
case AccessInviteStatus.invite_exists:
|
||||
@@ -273,7 +273,7 @@ public class SettingsAccountController : BaseApiController
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
return ProblemBadResponse("Account not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!;
|
||||
@@ -299,9 +299,9 @@ public class SettingsAccountController : BaseApiController
|
||||
switch (exec.Status)
|
||||
{
|
||||
case InviteAcceptStatus.invite_not_found:
|
||||
return ProblemBadRequest("Invite not found.");
|
||||
return ProblemBadResponse("Invite not found.");
|
||||
case InviteAcceptStatus.account_not_found:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
return ProblemBadResponse("Account not found.");
|
||||
|
||||
case InviteAcceptStatus.already_accepted:
|
||||
case InviteAcceptStatus.success:
|
||||
@@ -321,7 +321,7 @@ public class SettingsAccountController : BaseApiController
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadRequest("Invite not found.");
|
||||
return ProblemBadResponse("Invite not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
return _mapper.Map<AccountAccessInviteViewModel>(exec.Result!);
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
namespace MyOffice.Web.Controllers;
|
||||
|
||||
using Data.Models.Items;
|
||||
using Data.Repositories.Account;
|
||||
using AutoMapper;
|
||||
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 Core.Extensions;
|
||||
using Core;
|
||||
using Infrastructure.Attributes;
|
||||
using Services.Item;
|
||||
using Services.Item.Domain;
|
||||
|
||||
@@ -18,42 +17,43 @@ using Services.Item.Domain;
|
||||
public class SettingsItemController : BaseApiController
|
||||
{
|
||||
private ILogger<SettingsItemController> _logger;
|
||||
|
||||
private IMapper _mapper;
|
||||
private ItemService _itemService;
|
||||
|
||||
public SettingsItemController(
|
||||
ILogger<SettingsItemController> logger,
|
||||
ItemService itemService
|
||||
ItemService itemService,
|
||||
IMapper mapper
|
||||
)
|
||||
{
|
||||
_itemService = itemService;
|
||||
_logger = logger;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
[HttpGet("~/api/settings/item-categories")]
|
||||
public object ItemsCategories()
|
||||
public ObjectResult ItemsCategories()
|
||||
{
|
||||
var list = _itemService.GetAllCategories(UserId);
|
||||
|
||||
return list
|
||||
.Select(x => x.ToModel())
|
||||
return Ok(_mapper.Map<List<ItemCategoryViewModel>>(list)
|
||||
.OrderByDescending(x => x.SortOrder)
|
||||
.ThenBy(x => x.Name);
|
||||
.ThenBy(x => x.Name));
|
||||
}
|
||||
|
||||
[HttpPost("~/api/settings/item-categories")]
|
||||
public object ItemCategoriesAdd(ItemCategoryViewModel request)
|
||||
public ObjectResult ItemCategoriesAdd(ItemCategoryViewModel request)
|
||||
{
|
||||
var exec = _itemService.CategoryAdd(UserId, request.FromModel());
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!.ToModel();
|
||||
return Ok(_mapper.Map<ItemCategoryViewModel>(exec.Result!));
|
||||
|
||||
case GeneralExecStatus.failure:
|
||||
case GeneralExecStatus.not_found:
|
||||
return ProblemBadRequest("Adding item category failed.");
|
||||
return ProblemBadResponse("Adding item category failed.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -61,18 +61,18 @@ public class SettingsItemController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpPut("~/api/settings/item-categories/{id}")]
|
||||
public object ItemCategoriesEdit(string id, ItemCategoryViewModel request)
|
||||
public ObjectResult ItemCategoriesUpdate([AsGuid] string id, ItemCategoryViewModel request)
|
||||
{
|
||||
var exec = _itemService.CategoryUpdate(UserId, id.AsGuid(), request.FromModel());
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!.ToModel();
|
||||
return Ok(_mapper.Map<ItemCategoryViewModel>(exec.Result!));
|
||||
|
||||
case GeneralExecStatus.failure:
|
||||
case GeneralExecStatus.not_found:
|
||||
return ProblemBadRequest("Update item category failed.");
|
||||
return ProblemBadResponse("Update item category failed.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -80,20 +80,20 @@ public class SettingsItemController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpDelete("~/api/settings/item-categories/{id}")]
|
||||
public object ItemCategoriesDelete(string id)
|
||||
public ObjectResult ItemCategoriesDelete([AsGuid] string id)
|
||||
{
|
||||
var exec = _itemService.CategoryRemove(UserId, id.AsGuid());
|
||||
switch (exec.Status)
|
||||
{
|
||||
case ItemCategoryRemoveResult.success:
|
||||
return exec.Result!;
|
||||
return Ok(_mapper.Map<ItemCategoryViewModel>(exec.Result!));
|
||||
|
||||
case ItemCategoryRemoveResult.failure:
|
||||
return ProblemBadRequest("Remove item category failed.");
|
||||
return ProblemBadResponse("Remove item category failed.");
|
||||
case ItemCategoryRemoveResult.not_found:
|
||||
return ProblemBadRequest("Account item not found.");
|
||||
return ProblemBadResponse("Account item not found.");
|
||||
case ItemCategoryRemoveResult.accounts_exists:
|
||||
return ProblemBadRequest("Account motion have accounts.");
|
||||
return ProblemBadResponse("Account motion have accounts.");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
@@ -101,29 +101,28 @@ public class SettingsItemController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpGet("~/api/settings/items")]
|
||||
public object Items(string? category)
|
||||
public ObjectResult Items([AsGuid] 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());
|
||||
return Ok(_mapper.Map<List<ItemViewModel>>(list.OrderBy(x => x.Name)));
|
||||
}
|
||||
|
||||
[HttpPut("~/api/settings/items/{id}")]
|
||||
public object Items(string id, ItemEditModel request)
|
||||
public ObjectResult Items([AsGuid] 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.");
|
||||
return ProblemBadResponse("Item not found.");
|
||||
case GeneralExecStatus.failure:
|
||||
return ProblemBadRequest("Item update failed.");
|
||||
return ProblemBadResponse("Item update failed.");
|
||||
case GeneralExecStatus.success:
|
||||
return Ok(exec.Result!.ToModel());
|
||||
return Ok(_mapper.Map<ItemViewModel>(exec.Result!));
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
|
||||
@@ -84,10 +84,10 @@ public class UserController : BaseApiController
|
||||
public async Task<object> AttachProvider([FromBody] AttachModel model)
|
||||
{
|
||||
var validator = _externalProviderValidators.FirstOrDefault(x => x.Provider.EqualsIgnoreCase(model.Provider));
|
||||
if (validator == null) return ProblemBadRequest("Provider not supported");
|
||||
if (validator == null) return ProblemBadResponse("Provider not supported");
|
||||
|
||||
var result = await validator.ValidateAsync(model.Token);
|
||||
if (!result.IsSuccessed) return ProblemBadRequest("Token not valid");
|
||||
if (!result.IsSuccessed) return ProblemBadResponse("Token not valid");
|
||||
|
||||
var execResult = _userService.AddUserExternal(UserId, model.Provider, result.ExternalId!, result.Email!);
|
||||
switch (execResult.Status)
|
||||
@@ -100,7 +100,7 @@ public class UserController : BaseApiController
|
||||
|
||||
case AddUserExternalStatusEnum.externalid_used:
|
||||
case AddUserExternalStatusEnum.user_not_valid:
|
||||
return ProblemBadRequest("Provider already connected");
|
||||
return ProblemBadResponse("Provider already connected");
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(execResult.Status.ToString());
|
||||
@@ -113,7 +113,7 @@ public class UserController : BaseApiController
|
||||
{
|
||||
var exec = await _userService.RemoveUserExternal(UserId, model.Provider);
|
||||
|
||||
if (exec.Status == GeneralExecStatus.not_found) return ProblemBadRequest("Provider not connected");
|
||||
if (exec.Status == GeneralExecStatus.not_found) return ProblemBadResponse("Provider not connected");
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user