[ADD] Simple views for accounts and channels
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user