[CHANGE] Fixed storing account/channel
This commit is contained in:
@@ -61,7 +61,7 @@ public class LibraryService : ILibraryService
|
||||
{
|
||||
foreach (var image in images)
|
||||
{
|
||||
if (context.Files.Any(f => image.Url.Equals(f.OriginalUrl, StringComparison.OrdinalIgnoreCase)))
|
||||
if (context.Files.Any(f => image.Url.Equals(f.OriginalUrl)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -108,7 +108,7 @@ public class LibraryService : ILibraryService
|
||||
await using var context = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||
|
||||
var updateEntity = false;
|
||||
var dbClient = context.ClientAccounts.FirstOrDefault(c => c.Id == client.Id);
|
||||
var dbClient = context.ClientAccounts.Include(ca => ca.HttpCookies).FirstOrDefault(c => c.Id == client.Id);
|
||||
if (dbClient == null)
|
||||
{
|
||||
dbClient = client;
|
||||
@@ -245,13 +245,55 @@ public class LibraryService : ILibraryService
|
||||
return HandleException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ListResult<ClientAccountEntity>> GetAccountsAsync(string? search, int offset = 0, int total = 20, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (total == 0)
|
||||
{
|
||||
total = 20;
|
||||
}
|
||||
|
||||
public async Task<ListResult<ChannelEntity>> GetChannelsAsync(int total = 20, int offset = 0, CancellationToken cancellationToken = default)
|
||||
try
|
||||
{
|
||||
await using var context = await _dbContextFactory.CreateDbContextAsync(cancellationToken);
|
||||
var accounts = context.ClientAccounts
|
||||
.Include(ca => ca.Channel)
|
||||
.Include(ca => ca.HttpCookies)
|
||||
.OrderByDescending(ca => ca.Id);
|
||||
var totalAccounts = accounts.Count();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(search) && totalAccounts != 0)
|
||||
{
|
||||
var normalizedSearch = $"%{search.ToLower()}%";
|
||||
var searched = accounts
|
||||
.Where(ca =>
|
||||
EF.Functions.Like(
|
||||
(
|
||||
ca.Id.ToString() + " " +
|
||||
(ca.Channel != null ? ca.Channel.Name : "") + " " +
|
||||
(ca.Channel != null ? ca.Channel.Handle : "")
|
||||
).ToLower(),
|
||||
normalizedSearch
|
||||
)
|
||||
);
|
||||
totalAccounts = searched.Count();
|
||||
accounts = searched.OrderByDescending(ca => ca.Id);
|
||||
}
|
||||
|
||||
return new ListResultReturn<ClientAccountEntity>(totalAccounts == 0 ? [] : accounts.Skip(offset).Take(total).ToList(), totalAccounts);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return ResultError.Error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ListResult<ChannelEntity>> GetChannelsAsync(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).Where(x => x.ClientAccount != null).OrderBy(x => x.Id);
|
||||
var orderedAccounts = context.Channels.Include(x => x.ClientAccount).OrderBy(x => x.Id);
|
||||
return new ListResultReturn<ChannelEntity>(orderedAccounts.Skip(offset).Take(total).ToList(),orderedAccounts.Count());
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
Reference in New Issue
Block a user