Fixed: Add new modifier category error
This commit is contained in:
parent
4e3362c614
commit
9b55d037f2
@ -42,7 +42,7 @@ def save(
|
|||||||
item = ModifierCategory(
|
item = ModifierCategory(
|
||||||
name=data.name,
|
name=data.name,
|
||||||
minimum=data.minimum,
|
minimum=data.minimum,
|
||||||
maximum=data.maximum,
|
maximum=None if data.maximum == 0 else data.maximum,
|
||||||
is_active=data.is_active,
|
is_active=data.is_active,
|
||||||
)
|
)
|
||||||
db.add(item)
|
db.add(item)
|
||||||
@ -72,7 +72,7 @@ def update(
|
|||||||
item: ModifierCategory = db.query(ModifierCategory).filter(ModifierCategory.id == id_).first()
|
item: ModifierCategory = db.query(ModifierCategory).filter(ModifierCategory.id == id_).first()
|
||||||
item.name = data.name
|
item.name = data.name
|
||||||
item.minimum = data.minimum
|
item.minimum = data.minimum
|
||||||
item.maximum = data.maximum
|
item.maximum = None if data.maximum == 0 else data.maximum
|
||||||
item.is_active = data.is_active
|
item.is_active = data.is_active
|
||||||
add_products(item, data.menu_categories, db)
|
add_products(item, data.menu_categories, db)
|
||||||
db.commit()
|
db.commit()
|
||||||
@ -88,13 +88,13 @@ def update(
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/{id_}", response_model=schemas.ModifierCategoryIn)
|
@router.delete("/{id_}", response_model=schemas.ModifierCategoryBlank)
|
||||||
def delete(
|
def delete(
|
||||||
id_: uuid.UUID,
|
id_: uuid.UUID,
|
||||||
date_: date = Depends(effective_date),
|
date_: date = Depends(effective_date),
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
user: UserToken = Security(get_user, scopes=["modifiers"]),
|
user: UserToken = Security(get_user, scopes=["modifiers"]),
|
||||||
) -> schemas.ModifierCategoryIn:
|
) -> schemas.ModifierCategoryBlank:
|
||||||
try:
|
try:
|
||||||
item: ModifierCategory = db.query(ModifierCategory).filter(ModifierCategory.id == id_).first()
|
item: ModifierCategory = db.query(ModifierCategory).filter(ModifierCategory.id == id_).first()
|
||||||
db.delete(item)
|
db.delete(item)
|
||||||
@ -111,13 +111,13 @@ def delete(
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
@router.get("", response_model=schemas.ModifierCategoryIn)
|
@router.get("", response_model=schemas.ModifierCategoryBlank)
|
||||||
def show_blank(
|
def show_blank(
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
date_: date = Depends(effective_date),
|
date_: date = Depends(effective_date),
|
||||||
user: UserToken = Security(get_user, scopes=["modifiers"]),
|
user: UserToken = Security(get_user, scopes=["modifiers"]),
|
||||||
) -> schemas.ModifierCategoryIn:
|
) -> schemas.ModifierCategoryBlank:
|
||||||
return modifier_category_info(date_, db=db)
|
return modifier_category_blank(date_, db=db)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/list")
|
@router.get("/list")
|
||||||
@ -259,7 +259,7 @@ def modifier_category_info(item: ModifierCategory, date_: date, db: Session) ->
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def modifier_category_blank(date_: date, db: Session) -> schemas.ModifierCategoryIn:
|
def modifier_category_blank(date_: date, db: Session) -> schemas.ModifierCategoryBlank:
|
||||||
menu_categories = (
|
menu_categories = (
|
||||||
db.query(MenuCategory)
|
db.query(MenuCategory)
|
||||||
.join(MenuCategory.products)
|
.join(MenuCategory.products)
|
||||||
@ -282,7 +282,7 @@ def modifier_category_blank(date_: date, db: Session) -> schemas.ModifierCategor
|
|||||||
)
|
)
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
return schemas.ModifierCategoryIn(
|
return schemas.ModifierCategoryBlank(
|
||||||
name="",
|
name="",
|
||||||
minimum=0,
|
minimum=0,
|
||||||
maximum=0,
|
maximum=0,
|
||||||
|
@ -16,7 +16,6 @@ class ModifierCategoryIn(BaseModel):
|
|||||||
menu_categories: Optional[List[MenuCategoryLink]]
|
menu_categories: Optional[List[MenuCategoryLink]]
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
fields = {"id_": "id"}
|
|
||||||
anystr_strip_whitespace = True
|
anystr_strip_whitespace = True
|
||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
|
|
||||||
@ -31,6 +30,14 @@ class ModifierCategory(ModifierCategoryIn):
|
|||||||
alias_generator = to_camel
|
alias_generator = to_camel
|
||||||
|
|
||||||
|
|
||||||
|
class ModifierCategoryBlank(ModifierCategoryIn):
|
||||||
|
name: str
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
anystr_strip_whitespace = True
|
||||||
|
alias_generator = to_camel
|
||||||
|
|
||||||
|
|
||||||
class ModifierCategoryLink(BaseModel):
|
class ModifierCategoryLink(BaseModel):
|
||||||
id_: uuid.UUID = Field(...)
|
id_: uuid.UUID = Field(...)
|
||||||
name: Optional[str]
|
name: Optional[str]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user