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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user