[CHANGE] Preparing library service
This commit is contained in:
@@ -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<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)
|
||||
{
|
||||
builder.Services.AddOptions<LibrarySettings>()
|
||||
|
@@ -26,8 +26,4 @@
|
||||
<ProjectReference Include="..\Manager.YouTube\Manager.YouTube.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Services\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
11
Manager.App/Models/Library/LibraryInformation.cs
Normal file
11
Manager.App/Models/Library/LibraryInformation.cs
Normal 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; }
|
||||
}
|
@@ -9,9 +9,10 @@ builder.Services.AddRazorComponents()
|
||||
.AddInteractiveServerComponents();
|
||||
|
||||
|
||||
/* App setup */
|
||||
/* Manager */
|
||||
builder.SetupLogging();
|
||||
builder.SetupSettings();
|
||||
builder.ManagerSetup();
|
||||
|
||||
/* MudBlazor */
|
||||
builder.Services.AddMudServices();
|
||||
|
6
Manager.App/Services/ILibraryService.cs
Normal file
6
Manager.App/Services/ILibraryService.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Manager.App.Services;
|
||||
|
||||
public interface ILibraryService
|
||||
{
|
||||
|
||||
}
|
34
Manager.App/Services/LibraryService.cs
Normal file
34
Manager.App/Services/LibraryService.cs
Normal 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!");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user