fix foreign keys
This commit is contained in:
parent
47724059bd
commit
ed6c49a1b7
4
Makefile
4
Makefile
@ -16,10 +16,6 @@ start:
|
||||
docker compose down -v db
|
||||
docker compose up --build
|
||||
|
||||
clean-db:
|
||||
docker compose down
|
||||
docker compose down -v db
|
||||
|
||||
clean:
|
||||
rm -rf $(VENV_DIR)
|
||||
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
from pydantic import BaseModel
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
class HouseCreateRequest(BaseModel):
|
||||
address: str
|
||||
city: str
|
||||
country: str
|
||||
price: float
|
||||
description: str
|
||||
address: str = Field(..., min_length=1, max_length=255, description="House address", examples=["123 Main St"])
|
||||
city: str = Field(..., description="City where the house is located", examples=["Springfield"])
|
||||
country: str = Field(..., description="Country where the house is located", examples=["USA"])
|
||||
price: float = Field(..., description="Price of the house", examples=[250000.00])
|
||||
description: str = Field(..., description="Description of the house", examples=["A beautiful 3-bedroom house"])
|
||||
|
||||
|
||||
@ -8,4 +8,4 @@ class House(SQLModel, table=True):
|
||||
country: str = Field()
|
||||
price: float = Field()
|
||||
description: str = Field()
|
||||
owner_id: UUID = Field(foreign_key="owner.id")
|
||||
owner_user_id: UUID = Field(foreign_key="owner.user_id")
|
||||
|
||||
@ -3,4 +3,4 @@ from uuid import uuid4, UUID
|
||||
|
||||
class Owner(SQLModel, table=True):
|
||||
id: UUID = Field(default_factory=uuid4, primary_key=True)
|
||||
user_id: UUID = Field(foreign_key="user.id")
|
||||
user_id: UUID = Field(foreign_key="user.id", unique=True)
|
||||
|
||||
@ -23,7 +23,7 @@ async def create_house(body: HouseCreateRequest, auth: Annotated[AuthContext, De
|
||||
await owner_repository.save(new_owner)
|
||||
|
||||
house = House(
|
||||
owner_id=auth.user.id,
|
||||
owner_user_id=auth.user.id,
|
||||
address=body.address,
|
||||
city=body.city,
|
||||
country=body.country,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user