This commit is contained in:
2023-06-17 14:16:09 +03:00
parent 62178f1f32
commit 7ae5d3bc81
180 changed files with 12932 additions and 192 deletions
@@ -0,0 +1,50 @@
namespace MyOffice.Web.Controllers;
using Core.Extensions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Models.Account;
using MyOffice.Web.Models.AccountMotion;
using Services.Account;
[Authorize]
[ApiController]
[Route("api/[controller]")]
public class AccountController : BaseApiController
{
private readonly ILogger<AccountController> _logger;
private readonly AccountService _accountService;
public AccountController(
ILogger<AccountController> logger,
AccountService accountService
)
{
_logger = logger;
_accountService = accountService;
}
[HttpGet("~/api/accounts")]
public object AccountsGet(string category)
{
var list = _accountService.GetByCategoryDetailed(UserId, category!.AsGuid());
return list.Select(x => x.ToModel());
}
[HttpGet("~/api/accounts/{id}/motions")]
public object AccountsMotionsGet(string category)
{
var list = _accountService.GetByCategoryDetailed(UserId, category!.AsGuid());
return list.Select(x => x.ToModel());
}
[HttpPost("~/api/accounts/{id}/motions")]
public object AccountsMotionsPost(string id, AccountMotionRequest accountMotion)
{
var list = _accountService.GetByCategoryDetailed(UserId, category!.AsGuid());
return list.Select(x => x.ToModel());
}
}
@@ -0,0 +1,95 @@
namespace MyOffice.Web.Controllers;
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]
[Route("api/[controller]")]
public class CurrencyController : BaseApiController
{
private readonly CurrencyService _currencyService;
private readonly ILogger<CurrencyController> _logger;
public CurrencyController(
CurrencyService currencyService,
ILogger<CurrencyController> logger
)
{
_currencyService = currencyService;
_logger = logger;
}
[HttpGet("~/api/settings/currencies")]
public object Get()
{
var list = _currencyService.GetAllWithRates(UserId);
return list.Select(x => x.Key.ToModel(x.Value));
}
[HttpPost("~/api/settings/currencies")]
public object Post(CurrencyAddModel currency)
{
var exec = _currencyService.AddCurrency(UserId, new Currency
{
UserId = UserId,
CurrencyGlobalId = currency.Id,
Name = currency.Name,
ShortName = currency.ShortName,
});
switch (exec.Status)
{
case AddCurrencyStatus.success:
case AddCurrencyStatus.exists:
_currencyService.AddCurrencyRate(UserId, exec.Result!.Id, new CurrencyRate()
{
CurrencyId = exec.Result!.Id,
Rate = currency.Rate,
Quantity = currency.Quantity,
DateTime = currency.RateDate.Date,
});
return currency;
case AddCurrencyStatus.failed:
return ProblemBadRequest("Adding currency failed.");
default:
throw new NotSupportedException(exec.Status.ToString());
}
}
[HttpPost("~/api/settings/currencies/{id}/rate")]
public object Post(string id, CurrencyRateModel currencyRate)
{
var exec = _currencyService.AddCurrencyRate(UserId, id.AsGuid(), new CurrencyRate()
{
CurrencyId = id.AsGuid(),
Quantity = currencyRate.Quantity,
Rate = currencyRate.Rate,
DateTime = currencyRate.RateDate.Date,
});
switch (exec.Status)
{
case CurrencyAddRateStatus.failed:
return ProblemBadRequest("Adding currency rate failed.");
case CurrencyAddRateStatus.not_found:
return ProblemBadRequest("Currency not found.");
case CurrencyAddRateStatus.success:
return exec.Result!;
default:
throw new NotSupportedException(exec.Status.ToString());
}
}
}
@@ -0,0 +1,30 @@
namespace MyOffice.Web.Controllers;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Data.Repositories.Currency;
using Models.Currency;
using Services.Currency;
[Authorize]
[ApiController]
[Route("api/[controller]")]
public class GeneralController : BaseApiController
{
private readonly CurrencyService _currencyService;
public GeneralController(
CurrencyService currencyService
)
{
_currencyService = currencyService;
}
[HttpGet("~/api/general/currencies")]
public object Get()
{
var list = _currencyService.GetGlobalAll();
return list.Select(x => x.ToModel());
}
}
@@ -0,0 +1,122 @@
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);
}
[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!;
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!;
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.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());
}
}
}
@@ -0,0 +1,178 @@
namespace MyOffice.Web.Controllers;
using Core;
using Core.Extensions;
using Data.Models.Accounts;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using Models.Account;
using Services.Account;
using Services.Account.Domain;
[Authorize]
[ApiController]
[Route("api/[controller]")]
public class SettingsAccountController : BaseApiController
{
private readonly ILogger<SettingsAccountController> _logger;
private readonly AccountService _accountService;
public SettingsAccountController(
ILogger<SettingsAccountController> logger,
AccountService accountService
)
{
_logger = logger;
_accountService = accountService;
}
[HttpGet("~/api/settings/account-categories")]
public object AccountCategories()
{
var list = _accountService.GetAllCategories(UserId);
return list.Select(x => x.ToModel());
}
[HttpPost("~/api/settings/account-categories")]
public object AccountCategoriesAdd(MotionCategoryViewModel request)
{
var exec = _accountService.CategoryAdd(UserId, new AccountCategory { Name = request.Name! });
switch (exec.Status)
{
case GeneralExecStatus.success:
return exec.Result!;
case GeneralExecStatus.failure:
case GeneralExecStatus.not_found:
return ProblemBadRequest("Adding account category failed.");
default:
throw new NotSupportedException(exec.Status.ToString());
}
}
[HttpPut("~/api/settings/account-categories/{id}")]
public object AccountCategoriesEdit(string id, MotionCategoryViewModel request)
{
var exec = _accountService.CategoryUpdate(UserId, id.AsGuid(), new AccountCategory { Name = request.Name! });
switch (exec.Status)
{
case GeneralExecStatus.success:
return exec.Result!;
case GeneralExecStatus.failure:
case GeneralExecStatus.not_found:
return ProblemBadRequest("Update account category failed.");
default:
throw new NotSupportedException(exec.Status.ToString());
}
}
[HttpDelete("~/api/settings/account-categories/{id}")]
public object AccountCategoriesDelete(string id)
{
var exec = _accountService.CategoryRemove(UserId, id.AsGuid());
switch (exec.Status)
{
case AccountCategoryRemoveResult.success:
return exec.Result!;
case AccountCategoryRemoveResult.failure:
return ProblemBadRequest("Remove account category failed.");
case AccountCategoryRemoveResult.not_found:
return ProblemBadRequest("Account category not found.");
case AccountCategoryRemoveResult.accounts_exists:
return ProblemBadRequest("Account category have accounts.");
default:
throw new NotSupportedException(exec.Status.ToString());
}
}
[HttpGet("~/api/settings/accounts")]
public object AccountsGet(string? category)
{
var list = category.IsPresent()
? _accountService.GetByCategory(UserId, category!.AsGuid())
: _accountService.GetAllAccounts(UserId);
return list.Select(x => x.ToModel());
}
[HttpPost("~/api/settings/accounts")]
public object AccountsAdd(AccountViewModel request)
{
var exec = _accountService.AccountAdd(UserId, new AccountAdd
{
Name = request.Name,
CurrencyId = request.CurrencyId,
CategoryId = request.CategoryId.AsGuid(),
});
switch (exec.Status)
{
case AccountAddResult.category_not_found:
return ProblemBadRequest("Category not found.");
case AccountAddResult.currency_not_found:
return ProblemBadRequest("Currency not found.");
case AccountAddResult.failure:
return ProblemBadRequest("Adding account failed.");
case AccountAddResult.success:
return exec.Result!;
default:
throw new NotSupportedException(exec.Status.ToString());
}
}
[HttpPut("~/api/settings/accounts/{id}")]
public object AccountsAdd(string id, AccountEditRequestModel request)
{
var exec = _accountService.AccountUpdate(UserId, id.AsGuid(), new AccountEdit
{
Name = request.Name,
CurrencyId = request.CurrencyId,
CategoryId = request.CategoryId?.AsGuidNull(),
UserId = request.UserId?.AsGuidNull(),
});
switch (exec.Status)
{
case AccountEditResult.not_found:
return ProblemBadRequest("Account not found.");
case AccountEditResult.category_not_found:
return ProblemBadRequest("Category not found.");
case AccountEditResult.currency_not_found:
return ProblemBadRequest("Currency not found.");
case AccountEditResult.failure:
return ProblemBadRequest("Adding account failed.");
case AccountEditResult.success:
return exec.Result!;
default:
throw new NotSupportedException(exec.Status.ToString());
}
}
[HttpDelete("~/api/settings/accounts/{id}/category/{categoryId}")]
public object AccountsCategoryRemove(string id, string categoryId)
{
var exec = _accountService.AccountCategoryRemove(UserId, id.AsGuid(), categoryId.AsGuid());
switch (exec.Status)
{
case GeneralExecStatus.not_found:
case GeneralExecStatus.failure:
return ProblemBadRequest("Category not found.");
case GeneralExecStatus.success:
return exec.Result!;
default:
throw new NotSupportedException(exec.Status.ToString());
}
}
}
+3 -1
View File
@@ -70,6 +70,7 @@ public class UserController : BaseApiController
user.FirstName = model.FirstName;
user.LastName = model.LastName;
user.FullName = model.FullName.NullIfEmpty() ?? $"{model.FirstName} {model.LastName}";
user.CurrencyId = model.Currency;
await _userManager.UpdateAsync(user);
@@ -144,7 +145,7 @@ public class ProfileModel
public string? LastName { get; set; }
public string? FullName { get; set; }
public bool? IsEmailConfirmed { get; set; }
public string? Currency { get; set; }
public List<ProviderModel>? Providers { get; set; }
}
@@ -159,6 +160,7 @@ public static class ProfileModelExtensions
LastName = user.LastName,
FullName = user.FullName,
IsEmailConfirmed = user.IsEmailConfirmed,
Currency = user.CurrencyId,
Providers = userClaims?.Select(x => new ProfileModel.ProviderModel
{
Provider = x.Provider,