upload project source code
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.common.response import SuccessResponse
|
||||
from app.core.dependencies import db_getter, get_current_user
|
||||
from app.api.v1.module_system.auth.schema import AuthSchema
|
||||
from app.api.v1.module_common.activity.crud import ActivityCRUD
|
||||
|
||||
# 定义路由前缀
|
||||
ActivityRouter = APIRouter(prefix="/activity", tags=["活动记录"])
|
||||
|
||||
|
||||
@ActivityRouter.get("/display", summary="获取活动展示列表", description="获取前端展示格式的用户活动记录(无需登录)")
|
||||
async def get_activity_display(
|
||||
limit: int = 10,
|
||||
db: AsyncSession = Depends(db_getter)
|
||||
) -> SuccessResponse:
|
||||
"""
|
||||
获取活动展示列表(公开接口,无需登录)
|
||||
|
||||
返回格式: ["张** 预约了 宝宝起名 服务", "李** 完成了 个人改名 测算", ...]
|
||||
"""
|
||||
# 创建一个不需要用户信息的 auth 对象
|
||||
auth = AuthSchema(db=db, check_data_scope=False)
|
||||
crud = ActivityCRUD(auth)
|
||||
|
||||
data = await crud.get_display_list(limit=limit)
|
||||
return SuccessResponse(data=data)
|
||||
|
||||
|
||||
@ActivityRouter.post("/create", summary="创建活动记录", description="创建活动记录(需要登录)")
|
||||
async def create_activity(
|
||||
user_name: str,
|
||||
action: str,
|
||||
service_name: str,
|
||||
service_type: str = None,
|
||||
sort_order: int = 0,
|
||||
auth: AuthSchema = Depends(get_current_user)
|
||||
) -> SuccessResponse:
|
||||
"""
|
||||
创建活动记录(需要登录)
|
||||
"""
|
||||
crud = ActivityCRUD(auth)
|
||||
|
||||
data = {
|
||||
"user_name": user_name,
|
||||
"action": action,
|
||||
"service_name": service_name,
|
||||
"service_type": service_type,
|
||||
"sort_order": sort_order
|
||||
}
|
||||
|
||||
result = await crud.create(data)
|
||||
return SuccessResponse(data={"id": result.id}, msg="创建成功")
|
||||
Reference in New Issue
Block a user