39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
import logging
|
|
from typing import Optional
|
|
from uuid import uuid4
|
|
|
|
from sqlmodel import Session, select
|
|
|
|
from app.database.models.shop_model import Shop, ShopStatus
|
|
from app.database.models.user_model import User
|
|
from app.schemas.shop_schemas import ShopCreate
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
def get_shop_by_id(session: Session, shop_id: int) -> Optional[Shop]:
|
|
logger.debug("Getting shop by shop_id - %d", id)
|
|
stmt = select(Shop).where(Shop.id == shop_id)
|
|
db_shop = session.exec(stmt).one_or_none()
|
|
return db_shop
|
|
|
|
def get_shop_by_uuid(session: Session, shop_uuid: str) -> Optional[Shop]:
|
|
logger.debug("Getting shop by UUID - %s" , shop_uuid)
|
|
stmt = select(Shop).where(Shop.uuid == shop_uuid)
|
|
db_shop = session.exec(stmt).one_or_none()
|
|
return db_shop
|
|
|
|
def create_shop(session: Session, shop_data: ShopCreate, creator: User) -> None:
|
|
shop_uuid = uuid4()
|
|
new_shop = Shop(
|
|
uuid=shop_uuid,
|
|
owner_id=creator.id,
|
|
name=shop_data.name,
|
|
description=shop_data.description,
|
|
status=ShopStatus.INACTIVE,
|
|
contact_email=creator.email,
|
|
contact_phone_number=creator.phone_number,
|
|
currency=shop_data.currency
|
|
)
|
|
session.add(new_shop)
|
|
session.commit()
|