Fix bugs, add README and Makefile
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
import uuid
|
||||
import enum
|
||||
from datetime import date
|
||||
from typing import Self, List
|
||||
from typing import Any, Self
|
||||
|
||||
import sqlalchemy as sa
|
||||
from pydantic import BaseModel
|
||||
from sqlmodel import SQLModel, Field, Relationship
|
||||
|
||||
from birthday_pool_bot.dto import (
|
||||
BankEnum,
|
||||
PaymentData as DTOPaymentData,
|
||||
Pool as DTOPool,
|
||||
Subscription as DTOSubscription,
|
||||
@@ -46,7 +45,10 @@ class User(BaseSQLModel, table=True):
|
||||
name: str | None = Field(nullable=True)
|
||||
birthday: date | None = Field(nullable=True)
|
||||
phone: str | None = Field(default=None, nullable=True)
|
||||
telegram_id: int | None = Field(default=None, nullable=True)
|
||||
telegram_id: int | None = Field(
|
||||
default=None,
|
||||
sa_column=sa.Column(sa.BigInteger(), nullable=True),
|
||||
)
|
||||
gift_payment_data: dict | None = Field(
|
||||
sa_column=sa.Column(sa.JSON, nullable=True),
|
||||
default_factory=dict,
|
||||
@@ -118,6 +120,12 @@ class Pool(BaseSQLModel, table=True):
|
||||
"lazy": None,
|
||||
},
|
||||
)
|
||||
birthday_user: User = Relationship(
|
||||
sa_relationship_kwargs={
|
||||
"primaryjoin": "User.id == Pool.birthday_user_id",
|
||||
"lazy": None,
|
||||
},
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_item(cls, item: DTOPool) -> Self:
|
||||
@@ -128,6 +136,11 @@ class Pool(BaseSQLModel, table=True):
|
||||
description=item.description,
|
||||
payment_data=item.payment_data.model_dump_json(),
|
||||
owner=None if item.owner is None else DTOUser.from_item(item.owner),
|
||||
birthday_user=(
|
||||
None
|
||||
if item.birthday_user is None else
|
||||
DTOUser.from_item(item.birthday_user)
|
||||
),
|
||||
)
|
||||
|
||||
def to_item(self) -> DTOPool:
|
||||
@@ -137,7 +150,8 @@ class Pool(BaseSQLModel, table=True):
|
||||
birthday_user_id=self.birthday_user_id,
|
||||
description=self.description,
|
||||
payment_data=DTOPaymentData.model_validate_json(self.payment_data),
|
||||
owner=None if self.owner is None else self.owner.to_item()
|
||||
owner=None if self.owner is None else self.owner.to_item(),
|
||||
birthday_user=None if self.birthday_user is None else self.birthday_user.to_item(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user