refactor: abstract IWebHostEnvironment to IReceiptStorageOptions
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
namespace MoneyMap.Services;
|
||||||
|
|
||||||
|
public interface IReceiptStorageOptions
|
||||||
|
{
|
||||||
|
string ReceiptsBasePath { get; }
|
||||||
|
}
|
||||||
@@ -21,8 +21,7 @@ namespace MoneyMap.Services
|
|||||||
public class ReceiptManager : IReceiptManager
|
public class ReceiptManager : IReceiptManager
|
||||||
{
|
{
|
||||||
private readonly MoneyMapContext _db;
|
private readonly MoneyMapContext _db;
|
||||||
private readonly IWebHostEnvironment _environment;
|
private readonly IReceiptStorageOptions _receiptStorage;
|
||||||
private readonly IConfiguration _configuration;
|
|
||||||
private readonly IServiceProvider _serviceProvider;
|
private readonly IServiceProvider _serviceProvider;
|
||||||
private readonly IReceiptParseQueue _parseQueue;
|
private readonly IReceiptParseQueue _parseQueue;
|
||||||
private readonly ILogger<ReceiptManager> _logger;
|
private readonly ILogger<ReceiptManager> _logger;
|
||||||
@@ -46,15 +45,13 @@ namespace MoneyMap.Services
|
|||||||
|
|
||||||
public ReceiptManager(
|
public ReceiptManager(
|
||||||
MoneyMapContext db,
|
MoneyMapContext db,
|
||||||
IWebHostEnvironment environment,
|
IReceiptStorageOptions receiptStorage,
|
||||||
IConfiguration configuration,
|
|
||||||
IServiceProvider serviceProvider,
|
IServiceProvider serviceProvider,
|
||||||
IReceiptParseQueue parseQueue,
|
IReceiptParseQueue parseQueue,
|
||||||
ILogger<ReceiptManager> logger)
|
ILogger<ReceiptManager> logger)
|
||||||
{
|
{
|
||||||
_db = db;
|
_db = db;
|
||||||
_environment = environment;
|
_receiptStorage = receiptStorage;
|
||||||
_configuration = configuration;
|
|
||||||
_serviceProvider = serviceProvider;
|
_serviceProvider = serviceProvider;
|
||||||
_parseQueue = parseQueue;
|
_parseQueue = parseQueue;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
@@ -62,9 +59,7 @@ namespace MoneyMap.Services
|
|||||||
|
|
||||||
private string GetReceiptsBasePath()
|
private string GetReceiptsBasePath()
|
||||||
{
|
{
|
||||||
// Get from config, default to "receipts" in wwwroot
|
return _receiptStorage.ReceiptsBasePath;
|
||||||
var relativePath = _configuration["Receipts:StoragePath"] ?? "receipts";
|
|
||||||
return Path.Combine(_environment.WebRootPath, relativePath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ReceiptUploadResult> UploadReceiptAsync(long transactionId, IFormFile file)
|
public async Task<ReceiptUploadResult> UploadReceiptAsync(long transactionId, IFormFile file)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using MoneyMap.Data;
|
using MoneyMap.Data;
|
||||||
using MoneyMap.Services;
|
using MoneyMap.Services;
|
||||||
using MoneyMap.Services.AITools;
|
using MoneyMap.Services.AITools;
|
||||||
|
using MoneyMap.WebApp.Services;
|
||||||
|
|
||||||
// Set default culture to en-US for currency formatting ($)
|
// Set default culture to en-US for currency formatting ($)
|
||||||
var culture = new CultureInfo("en-US");
|
var culture = new CultureInfo("en-US");
|
||||||
@@ -57,6 +58,9 @@ builder.Services.AddScoped<ITopCategoriesProvider, TopCategoriesProvider>();
|
|||||||
builder.Services.AddScoped<IRecentTransactionsProvider, RecentTransactionsProvider>();
|
builder.Services.AddScoped<IRecentTransactionsProvider, RecentTransactionsProvider>();
|
||||||
builder.Services.AddScoped<ISpendTrendsProvider, SpendTrendsProvider>();
|
builder.Services.AddScoped<ISpendTrendsProvider, SpendTrendsProvider>();
|
||||||
|
|
||||||
|
// Receipt storage configuration
|
||||||
|
builder.Services.AddSingleton<IReceiptStorageOptions, WebReceiptStorageOptions>();
|
||||||
|
|
||||||
// Receipt services
|
// Receipt services
|
||||||
builder.Services.AddScoped<IReceiptManager, ReceiptManager>();
|
builder.Services.AddScoped<IReceiptManager, ReceiptManager>();
|
||||||
builder.Services.AddScoped<IReceiptAutoMapper, ReceiptAutoMapper>();
|
builder.Services.AddScoped<IReceiptAutoMapper, ReceiptAutoMapper>();
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
using MoneyMap.Services;
|
||||||
|
|
||||||
|
namespace MoneyMap.WebApp.Services;
|
||||||
|
|
||||||
|
public class WebReceiptStorageOptions : IReceiptStorageOptions
|
||||||
|
{
|
||||||
|
public string ReceiptsBasePath { get; }
|
||||||
|
|
||||||
|
public WebReceiptStorageOptions(IWebHostEnvironment env, IConfiguration config)
|
||||||
|
{
|
||||||
|
var relativePath = config["Receipts:StoragePath"] ?? "receipts";
|
||||||
|
if (Path.IsPathRooted(relativePath))
|
||||||
|
ReceiptsBasePath = relativePath;
|
||||||
|
else
|
||||||
|
ReceiptsBasePath = Path.Combine(env.WebRootPath, relativePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user