Minor tweaks to sign up on frontend and database structure

This commit is contained in:
Thastertyn committed 2025-03-17 19:27:09 +01:00
1 parent d0690f2f06
commit 260bef98cd
10 files changed
+56 -1037

No files matched your search

+11 -3
View File
@@ -1,18 +1,26 @@
from typing import Optional
from fastapi import APIRouter
from app.api.dependencies import CurrentOwnerUser, SessionDep
from app.crud.shop_crud import create_shop
from app.schemas.shop_schemas import ShopCreate
from app.schemas.user_schemas import Token
from app.schemas.shop_schemas import ShopCreate, ShopPublic
router = APIRouter(prefix="/shop", tags=["Dashboard"])
@router.post("", status_code=201)
def register_new_shop(
async def register_new_shop(
session: SessionDep,
current_user: CurrentOwnerUser,
shop_data: ShopCreate
) -> bool:
create_shop(session, shop_data, current_user)
return True
@router.get("")
async def get_owned_shop_info(
current_user: CurrentOwnerUser
) -> Optional[ShopPublic]:
return current_user.owned_shop
+1 -1
View File
@@ -31,7 +31,7 @@ def create_shop(session: Session, shop_data: ShopCreate, creator: User) -> None:
description=shop_data.description,
status=ShopStatus.INACTIVE,
contact_email=creator.email,
phone_number=creator.phone_number,
contact_phone_number=creator.phone_number,
currency=shop_data.currency
)
session.add(new_shop)
+18 -18
View File
@@ -21,7 +21,7 @@ class ShopLinkEntry(BaseModel):
class ShopLinks(BaseModel):
links: list[ShopLinkEntry]
links: list[ShopLinkEntry] = []
class ShopBusinessHourEntry(BaseModel):
@@ -31,15 +31,15 @@ class ShopBusinessHourEntry(BaseModel):
class ShopBusinessHours(BaseModel):
hours: list[ShopBusinessHourEntry]
hours: list[ShopBusinessHourEntry] = []
class ShopAddress(SQLModel):
street: str = Field(max_length=255, nullable=False)
city: str = Field(max_length=100, nullable=False)
state: str = Field(max_length=100, nullable=True)
postal_code: str = Field(max_length=20, nullable=False)
country: str = Field(max_length=100, nullable=False)
street: str = Field(default="", max_length=255, nullable=False)
city: str = Field(default="", max_length=100, nullable=False)
state: Optional[str] = Field(default=None, max_length=100, nullable=True)
postal_code: str = Field(default="", max_length=20, nullable=False)
country: str = Field(default="", max_length=100, nullable=False)
class Shop(SQLModel, table=True):
@@ -55,13 +55,19 @@ class Shop(SQLModel, table=True):
status: ShopStatus = Field(sa_column=Column(Enum(ShopStatus)))
logo: Optional[str] = Field(max_length=100)
contact_email: str = Field(max_length=128, nullable=False, unique=True)
phone_number: str = Field(max_length=15, nullable=False)
address: ShopAddress = Field(sa_column=Column(JSONB, nullable=False, default=lambda: {}))
business_hours: ShopBusinessHours = Field(sa_column=Column(JSONB, nullable=False, default=lambda: {}))
links: ShopLinks = Field(sa_column=Column(JSONB, nullable=False, default=lambda: {}))
contact_phone_number: str = Field(max_length=15, nullable=False)
address: ShopAddress = Field(
sa_column=Column(JSONB, nullable=False, default=lambda: ShopAddress().dict())
)
business_hours: ShopBusinessHours = Field(
sa_column=Column(JSONB, nullable=False, default=lambda: ShopBusinessHours().dict())
)
links: ShopLinks = Field(
sa_column=Column(JSONB, nullable=False, default=lambda: ShopLinks().dict())
)
currency: str = Field(max_length=3, nullable=False)
owner: Optional["User"] = Relationship(
owner: "User" = Relationship(
back_populates='owned_shop',
sa_relationship_kwargs={"foreign_keys": "[Shop.owner_id]"}
)
@@ -71,11 +77,5 @@ class Shop(SQLModel, table=True):
sa_relationship_kwargs={"foreign_keys": "[User.shop_id]"}
)
# __table_args__ = (
# CheckConstraint("business_hours ? 'hours'", name="check_business_hours_keys"),
# CheckConstraint("links ? 'links'", name="check_links_keys"),
# CheckConstraint("address ? 'address'", name="check_address_keys")
# )
__all__ = ["Shop", "ShopBusinessHours", "ShopLinks", "ShopStatus"]
+1 -1
View File
@@ -31,7 +31,7 @@ class User(SQLModel, table=True):
password: str = Field(max_length=60, nullable=False)
first_name: Optional[str] = Field(max_length=64)
last_name: Optional[str] = Field(max_length=64)
phone_number: str = Field(max_length=15, nullable=False)
phone_number: str = Field(max_length=16, nullable=False)
profile_picture: Optional[str] = Field(max_length=100)
created_at: datetime = Field(default_factory=datetime.utcnow, nullable=False)
updated_at: datetime = Field(default_factory=datetime.utcnow, nullable=False)
+18 -5
View File
@@ -1,14 +1,27 @@
from pydantic import EmailStr
from sqlmodel import Field, SQLModel
from datetime import datetime
from pydantic import EmailStr, BaseModel, Field
from sqlmodel import SQLModel
from app.database.models.shop_model import ShopAddress
from app.database.models.shop_model import ShopAddress, ShopStatus, ShopBusinessHours, ShopLinks
class ShopCreate(SQLModel):
class ShopCreate(BaseModel):
name: str = Field(max_length=100, nullable=False, unique=True)
description: str = Field(max_length=500, nullable=False)
currency: str = Field(max_length=3, nullable=False)
contact_email: EmailStr = Field()
contact_phone_number: str = Field(min_length=2, max_length=16, schema_extra={"pattern": r'^\+[1-9]\d{1,14}$'})
contact_phone_number: str = Field(min_length=2, max_length=16, pattern=r'^\+[1-9]\d{1,14}$')
address: ShopAddress
class ShopPublic(BaseModel):
name: str
description: str
currency: str
contact_email: EmailStr
contact_phone_number: str
address: ShopAddress
business_hours: ShopBusinessHours
links: ShopLinks
status: ShopStatus