feat(auth、user):新增用户的粉丝数、关注数、简介

This commit is contained in:
xingc
2025-10-16 15:28:07 +08:00
parent cddb0ab0dd
commit 0cf3145e86
5 changed files with 99 additions and 11 deletions

View File

@@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
# @File: actions.py
# @Date: 2025/10/15 18:58
# @Software: PyCharm
# @Author: xingc
# @Desc:
import logging
from sqlalchemy.ext.asyncio import AsyncSession
from core.db.crud import CRUD
from core.db.engine import async_db_session
from core.db.models import User, UserFollows
logger = logging.getLogger(__name__)
async def update_user_follower_total(
follower_id: int,
followed_id: int,
db_session: AsyncSession
):
"""
更新用户计数
:param follower_id: 关注者id
:param followed_id: 被关注者id
:param db_session:
:return:
"""
db_crud = CRUD(db_session, UserFollows)
# 更新关注数
followers_count = await db_crud.total(
filters={
'follower_id': follower_id,
'followed_id': followed_id,
}
)
await db_crud.update(
model=User,
data={
'followers_count': followers_count,
},
filters={
'user_id': follower_id,
}
)
# 更新粉丝数
fans_count = await db_crud.total(
filters={
'followed_id': followed_id,
}
)
await db_crud.update(
model=User,
data={
'fans_count': fans_count,
},
filters={
'user_id': followed_id,
}
)