This commit is contained in:
2023-06-21 17:56:00 +03:00
parent fa8852a32a
commit e9d4053e65
55 changed files with 3883 additions and 262 deletions
+42 -6
View File
@@ -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());
+32 -7
View File
@@ -32,13 +32,15 @@ public class CurrencyController : BaseApiController
{
var list = _currencyService.GetAllWithRates(UserId);
return list.Select(x => x.Key.ToModel(x.Value));
return list
.OrderBy(x => x.Key.CurrencyGlobalId)
.Select(x => x.Key.ToModel(x.Value));
}
[HttpPost("~/api/settings/currencies")]
public object Post(CurrencyAddModel currency)
{
var exec = _currencyService.AddCurrency(UserId, new Currency
var exec = _currencyService.CurrencyAdd(UserId, new Currency
{
UserId = UserId,
CurrencyGlobalId = currency.Id,
@@ -48,9 +50,9 @@ public class CurrencyController : BaseApiController
switch (exec.Status)
{
case AddCurrencyStatus.success:
case AddCurrencyStatus.exists:
_currencyService.AddCurrencyRate(UserId, exec.Result!.Id, new CurrencyRate()
case CurrencyAddStatus.success:
case CurrencyAddStatus.exists:
_currencyService.CurrencyRateAdd(UserId, exec.Result!.Id, new CurrencyRate()
{
CurrencyId = exec.Result!.Id,
Rate = currency.Rate,
@@ -59,7 +61,7 @@ public class CurrencyController : BaseApiController
});
return currency;
case AddCurrencyStatus.failed:
case CurrencyAddStatus.failed:
return ProblemBadRequest("Adding currency failed.");
default:
@@ -67,10 +69,33 @@ public class CurrencyController : BaseApiController
}
}
[HttpPut("~/api/settings/currencies/{id}")]
public object Put(string id, CurrencyEditModel currency)
{
var exec = _currencyService.CurrencyUpdate(
UserId,
id.AsGuid(),
new CurrencyEdit { Name = currency.Name, ShortName = currency.ShortName }
);
switch (exec.Status)
{
case CurrencyEditStatus.success:
return exec.Result!.ToModel();
case CurrencyEditStatus.not_found:
case CurrencyEditStatus.failed:
return ProblemBadRequest("Currency not found.");
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()
var exec = _currencyService.CurrencyRateAdd(UserId, id.AsGuid(), new CurrencyRate()
{
CurrencyId = id.AsGuid(),
Quantity = currencyRate.Quantity,
+10 -5
View File
@@ -32,7 +32,10 @@ public class SettingsMotionController : BaseApiController
{
var list = _motionService.GetAllCategories(UserId);
return list.Select(x => x.ToModel()).OrderByDescending(x => x.SortOrder);
return list
.Select(x => x.ToModel())
.OrderByDescending(x => x.SortOrder)
.ThenBy(x => x.Name);
}
[HttpPost("~/api/settings/motion-categories")]
@@ -42,7 +45,7 @@ public class SettingsMotionController : BaseApiController
switch (exec.Status)
{
case GeneralExecStatus.success:
return exec.Result!;
return exec.Result!.ToModel();
case GeneralExecStatus.failure:
case GeneralExecStatus.not_found:
@@ -60,7 +63,7 @@ public class SettingsMotionController : BaseApiController
switch (exec.Status)
{
case GeneralExecStatus.success:
return exec.Result!;
return exec.Result!.ToModel();
case GeneralExecStatus.failure:
case GeneralExecStatus.not_found:
@@ -97,9 +100,11 @@ public class SettingsMotionController : BaseApiController
{
var list = category.IsMissing()
? _motionService.GetAll(UserId)
: _motionService.GetByCategory(UserId, category.AsGuid());
: _motionService.GetByCategory(UserId, category!.AsGuid());
return list.Select(x => x.ToModel());
return list
.OrderBy(x => x.MotionGlobal.Name)
.Select(x => x.ToModel());
}
[HttpPut("~/api/settings/motions/{id}")]
@@ -31,7 +31,26 @@ public class SettingsAccountController : BaseApiController
{
var list = _accountService.GetAllCategories(UserId);
return list.Select(x => x.ToModel());
return list.OrderBy(x => x.Name).Select(x => x.ToModel());
}
[HttpGet("~/api/settings/account-categories/{id}")]
public object AccountCategory(string id)
{
var exec = _accountService.GetCategory(UserId, id.AsGuid());
switch (exec.Status)
{
case GeneralExecStatus.not_found:
case GeneralExecStatus.failure:
return ProblemBadRequest("Account category not found.");
case GeneralExecStatus.success:
return exec.Result!.ToModel();
default:
throw new NotSupportedException(exec.Status.ToString());
}
}
[HttpPost("~/api/settings/account-categories")]
@@ -98,7 +117,9 @@ public class SettingsAccountController : BaseApiController
? _accountService.GetByCategory(UserId, category!.AsGuid())
: _accountService.GetAllAccounts(UserId);
return list.Select(x => x.ToModel());
return list
.OrderBy(x => x.Name)
.Select(x => x.ToModel());
}
[HttpPost("~/api/settings/accounts")]
@@ -1,47 +0,0 @@
namespace MyOffice.Web.Controllers;
using Models.WeatherForecast;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet("~/api/weatherforecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
[HttpGet("~/api/weatherforecast/auth")]
[Authorize]
public IEnumerable<WeatherForecast> GetAuth()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
@@ -18,8 +18,8 @@ public class AccountMotionRequest
public DateTime Date { get; set; }
public string Motion { get; set; } = null!;
public string? Description { get; set; }
public decimal Plus { get; set; }
public decimal Minus { get; set; }
public decimal? Plus { get; set; }
public decimal? Minus { get; set; }
}
public static class AccountMotionViewModelExtension
@@ -34,8 +34,8 @@ public static class AccountMotionRequestExtension
{
Date = input.Date,
Motion = input.Motion,
Minus = input.Minus,
Plus = input.Plus,
Minus = input.Minus ?? 0,
Plus = input.Plus ?? 0,
Description = input.Description,
};
}
@@ -0,0 +1,10 @@
namespace MyOffice.Web.Models.Currency;
public class CurrencyEditModel
{
public string Name { get; set; } = null!;
public string ShortName { get; set; } = null!;
public int Quantity { get; set; }
public decimal Rate { get; set; }
public DateTime RateDate { get; set; }
}
@@ -8,7 +8,9 @@
{
public string Id { get; set; } = null!;
public string Code { get; set; } = null!;
public string Symbol { get; set; } = null!;
public string Name { get; set; } = null!;
public string ShortName { get; set; } = null!;
public decimal? Rate { get; set; }
public int? Quantity { get; set; }
public DateTime? RateDate { get; set; }
@@ -22,7 +24,9 @@
{
Id = input.Id.ToShort(),
Code = input.CurrencyGlobal!.Id,
Symbol = input.CurrencyGlobal!.Symbol,
Name = input.Name,
ShortName = input.ShortName,
Quantity = rate?.Quantity,
Rate = rate?.Rate,
RateDate = rate?.DateTime,
@@ -0,0 +1,33 @@
namespace MyOffice.Web.Models.Motion
{
using System.ComponentModel.DataAnnotations;
using Core.Extensions;
using Data.Models.Accounts;
using MyOffice.Data.Models.Motions;
public class AccountMotionViewModel
{
public string Id { get; set; } = null!;
public DateTime Date { get; set; }
public string Motion { get; set; } = null!;
public string? Description { get; set; }
public decimal Plus { get; set; }
public decimal Minus { get; set; }
}
public static class AccountMotionViewModelExtensions
{
public static AccountMotionViewModel ToModel(this AccountMotion input)
{
return new AccountMotionViewModel
{
Id = input.Id.ToShort(),
Date = input.DateTime,
Motion = input.Motion.MotionGlobal.Name,
Description = input.Description,
Plus = input.AmountPlus,
Minus = input.AmountMinus,
};
}
}
}
@@ -0,0 +1,12 @@
namespace MyOffice.Web.Models.Motion
{
using System.ComponentModel.DataAnnotations;
public class AccountMotionsGetModel
{
[Required]
public DateTime From { get; set; }
[Required]
public DateTime To { get; set; }
}
}
@@ -1,12 +0,0 @@
namespace MyOffice.Web.Models.WeatherForecast;
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}