feat(faq): refine category icons and project faq flows
This commit is contained in:
@@ -14,7 +14,7 @@ async def create_category(db: AsyncSession, category_in: CategoryCreate) -> FaqC
|
||||
name=category_in.name,
|
||||
description=category_in.description,
|
||||
sort_order=category_in.sort_order,
|
||||
is_active=category_in.is_active,
|
||||
icon=category_in.icon,
|
||||
)
|
||||
db.add(category)
|
||||
await db.commit()
|
||||
@@ -26,15 +26,12 @@ async def list_categories(
|
||||
db: AsyncSession,
|
||||
study_id: uuid.UUID | None,
|
||||
include_global: bool = True,
|
||||
is_active: bool | None = True,
|
||||
) -> Sequence[FaqCategory]:
|
||||
stmt = select(FaqCategory)
|
||||
if include_global:
|
||||
stmt = stmt.where((FaqCategory.study_id == study_id) | (FaqCategory.study_id.is_(None)))
|
||||
else:
|
||||
stmt = stmt.where(FaqCategory.study_id == study_id)
|
||||
if is_active is not None:
|
||||
stmt = stmt.where(FaqCategory.is_active == is_active)
|
||||
stmt = stmt.order_by(FaqCategory.sort_order, FaqCategory.name)
|
||||
result = await db.execute(stmt)
|
||||
return result.scalars().all()
|
||||
@@ -59,6 +56,22 @@ async def get_category_by_name(
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
|
||||
async def get_category_by_icon(
|
||||
db: AsyncSession,
|
||||
study_id: uuid.UUID | None,
|
||||
icon: str,
|
||||
) -> FaqCategory | None:
|
||||
if not icon:
|
||||
return None
|
||||
stmt = select(FaqCategory).where(FaqCategory.icon == icon)
|
||||
if study_id is None:
|
||||
stmt = stmt.where(FaqCategory.study_id.is_(None))
|
||||
else:
|
||||
stmt = stmt.where(FaqCategory.study_id == study_id)
|
||||
result = await db.execute(stmt)
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
|
||||
async def update_category(db: AsyncSession, category: FaqCategory, category_in: CategoryUpdate) -> FaqCategory:
|
||||
update_data = category_in.model_dump(exclude_unset=True)
|
||||
if update_data:
|
||||
|
||||
Reference in New Issue
Block a user