mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
dev: Started cleanup of quote commands. Moving logic to the service
This commit is contained in:
@@ -13,7 +13,7 @@ public sealed class QuoteService : IQuoteService, INService
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Delete all quotes created by the author in a guild
|
||||
/// </summary>
|
||||
@@ -24,9 +24,39 @@ public sealed class QuoteService : IQuoteService, INService
|
||||
{
|
||||
await using var ctx = _db.GetDbContext();
|
||||
var deleted = await ctx.GetTable<Quote>()
|
||||
.Where(x => x.GuildId == guildId && x.AuthorId == userId)
|
||||
.DeleteAsync();
|
||||
.Where(x => x.GuildId == guildId && x.AuthorId == userId)
|
||||
.DeleteAsync();
|
||||
|
||||
return deleted;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete all quotes in a guild
|
||||
/// </summary>
|
||||
/// <param name="guildId">ID of the guild</param>
|
||||
/// <returns>Number of deleted qutoes</returns>
|
||||
public async Task<int> DeleteAllQuotesAsync(ulong guildId)
|
||||
{
|
||||
await using var ctx = _db.GetDbContext();
|
||||
var deleted = await ctx.GetTable<Quote>()
|
||||
.Where(x => x.GuildId == guildId)
|
||||
.DeleteAsync();
|
||||
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyCollection<Quote>> GetAllQuotesAsync(ulong guildId, int page, OrderType order)
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
var q = uow.Set<Quote>()
|
||||
.ToLinqToDBTable()
|
||||
.Where(x => x.GuildId == guildId);
|
||||
|
||||
if (order == OrderType.Keyword)
|
||||
q = q.OrderBy(x => x.Keyword);
|
||||
else
|
||||
q = q.OrderBy(x => x.Id);
|
||||
|
||||
return await q.Skip(15 * page).Take(15).ToArrayAsyncLinqToDB();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user