From 4df0064978ef611e51ec98a2710a4a87374e7a0d Mon Sep 17 00:00:00 2001 From: max Date: Mon, 18 Aug 2025 01:56:41 +0200 Subject: [PATCH] [CHANGE] Preparing library service --- Manager.App/DependencyInjection.cs | 19 +++++++++++ Manager.App/Manager.App.csproj | 4 --- .../Models/Library/LibraryInformation.cs | 11 ++++++ Manager.App/Program.cs | 3 +- Manager.App/Services/ILibraryService.cs | 6 ++++ Manager.App/Services/LibraryService.cs | 34 +++++++++++++++++++ 6 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 Manager.App/Models/Library/LibraryInformation.cs create mode 100644 Manager.App/Services/ILibraryService.cs create mode 100644 Manager.App/Services/LibraryService.cs diff --git a/Manager.App/DependencyInjection.cs b/Manager.App/DependencyInjection.cs index ad2dbaa..fbe9961 100644 --- a/Manager.App/DependencyInjection.cs +++ b/Manager.App/DependencyInjection.cs @@ -2,12 +2,31 @@ using DotBased.Logging; using DotBased.Logging.MEL; using DotBased.Logging.Serilog; using Manager.App.Models.Settings; +using Manager.App.Services; +using Manager.Data.Contexts; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Options; using Serilog; namespace Manager.App; public static class DependencyInjection { + public static void ManagerSetup(this WebApplicationBuilder builder) + { + builder.Services.AddDbContextFactory((serviceProvider, options) => + { + var libSettings = serviceProvider.GetRequiredService>().Value; + var logger = serviceProvider.GetRequiredService>(); + + var dbPath = Path.Combine(libSettings.Path, "Library.db"); + logger.LogInformation("Setting library database to: {DbPath}", dbPath); + options.UseSqlite($"Data Source={dbPath}"); + }); + + builder.Services.AddScoped(); + } + public static void SetupSettings(this WebApplicationBuilder builder) { builder.Services.AddOptions() diff --git a/Manager.App/Manager.App.csproj b/Manager.App/Manager.App.csproj index c25e6ce..e95d807 100644 --- a/Manager.App/Manager.App.csproj +++ b/Manager.App/Manager.App.csproj @@ -26,8 +26,4 @@ - - - - diff --git a/Manager.App/Models/Library/LibraryInformation.cs b/Manager.App/Models/Library/LibraryInformation.cs new file mode 100644 index 0000000..a153deb --- /dev/null +++ b/Manager.App/Models/Library/LibraryInformation.cs @@ -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; } +} \ No newline at end of file diff --git a/Manager.App/Program.cs b/Manager.App/Program.cs index 8b4fa63..7ee974e 100644 --- a/Manager.App/Program.cs +++ b/Manager.App/Program.cs @@ -9,9 +9,10 @@ builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); -/* App setup */ +/* Manager */ builder.SetupLogging(); builder.SetupSettings(); +builder.ManagerSetup(); /* MudBlazor */ builder.Services.AddMudServices(); diff --git a/Manager.App/Services/ILibraryService.cs b/Manager.App/Services/ILibraryService.cs new file mode 100644 index 0000000..a797581 --- /dev/null +++ b/Manager.App/Services/ILibraryService.cs @@ -0,0 +1,6 @@ +namespace Manager.App.Services; + +public interface ILibraryService +{ + +} \ No newline at end of file diff --git a/Manager.App/Services/LibraryService.cs b/Manager.App/Services/LibraryService.cs new file mode 100644 index 0000000..a1b2faa --- /dev/null +++ b/Manager.App/Services/LibraryService.cs @@ -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 _logger; + private readonly LibrarySettings _librarySettings; + private readonly IDbContextFactory _dbContextFactory; + private readonly DirectoryInfo _libraryDirectory; + private const string SubDirMedia = "Media"; + private const string SubDirChannels = "Channels"; + + public LibraryService(ILogger logger, IOptions librarySettings, IDbContextFactory 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> GetLibraryInfoAsync() + { + await using var context = await _dbContextFactory.CreateDbContextAsync(); + //TODO: Get library info + return ResultError.Fail("Not implemented!"); + } +} \ No newline at end of file