[ADD] Simple views for accounts and channels

This commit is contained in:
max
2025-09-22 15:50:30 +02:00
parent a7baeb0d73
commit a478943792
10 changed files with 180 additions and 79 deletions

View File

@@ -14,5 +14,5 @@ public interface ILibraryService
public Task<Result> SaveChannelAsync(InnertubeChannel innertubeChannel, CancellationToken cancellationToken = default);
public Task<Result<LibraryInformation>> GetLibraryInfoAsync(CancellationToken cancellationToken = default);
public Task<ListResult<ClientAccountEntity>> GetAccountsAsync(string? search, int offset = 0, int total = 20, CancellationToken cancellationToken = default);
public Task<ListResult<ChannelEntity>> GetChannelsAsync(int offset = 0, int total = 20, CancellationToken cancellationToken = default);
public Task<ListResult<ChannelEntity>> GetChannelsAsync(string? search, int offset = 0, int total = 20, CancellationToken cancellationToken = default);
}

View File

@@ -151,6 +151,7 @@ public class LibraryService : ILibraryService
var channel = await context.Channels
.Include(c => c.ClientAccount)
.ThenInclude(p => p!.HttpCookies)
.Include(f => f.Files)
.FirstOrDefaultAsync(c => c.Id == id, cancellationToken);
if (channel == null)
@@ -288,13 +289,33 @@ public class LibraryService : ILibraryService
}
}
public async Task<ListResult<ChannelEntity>> GetChannelsAsync(int offset = 0, int total = 20, CancellationToken cancellationToken = default)
public async Task<ListResult<ChannelEntity>> GetChannelsAsync(string? search, int offset = 0, int total = 20, CancellationToken cancellationToken = default)
{
try
{
await using var context = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
var orderedAccounts = context.Channels.Include(x => x.ClientAccount).OrderBy(x => x.Id);
return new ListResultReturn<ChannelEntity>(orderedAccounts.Skip(offset).Take(total).ToList(),orderedAccounts.Count());
var orderedAccounts = context.Channels.OrderBy(x => x.Id);
var totalChannels = orderedAccounts.Count();
if (!string.IsNullOrWhiteSpace(search) && orderedAccounts.Any())
{
var normalizedSearch = $"%{search.ToLower()}%";
var searched = orderedAccounts
.Where(ca =>
EF.Functions.Like(
(
ca.Id.ToString() + " " +
ca.Name + " " +
ca.Handle
).ToLower(),
normalizedSearch
)
);
totalChannels = searched.Count();
orderedAccounts = searched.OrderByDescending(ca => ca.Id);
}
return new ListResultReturn<ChannelEntity>(totalChannels == 0 ? [] : orderedAccounts.Skip(offset).Take(total).ToList(), totalChannels);
}
catch (Exception e)
{