.qid cleaned up

This commit is contained in:
Toastie 2024-08-20 14:29:59 +12:00
parent b78f9dfd8c
commit 2e541eebac
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
2 changed files with 9 additions and 11 deletions

View file

@ -106,13 +106,7 @@ public partial class Utility
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task QuoteShow(kwum quoteId) public async Task QuoteShow(kwum quoteId)
{ {
Quote? quote; var quote = await _service.GetQuoteByIdAsync(ctx.Guild.Id, quoteId);
await using (var uow = _db.GetDbContext())
{
quote = uow.Set<Quote>().GetById(quoteId);
if (quote?.GuildId != ctx.Guild.Id)
quote = null;
}
if (quote is null) if (quote is null)
{ {
@ -224,9 +218,9 @@ public partial class Utility
if (quoteId < 0) if (quoteId < 0)
return; return;
var quote = await _service.GetQuoteByIdAsync(quoteId); var quote = await _service.GetQuoteByIdAsync(ctx.Guild.Id, quoteId);
if (quote is null || quote.GuildId != ctx.Guild.Id) if (quote is null)
{ {
await Response().Error(strs.quotes_notfound).SendAsync(); await Response().Error(strs.quotes_notfound).SendAsync();
return; return;

View file

@ -118,9 +118,13 @@ public sealed class QuoteService : IQuoteService, IEService
return count; return count;
} }
public async Task<Quote> GetQuoteByIdAsync(kwum quoteId) public async Task<Quote?> GetQuoteByIdAsync(ulong guildId, kwum quoteId)
{ {
await using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
return uow.Set<Quote>().GetById(quoteId);
var quote = await uow.GetTable<Quote>()
.Where(x => x.Id == quoteId && x.GuildId == guildId)
.FirstAsyncLinqToDB();
return quote;
} }
} }