refactor: move services and AITools to MoneyMap.Core
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MoneyMap.Data;
|
||||
using MoneyMap.Models;
|
||||
|
||||
namespace MoneyMap.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Service for retrieving reference/lookup data used in dropdowns and filters.
|
||||
/// </summary>
|
||||
public interface IReferenceDataService
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets all distinct categories from transactions, sorted alphabetically.
|
||||
/// </summary>
|
||||
Task<List<string>> GetAvailableCategoriesAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets all merchants, sorted by name.
|
||||
/// </summary>
|
||||
Task<List<Merchant>> GetAvailableMerchantsAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Gets all cards with optional account information included.
|
||||
/// </summary>
|
||||
Task<List<Card>> GetAvailableCardsAsync(bool includeAccount = true);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all accounts, sorted by institution and last4.
|
||||
/// </summary>
|
||||
Task<List<Account>> GetAvailableAccountsAsync();
|
||||
}
|
||||
|
||||
public class ReferenceDataService : IReferenceDataService
|
||||
{
|
||||
private readonly MoneyMapContext _db;
|
||||
|
||||
public ReferenceDataService(MoneyMapContext db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public async Task<List<string>> GetAvailableCategoriesAsync()
|
||||
{
|
||||
return await _db.Transactions
|
||||
.Select(t => t.Category ?? "")
|
||||
.Where(c => !string.IsNullOrWhiteSpace(c))
|
||||
.Distinct()
|
||||
.OrderBy(c => c)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<Merchant>> GetAvailableMerchantsAsync()
|
||||
{
|
||||
return await _db.Merchants
|
||||
.OrderBy(m => m.Name)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<Card>> GetAvailableCardsAsync(bool includeAccount = true)
|
||||
{
|
||||
var query = _db.Cards.AsQueryable();
|
||||
|
||||
if (includeAccount)
|
||||
{
|
||||
query = query.Include(c => c.Account);
|
||||
}
|
||||
|
||||
return await query
|
||||
.OrderBy(c => c.Owner)
|
||||
.ThenBy(c => c.Last4)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<Account>> GetAvailableAccountsAsync()
|
||||
{
|
||||
return await _db.Accounts
|
||||
.OrderBy(a => a.Institution)
|
||||
.ThenBy(a => a.Last4)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user