[CHANGE] Preparing library service

This commit is contained in:
max
2025-08-18 01:56:41 +02:00
parent 4dc3ffda36
commit 4df0064978
6 changed files with 72 additions and 5 deletions

View File

@@ -2,12 +2,31 @@ using DotBased.Logging;
using DotBased.Logging.MEL; using DotBased.Logging.MEL;
using DotBased.Logging.Serilog; using DotBased.Logging.Serilog;
using Manager.App.Models.Settings; using Manager.App.Models.Settings;
using Manager.App.Services;
using Manager.Data.Contexts;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using Serilog; using Serilog;
namespace Manager.App; namespace Manager.App;
public static class DependencyInjection public static class DependencyInjection
{ {
public static void ManagerSetup(this WebApplicationBuilder builder)
{
builder.Services.AddDbContextFactory<LibraryDbContext>((serviceProvider, options) =>
{
var libSettings = serviceProvider.GetRequiredService<IOptions<LibrarySettings>>().Value;
var logger = serviceProvider.GetRequiredService<ILogger<LibraryDbContext>>();
var dbPath = Path.Combine(libSettings.Path, "Library.db");
logger.LogInformation("Setting library database to: {DbPath}", dbPath);
options.UseSqlite($"Data Source={dbPath}");
});
builder.Services.AddScoped<ILibraryService, LibraryService>();
}
public static void SetupSettings(this WebApplicationBuilder builder) public static void SetupSettings(this WebApplicationBuilder builder)
{ {
builder.Services.AddOptions<LibrarySettings>() builder.Services.AddOptions<LibrarySettings>()

View File

@@ -26,8 +26,4 @@
<ProjectReference Include="..\Manager.YouTube\Manager.YouTube.csproj" /> <ProjectReference Include="..\Manager.YouTube\Manager.YouTube.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Services\" />
</ItemGroup>
</Project> </Project>

View File

@@ -0,0 +1,11 @@
namespace Manager.App.Models.Library;
public record LibraryInformation
{
public DateTime CreatedAtUtc { get; set; }
public DateTime LastModifiedUtc { get; set; }
public string LibraryPath { get; set; } = "";
public long TotalMedia { get; set; }
public long TotalChannels { get; set; }
public long TotalSizeBytes { get; set; }
}

View File

@@ -9,9 +9,10 @@ builder.Services.AddRazorComponents()
.AddInteractiveServerComponents(); .AddInteractiveServerComponents();
/* App setup */ /* Manager */
builder.SetupLogging(); builder.SetupLogging();
builder.SetupSettings(); builder.SetupSettings();
builder.ManagerSetup();
/* MudBlazor */ /* MudBlazor */
builder.Services.AddMudServices(); builder.Services.AddMudServices();

View File

@@ -0,0 +1,6 @@
namespace Manager.App.Services;
public interface ILibraryService
{
}

View File

@@ -0,0 +1,34 @@
using DotBased.Monads;
using Manager.App.Models.Library;
using Manager.App.Models.Settings;
using Manager.Data.Contexts;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
namespace Manager.App.Services;
public class LibraryService : ILibraryService
{
private readonly ILogger<LibraryService> _logger;
private readonly LibrarySettings _librarySettings;
private readonly IDbContextFactory<LibraryDbContext> _dbContextFactory;
private readonly DirectoryInfo _libraryDirectory;
private const string SubDirMedia = "Media";
private const string SubDirChannels = "Channels";
public LibraryService(ILogger<LibraryService> logger, IOptions<LibrarySettings> librarySettings, IDbContextFactory<LibraryDbContext> contextFactory)
{
_logger = logger;
_librarySettings = librarySettings.Value;
_dbContextFactory = contextFactory;
_libraryDirectory = Directory.CreateDirectory(Path.Combine(_librarySettings.Path, SubDirMedia));
_libraryDirectory = Directory.CreateDirectory(Path.Combine(_librarySettings.Path, SubDirChannels));
}
public async Task<Result<LibraryInformation>> GetLibraryInfoAsync()
{
await using var context = await _dbContextFactory.CreateDbContextAsync();
//TODO: Get library info
return ResultError.Fail("Not implemented!");
}
}