feat(C-06):关注feed+课程聚合修复

文章列表新增author_user_id/is_following与feed=following过滤;课程students_count改真实在学人数去重统计、新增total_minutes(不可解析不伪造);author_name走sync_to_async防ASGI同步阻塞。
This commit is contained in:
chunyu
2026-09-15 15:20:23 +08:00
parent 1e95db0bda
commit 37cad3947d
7 changed files with 264 additions and 11 deletions
+12
View File
@@ -77,6 +77,17 @@ class ArticleListCreateView(generics.ListCreateAPIView):
Q(tags__overlap=[search])
)
# 关注 feed:仅返回当前用户关注作者的文章
feed = self.request.query_params.get('feed')
if feed == 'following':
if not self.request.user.is_authenticated:
return Article.objects.none()
from user.models import Follow
followed_ids = Follow.objects.filter(
follower=self.request.user
).values_list('following_id', flat=True)
qs = qs.filter(author_id__in=followed_ids)
ordering = self.request.query_params.get('ordering', '-created_at')
return qs.order_by('-is_top', ordering)
@@ -94,6 +105,7 @@ class ArticleListCreateView(generics.ListCreateAPIView):
openapi.Parameter('category', openapi.IN_QUERY, description='文章分类筛选', type=openapi.TYPE_STRING),
openapi.Parameter('tag', openapi.IN_QUERY, description='文章标签筛选', type=openapi.TYPE_STRING),
openapi.Parameter('search', openapi.IN_QUERY, description='搜索关键词(标题、摘要、标签)', type=openapi.TYPE_STRING),
openapi.Parameter('feed', openapi.IN_QUERY, description='feed=following 时仅返回当前用户关注作者的文章(需登录)', type=openapi.TYPE_STRING),
openapi.Parameter('ordering', openapi.IN_QUERY, description='排序方式,默认 -created_at', type=openapi.TYPE_STRING),
openapi.Parameter('page', openapi.IN_QUERY, description='页码', type=openapi.TYPE_INTEGER),
openapi.Parameter('page_size', openapi.IN_QUERY, description='每页数量,默认10,最大100', type=openapi.TYPE_INTEGER),