添加f评论API

This commit is contained in:
2024-07-02 21:12:06 +08:00
parent 77cf8db4c4
commit ee10972d6e
7 changed files with 65 additions and 3 deletions

29
comment/views/admin.py Normal file
View File

@@ -0,0 +1,29 @@
from account.decorators import super_admin_required
from comment.serializers import CommentListSerializer
from problem.models import Problem
from utils.api import APIView
from comment.models import Comment
class CommentAPI(APIView):
@super_admin_required
def get(self, request):
comments = Comment.objects.select_related("problem").exclude(content="")
problem_id = request.GET.get("problem_id")
if problem_id:
try:
# 这里如果题目不可见,也需要显示该题目的评论
problem = Problem.objects.get(_id=problem_id, contest_id__isnull=True)
except Problem.DoesNotExist:
return self.error("Problem doesn't exist")
comments = comments.filter(problem=problem)
return self.success(
self.paginate_data(request, comments, CommentListSerializer)
)
@super_admin_required
def delete(self, request):
id = request.GET.get("id")
if id:
Comment.objects.filter(id=id).delete()
return self.success()

View File

@@ -53,7 +53,7 @@ class CommentAPI(APIView):
problem_id = request.GET.get("problem_id")
comment = (
Comment.objects.select_related("problem")
.filter(user=request.user, problem_id=problem_id, visible=True)
.filter(user=request.user, problem_id=problem_id)
.first()
)
if comment:
@@ -66,7 +66,7 @@ class CommentStatisticsAPI(APIView):
def get(self, request):
problem_id = request.GET.get("problem_id")
comments = Comment.objects.select_related("problem").filter(
problem_id=problem_id, visible=True
problem_id=problem_id
)
if comments.count() == 0:
return self.success()