fix
This commit is contained in:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user