From 145797076da57587224ebf0dc218dbedd78b4661 Mon Sep 17 00:00:00 2001 From: yuetsh <51725939@qq.com> Date: Mon, 1 Jul 2024 01:23:32 +0800 Subject: [PATCH] =?UTF-8?q?API=20=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comment/urls/oj.py | 3 ++- comment/views/oj.py | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/comment/urls/oj.py b/comment/urls/oj.py index 6f12edb..a25f075 100644 --- a/comment/urls/oj.py +++ b/comment/urls/oj.py @@ -1,8 +1,9 @@ from django.urls import re_path as url -from ..views.oj import CommentAPI +from ..views.oj import CommentAPI, CommentStatisticsAPI urlpatterns = [ url(r"^comment/?$", CommentAPI.as_view(), name="comment_api"), + url(r"^comment/statistics?$", CommentStatisticsAPI.as_view(), name="comment_statistics_api"), ] diff --git a/comment/views/oj.py b/comment/views/oj.py index 24c9aa0..31a9dc0 100644 --- a/comment/views/oj.py +++ b/comment/views/oj.py @@ -48,18 +48,23 @@ class CommentAPI(APIView): ) return self.success() + @login_required def get(self, request): problem_id = request.GET.get("problem_id") - my_comment = request.GET.get("my_comment") - - if my_comment: - comment = ( - Comment.objects.select_related("problem") - .filter(user=request.user, problem_id=problem_id, visible=True) - .first() - ) + comment = ( + Comment.objects.select_related("problem") + .filter(user=request.user, problem_id=problem_id, visible=True) + .first() + ) + if comment: return self.success(CommentSerializer(comment).data) + else: + return self.success() + +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 )