Implement quotes.

This commit is contained in:
2025-08-28 15:42:53 +10:00
parent 45e6ed4e29
commit d9fa5c4683
9 changed files with 496 additions and 28 deletions

View File

@@ -1,5 +1,6 @@
from typing import Optional
from .data import Quote, QuoteInfo, QuotesData
from .lib import utc_now
class QuoteRegistry:
@@ -13,7 +14,7 @@ class QuoteRegistry:
await self.data.init()
async def get_community_quotes(self, communityid: int) -> list[QuoteInfo]:
return await QuoteInfo.fetch_where(communityid=communityid)
return await QuoteInfo.fetch_where(communityid=communityid, is_deleted=False)
async def get_quoteinfo(self, quoteid: int) -> Optional[QuoteInfo]:
return await QuoteInfo.fetch(quoteid)
@@ -22,7 +23,7 @@ class QuoteRegistry:
return await Quote.fetch(quoteid)
async def get_quote_label(self, communityid: int, label: int) -> Optional[QuoteInfo]:
results = await QuoteInfo.fetch_where(communityid=communityid, quotelabel=label)
results = await QuoteInfo.fetch_where(communityid=communityid, quotelabel=label, is_deleted=False)
return results[0] if results else None
async def create_quote(
@@ -39,3 +40,6 @@ class QuoteRegistry:
info = await QuoteInfo.fetch(quote.quoteid)
assert info is not None
return info
async def delete_quote(self, quoteid: int):
await self.data.quotes.update_where(quoteid=quoteid).set(deleted_at=utc_now())