mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 17:58:26 -04:00
dev: added quote api
This commit is contained in:
@@ -26,6 +26,8 @@ public interface IQuoteService
|
||||
ulong guildId,
|
||||
string? keyword,
|
||||
string text);
|
||||
|
||||
Task<(IReadOnlyCollection<Quote> quotes, int totalCount)> FindQuotesAsync(ulong guildId, string query, int page);
|
||||
|
||||
Task<IReadOnlyCollection<Quote>> GetGuildQuotesAsync(ulong guildId);
|
||||
Task<int> RemoveAllByKeyword(ulong guildId, string keyword);
|
||||
@@ -39,6 +41,7 @@ public interface IQuoteService
|
||||
string text);
|
||||
|
||||
Task<Quote?> EditQuoteAsync(ulong authorId, int quoteId, string text);
|
||||
Task<Quote?> EditQuoteAsync(ulong guildId, int quoteId, string keyword, string text);
|
||||
|
||||
Task<bool> DeleteQuoteAsync(
|
||||
ulong guildId,
|
||||
|
@@ -169,6 +169,23 @@ public sealed class QuoteService : IQuoteService, INService
|
||||
return q;
|
||||
}
|
||||
|
||||
public async Task<Quote?> EditQuoteAsync(
|
||||
ulong guildId,
|
||||
int quoteId,
|
||||
string keyword,
|
||||
string text)
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
var result = await uow.GetTable<Quote>()
|
||||
.Where(x => x.Id == quoteId && x.GuildId == guildId)
|
||||
.Set(x => x.Keyword, keyword)
|
||||
.Set(x => x.Text, text)
|
||||
.UpdateWithOutputAsync((del, ins) => ins);
|
||||
|
||||
var q = result.FirstOrDefault();
|
||||
return q;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteQuoteAsync(
|
||||
ulong guildId,
|
||||
ulong authorId,
|
||||
@@ -219,4 +236,24 @@ public sealed class QuoteService : IQuoteService, INService
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task<(IReadOnlyCollection<Quote> quotes, int totalCount)> FindQuotesAsync(
|
||||
ulong guildId,
|
||||
string query,
|
||||
int page)
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
|
||||
var baseQuery = uow.GetTable<Quote>()
|
||||
.Where(x => x.GuildId == guildId)
|
||||
.Where(x => x.Keyword.Contains(query) || x.Text.Contains(query));
|
||||
|
||||
var quotes = await baseQuery
|
||||
.OrderBy(x => x.Id)
|
||||
.Skip((page - 1) * 10)
|
||||
.Take(10)
|
||||
.ToListAsyncLinqToDB();
|
||||
|
||||
return (quotes, await baseQuery.CountAsyncLinqToDB());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user