diff --git a/comment/serializers.py b/comment/serializers.py index dcef96a..911c883 100644 --- a/comment/serializers.py +++ b/comment/serializers.py @@ -13,4 +13,10 @@ class CreateCommentSerializer(serializers.Serializer): class CommentSerializer(serializers.ModelSerializer): class Meta: model = Comment - fields = "__all__" + fields = [ + "comprehensive_rating", + "description_rating", + "difficulty_rating", + "content", + "create_time", + ] diff --git a/comment/views/oj.py b/comment/views/oj.py index 3c9a2f1..24c9aa0 100644 --- a/comment/views/oj.py +++ b/comment/views/oj.py @@ -1,11 +1,11 @@ -from django.db.models import Avg, Count +from django.db.models import Avg from django.db.models.functions import Round from comment.models import Comment from problem.models import Problem from utils.api import APIView from account.decorators import login_required from utils.api.api import validate_serializer -from comment.serializers import CreateCommentSerializer +from comment.serializers import CreateCommentSerializer, CommentSerializer from submission.models import Submission, JudgeStatus @@ -50,11 +50,22 @@ class CommentAPI(APIView): 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() + ) + return self.success(CommentSerializer(comment).data) + comments = Comment.objects.select_related("problem").filter( problem_id=problem_id, visible=True ) if comments.count() == 0: return self.success() + count = comments.count() rating = comments.aggregate( description=Round(Avg("description_rating"), 2),