update
This commit is contained in:
@@ -6,9 +6,11 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Models.Account;
|
||||
using Models.Item;
|
||||
using Models.Motion;
|
||||
using Services.Account;
|
||||
using Services.Account.Domain;
|
||||
using Services.Item;
|
||||
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
@@ -17,14 +19,17 @@ public class AccountController : BaseApiController
|
||||
{
|
||||
private readonly ILogger<AccountController> _logger;
|
||||
private readonly AccountService _accountService;
|
||||
private readonly ItemService _itemService;
|
||||
|
||||
public AccountController(
|
||||
ILogger<AccountController> logger,
|
||||
AccountService accountService
|
||||
AccountService accountService,
|
||||
ItemService itemService
|
||||
)
|
||||
{
|
||||
_logger = logger;
|
||||
_accountService = accountService;
|
||||
_itemService = itemService;
|
||||
}
|
||||
|
||||
[HttpGet("~/api/accounts")]
|
||||
@@ -131,4 +136,40 @@ public class AccountController : BaseApiController
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("~/api/items")]
|
||||
public object FindItems(string term)
|
||||
{
|
||||
var items = _itemService
|
||||
.FindItems(UserId, term)
|
||||
.Select(x => x.ToModel())
|
||||
.ToList();
|
||||
|
||||
if (term.StartsWith("+") && term.Length > 1)
|
||||
{
|
||||
var accounts = _accountService.FindAccounts(UserId, term.Substring(1));
|
||||
foreach (var account in accounts)
|
||||
{
|
||||
var accountName = $"+{account.Name}";
|
||||
var item = items.FirstOrDefault(x => x.Name == accountName);
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
items.Add(new ItemViewModel
|
||||
{
|
||||
Name = accountName,
|
||||
AccountId = account.Id.ToShort(),
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
item.AccountId = account.Id.ToShort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return items
|
||||
.OrderBy(x => x.AccountId)
|
||||
.ThenBy(x => x.Name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace MyOffice.Web.Controllers;
|
||||
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using MyOffice.Services.Account;
|
||||
using MyOffice.Services.Item;
|
||||
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class DashboardController : BaseApiController
|
||||
{
|
||||
private readonly ILogger<DashboardController> _logger;
|
||||
|
||||
public DashboardController(
|
||||
ILogger<DashboardController> logger
|
||||
)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("~/api/accounts")]
|
||||
public object Index()
|
||||
{
|
||||
return new
|
||||
{
|
||||
IncomeLastWeek = 100m,
|
||||
IncomePreviousWeek = 100m,
|
||||
OutcomeLastWeek = 100m,
|
||||
OutcomePreviousWeek = 100m,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -17,13 +17,17 @@ using Services.Item.Domain;
|
||||
[Route("api/[controller]")]
|
||||
public class SettingsItemController : BaseApiController
|
||||
{
|
||||
private ILogger<SettingsItemController> _logger;
|
||||
|
||||
private ItemService _itemService;
|
||||
|
||||
public SettingsItemController(
|
||||
ILogger<SettingsItemController> logger,
|
||||
ItemService itemService
|
||||
)
|
||||
{
|
||||
_itemService = itemService;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet("~/api/settings/item-categories")]
|
||||
@@ -40,7 +44,8 @@ public class SettingsItemController : BaseApiController
|
||||
[HttpPost("~/api/settings/item-categories")]
|
||||
public object ItemCategoriesAdd(ItemCategoryViewModel request)
|
||||
{
|
||||
var exec = _itemService.CategoryAdd(UserId, new ItemCategory { Name = request.Name! });
|
||||
var exec = _itemService.CategoryAdd(UserId, request.FromModel());
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.success:
|
||||
@@ -58,7 +63,8 @@ public class SettingsItemController : BaseApiController
|
||||
[HttpPut("~/api/settings/item-categories/{id}")]
|
||||
public object ItemCategoriesEdit(string id, ItemCategoryViewModel request)
|
||||
{
|
||||
var exec = _itemService.CategoryUpdate(UserId, id.AsGuid(), new ItemCategory { Name = request.Name! });
|
||||
var exec = _itemService.CategoryUpdate(UserId, id.AsGuid(), request.FromModel());
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.success:
|
||||
|
||||
@@ -3,16 +3,18 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using MyOffice.Core.Extensions;
|
||||
using MyOffice.Data.Models.Items;
|
||||
using MyOffice.Migrations.Postgres.Migrations;
|
||||
|
||||
public class ItemCategoryViewModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Name { get; set; } = null!;
|
||||
|
||||
public bool AllowDelete { get; set; }
|
||||
public int SortOrder { get; set; }
|
||||
public bool IsInternal { get; set; }
|
||||
}
|
||||
|
||||
public static class ItemCategoryViewModelExtensions
|
||||
@@ -24,8 +26,21 @@
|
||||
Id = input.Id.ToShort(),
|
||||
Name = input.Name,
|
||||
AllowDelete = !input.Items.Any() && input.Id != input.UserId,
|
||||
IsInternal = input.IsInternal,
|
||||
SortOrder = input.Id == input.UserId ? 1 : 0
|
||||
};
|
||||
}
|
||||
|
||||
public static ItemCategory FromModel(this ItemCategoryViewModel input)
|
||||
{
|
||||
if (input == null)
|
||||
throw new ArgumentNullException(nameof(input));
|
||||
|
||||
return new ItemCategory
|
||||
{
|
||||
Name = input.Name,
|
||||
IsInternal = input.IsInternal,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
namespace MyOffice.Web.Models.Item
|
||||
{
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Data.Models.Accounts;
|
||||
using MyOffice.Core.Extensions;
|
||||
using MyOffice.Data.Models.Items;
|
||||
|
||||
@@ -9,24 +10,26 @@
|
||||
public string? Id { get; set; }
|
||||
|
||||
public string CategoryId { get; set; } = null!;
|
||||
public string Category { get; set; } = null!;
|
||||
public string? Category { get; set; } = null!;
|
||||
[Required]
|
||||
public string? Name { get; set; }
|
||||
|
||||
public bool AllowDelete { get; set; }
|
||||
public string? AccountId { get; set; }
|
||||
}
|
||||
|
||||
public static class ItemViewModelExtensions
|
||||
{
|
||||
public static ItemViewModel ToModel(this Item input)
|
||||
public static ItemViewModel ToModel(this Item input, Account? account = null)
|
||||
{
|
||||
return new ItemViewModel
|
||||
{
|
||||
Id = input.ItemGlobalId.ToShort(),
|
||||
CategoryId = input.Category.Id.ToShort(),
|
||||
Category = input.Category.Name,
|
||||
Id = input.ItemGlobal.Id.ToShort(),
|
||||
CategoryId = input.CategoryId.ToShort(),
|
||||
Category = input.Category?.Name,
|
||||
Name = input.ItemGlobal.Name,
|
||||
AllowDelete = !input.Motions.Any(),
|
||||
AllowDelete = input.Motions != null && !input.Motions.Any(),
|
||||
AccountId = account?.Id.ToShort(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ using MyOffice.Services.Account.Domain;
|
||||
public class MotionRequest
|
||||
{
|
||||
public DateTime Date { get; set; }
|
||||
public string Motion { get; set; } = null!;
|
||||
public string Item { get; set; } = null!;
|
||||
public string? Description { get; set; }
|
||||
public decimal? Plus { get; set; }
|
||||
public decimal? Minus { get; set; }
|
||||
@@ -18,7 +18,7 @@ public static class MotionRequestExtension
|
||||
return new MotionAddUpdate
|
||||
{
|
||||
Date = input.Date,
|
||||
Motion = input.Motion,
|
||||
Item = input.Item,
|
||||
Minus = input.Minus ?? 0,
|
||||
Plus = input.Plus ?? 0,
|
||||
Description = input.Description,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
{
|
||||
public string Id { get; set; } = null!;
|
||||
public DateTime Date { get; set; }
|
||||
public string Motion { get; set; } = null!;
|
||||
public string Item { get; set; } = null!;
|
||||
public string? Description { get; set; }
|
||||
public decimal Plus { get; set; }
|
||||
public decimal Minus { get; set; }
|
||||
@@ -21,7 +21,7 @@
|
||||
{
|
||||
Id = input.Id.ToShort(),
|
||||
Date = input.DateTime,
|
||||
Motion = input.Item.ItemGlobal.Name,
|
||||
Item = input.Item.ItemGlobal.Name,
|
||||
Description = input.Description,
|
||||
Plus = input.AmountPlus,
|
||||
Minus = input.AmountMinus,
|
||||
|
||||
Reference in New Issue
Block a user