feat(user): 新增用户信息(访问者)返回是否关注is_follow CRUD同步新增exists方法
This commit is contained in:
@@ -18,7 +18,6 @@ from core.routers.auth.schema import LoginUser
|
||||
from core.routers.auth.services import get_current_user_form_http
|
||||
|
||||
from . import schema
|
||||
from .schema import UpdateUserIn
|
||||
|
||||
user_router = APIRouter(prefix='/user', tags=['用户模块'])
|
||||
|
||||
@@ -45,7 +44,7 @@ async def get_me_info(
|
||||
@user_router.get(
|
||||
'/visit/{user_id}/info',
|
||||
summary='用户信息(访问者)',
|
||||
response_model=base_schema.BaseResponse[schema.LiteUser]
|
||||
response_model=base_schema.BaseResponse[schema.VisitUser]
|
||||
)
|
||||
async def get_visit_user_info(
|
||||
user_id: int,
|
||||
@@ -59,6 +58,22 @@ async def get_visit_user_info(
|
||||
user = await db_crud.get(filters={'user_id': user_id})
|
||||
if user is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail='访问用户不存在')
|
||||
|
||||
user.is_follow = await db_crud.exists(
|
||||
model=UserFollows,
|
||||
filters={
|
||||
'follower_id': login_user.user_id,
|
||||
'followed_id': user_id
|
||||
}
|
||||
)
|
||||
|
||||
user.displayed_card_total = await db_crud.total(
|
||||
model=UserCollection,
|
||||
filters={
|
||||
'user_id': user.user_id,
|
||||
'displayed': True}
|
||||
)
|
||||
|
||||
return {'data': user}
|
||||
|
||||
|
||||
@@ -136,12 +151,10 @@ async def follow_user(
|
||||
if follower_user is None:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail='被关注者不存在')
|
||||
|
||||
user: User | None = await db_crud.get(filters={'user_id': login_user.user_id})
|
||||
|
||||
db_crud = CRUD(db_session, UserFollows)
|
||||
record = {
|
||||
'follower_id': login_user.user_id,
|
||||
'followed_id': user.user_id,
|
||||
'followed_id': follower_user.user_id,
|
||||
}
|
||||
if action == 'follower':
|
||||
await db_crud.create(data=record, filters=record)
|
||||
|
||||
@@ -30,6 +30,10 @@ class LiteUser(BaseModel):
|
||||
gender: Optional[int] = None
|
||||
avatar_url: Optional[str] = None
|
||||
vip_expire_date: Optional[date] = None
|
||||
|
||||
|
||||
class VisitUser(LiteUser):
|
||||
is_follow: Optional[bool] = False
|
||||
displayed_card_total: Optional[int] = 0
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user