feat: add to_nostr_event for product
This commit is contained in:
parent
62e7d439c7
commit
8ce68f38f6
1 changed files with 22 additions and 0 deletions
22
models.py
22
models.py
|
|
@ -153,6 +153,28 @@ class PartialProduct(BaseModel):
|
||||||
class Product(PartialProduct):
|
class Product(PartialProduct):
|
||||||
id: str
|
id: str
|
||||||
|
|
||||||
|
def to_nostr_event(self, pubkey: str) -> NostrEvent:
|
||||||
|
content = {
|
||||||
|
"stall_id": self.stall_id,
|
||||||
|
"name": self.name,
|
||||||
|
"description": self.description,
|
||||||
|
"image": self.image,
|
||||||
|
"price": self.price,
|
||||||
|
"quantity": self.quantity,
|
||||||
|
}
|
||||||
|
categories = [["t", tag] for tag in self.categories]
|
||||||
|
|
||||||
|
event = NostrEvent(
|
||||||
|
pubkey=pubkey,
|
||||||
|
created_at=round(time.time()),
|
||||||
|
kind=30005,
|
||||||
|
tags=[["d", self.id]] + categories,
|
||||||
|
content=json.dumps(content, separators=(",", ":"), ensure_ascii=False),
|
||||||
|
)
|
||||||
|
event.id = event.event_id
|
||||||
|
|
||||||
|
return event
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_row(cls, row: Row) -> "Product":
|
def from_row(cls, row: Row) -> "Product":
|
||||||
product = cls(**dict(row))
|
product = cls(**dict(row))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue