From a8cfbbe0dbaacd82b4e3d8d9f68be4353b71c3e9 Mon Sep 17 00:00:00 2001 From: max Date: Thu, 4 Sep 2025 10:37:38 +0200 Subject: [PATCH] [CHANGE] Adding accounts --- Manager.App/Components/Layout/NavMenu.razor | 2 +- Manager.App/Components/Pages/Channels.razor | 83 +++++++++++++++++++ .../Components/Pages/Channels.razor.cs | 21 +++++ Manager.App/Components/Pages/Library.razor.cs | 3 +- Manager.App/Models/System/ListResult.cs | 30 +++++++ Manager.App/Services/ILibraryService.cs | 4 + Manager.App/Services/LibraryService.cs | 7 +- 7 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 Manager.App/Models/System/ListResult.cs diff --git a/Manager.App/Components/Layout/NavMenu.razor b/Manager.App/Components/Layout/NavMenu.razor index f0e9a3c..a611661 100644 --- a/Manager.App/Components/Layout/NavMenu.razor +++ b/Manager.App/Components/Layout/NavMenu.razor @@ -1,6 +1,6 @@  - Home + Home Channels Library Playlists diff --git a/Manager.App/Components/Pages/Channels.razor b/Manager.App/Components/Pages/Channels.razor index 63fb9df..2e0b35d 100644 --- a/Manager.App/Components/Pages/Channels.razor +++ b/Manager.App/Components/Pages/Channels.razor @@ -1,3 +1,86 @@ @page "/Channels" +@inject ILibraryService LibraryService Channels + + + + Add new account + + + +
+ + Cookies + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + +
+
+ + + Cancel + Save + + +
+ + + + + Add account + + + + + + Channels + + + Name + Channel id + Has login + + + @context.Name + @context.Id + @(context.ClientAccount != null) + + + No channels found + + + Loading... + + + + + + \ No newline at end of file diff --git a/Manager.App/Components/Pages/Channels.razor.cs b/Manager.App/Components/Pages/Channels.razor.cs index 108cfd3..349bae6 100644 --- a/Manager.App/Components/Pages/Channels.razor.cs +++ b/Manager.App/Components/Pages/Channels.razor.cs @@ -1,7 +1,28 @@ +using Manager.Data.Entities.LibraryContext; using Microsoft.AspNetCore.Components; +using MudBlazor; namespace Manager.App.Components.Pages; public partial class Channels : ComponentBase { + private bool _addAccountDialogVisible; + private DialogOptions _dialogOptions = new() { BackdropClick = false, CloseButton = true, FullWidth = true }; + private List _cookies = []; + private async Task> ServerReload(TableState state, CancellationToken token) + { + var results = await LibraryService.GetChannelAccountsAsync(state.Page * state.PageSize, state.PageSize, token); + if (!results.IsSuccess) + { + return new TableData(); + } + + return new TableData { Items = results.Value, TotalItems = results.Total }; + } +} + +public record HttpCookie() +{ + public string Name { get; set; } + public string Value { get; set; } } \ No newline at end of file diff --git a/Manager.App/Components/Pages/Library.razor.cs b/Manager.App/Components/Pages/Library.razor.cs index 22750e7..f5308ba 100644 --- a/Manager.App/Components/Pages/Library.razor.cs +++ b/Manager.App/Components/Pages/Library.razor.cs @@ -1,9 +1,10 @@ using Manager.App.Models.Library; +using Microsoft.AspNetCore.Components; using MudBlazor; namespace Manager.App.Components.Pages; -public partial class Library +public partial class Library : ComponentBase { private LibraryInformation? _libraryInformation; private bool _loading; diff --git a/Manager.App/Models/System/ListResult.cs b/Manager.App/Models/System/ListResult.cs new file mode 100644 index 0000000..ad5727e --- /dev/null +++ b/Manager.App/Models/System/ListResult.cs @@ -0,0 +1,30 @@ +using DotBased.Monads; + +namespace Manager.App.Models.System; + +public class ListResult : Result> +{ + protected ListResult(List result, int total) : base(result) + { + Total = total; + } + + protected ListResult(Exception exception) : base(exception) + { + Total = 0; + } + + protected ListResult(ResultError error) : base(error) + { + Total = 0; + } + + public int Total { get; set; } + + public static implicit operator ListResult(ResultError error) => new(error); + public static implicit operator ListResult(Exception exception) => new(exception); + public static implicit operator ListResult(List result) => new(result, 0); + public static implicit operator ListResult(ListResultReturn result) => new(result.List, result.Total); +} + +public record ListResultReturn(List List, int Total); \ No newline at end of file diff --git a/Manager.App/Services/ILibraryService.cs b/Manager.App/Services/ILibraryService.cs index 1ddd997..5ef840a 100644 --- a/Manager.App/Services/ILibraryService.cs +++ b/Manager.App/Services/ILibraryService.cs @@ -1,9 +1,13 @@ using DotBased.Monads; using Manager.App.Models.Library; +using Manager.App.Models.System; +using Manager.Data.Entities.LibraryContext; namespace Manager.App.Services; public interface ILibraryService { public Task> GetLibraryInfoAsync(CancellationToken cancellationToken = default); + + public Task> GetChannelAccountsAsync(int total = 20, int offset = 0, CancellationToken cancellationToken = default); } \ No newline at end of file diff --git a/Manager.App/Services/LibraryService.cs b/Manager.App/Services/LibraryService.cs index db5815f..8c8dce0 100644 --- a/Manager.App/Services/LibraryService.cs +++ b/Manager.App/Services/LibraryService.cs @@ -1,6 +1,7 @@ using DotBased.Monads; using Manager.App.Models.Library; using Manager.App.Models.Settings; +using Manager.App.Models.System; using Manager.Data.Contexts; using Manager.Data.Entities.LibraryContext; using Microsoft.EntityFrameworkCore; @@ -50,13 +51,13 @@ public class LibraryService : ILibraryService } } - public async Task>> GetAccountsAsync(int total = 20, int offset = 0, CancellationToken cancellationToken = default) + public async Task> GetChannelAccountsAsync(int total = 20, int offset = 0, CancellationToken cancellationToken = default) { try { await using var context = await _dbContextFactory.CreateDbContextAsync(cancellationToken); - var orderedAccounts = context.Channels.Include(x => x.ClientAccount).Where(x => x.ClientAccount != null).OrderBy(x => x.Id).Skip(offset).Take(total); - return orderedAccounts.ToList(); + var orderedAccounts = context.Channels.Include(x => x.ClientAccount).Where(x => x.ClientAccount != null).OrderBy(x => x.Id); + return new ListResultReturn(orderedAccounts.Skip(offset).Take(total).ToList(), orderedAccounts.Count()); } catch (Exception e) {