API 调整
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
from django.urls import re_path as url
|
from django.urls import re_path as url
|
||||||
|
|
||||||
from ..views.oj import CommentAPI
|
from ..views.oj import CommentAPI, CommentStatisticsAPI
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r"^comment/?$", CommentAPI.as_view(), name="comment_api"),
|
url(r"^comment/?$", CommentAPI.as_view(), name="comment_api"),
|
||||||
|
url(r"^comment/statistics?$", CommentStatisticsAPI.as_view(), name="comment_statistics_api"),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -48,18 +48,23 @@ class CommentAPI(APIView):
|
|||||||
)
|
)
|
||||||
return self.success()
|
return self.success()
|
||||||
|
|
||||||
|
@login_required
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
problem_id = request.GET.get("problem_id")
|
problem_id = request.GET.get("problem_id")
|
||||||
my_comment = request.GET.get("my_comment")
|
comment = (
|
||||||
|
Comment.objects.select_related("problem")
|
||||||
if my_comment:
|
.filter(user=request.user, problem_id=problem_id, visible=True)
|
||||||
comment = (
|
.first()
|
||||||
Comment.objects.select_related("problem")
|
)
|
||||||
.filter(user=request.user, problem_id=problem_id, visible=True)
|
if comment:
|
||||||
.first()
|
|
||||||
)
|
|
||||||
return self.success(CommentSerializer(comment).data)
|
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(
|
comments = Comment.objects.select_related("problem").filter(
|
||||||
problem_id=problem_id, visible=True
|
problem_id=problem_id, visible=True
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user