diff --git a/contest/serializers.py b/contest/serializers.py index 356cddae..c9f28950 100644 --- a/contest/serializers.py +++ b/contest/serializers.py @@ -106,3 +106,9 @@ class ACMContesHelperSerializer(serializers.Serializer): problem_id = serializers.CharField() rank_id = serializers.IntegerField() checked = serializers.BooleanField() + + +class ContestSimilarResultSerializer(serializers.ModelSerializer): + class Meta: + model = Contest + fields = ["similarity_check_result"] diff --git a/contest/tests.py b/contest/tests.py index 8a21977d..9c0628fe 100644 --- a/contest/tests.py +++ b/contest/tests.py @@ -63,6 +63,8 @@ class ContestAPITest(APITestCase): def setUp(self): user = self.create_admin() self.contest = Contest.objects.create(created_by=user, **DEFAULT_CONTEST_DATA) + self.contest.similarity_check_result = ["aaa", "bbb", "ccc"] + self.contest.save() self.url = self.reverse("contest_api") + "?id=" + str(self.contest.id) def test_get_contest_list(self): @@ -97,6 +99,12 @@ class ContestAPITest(APITestCase): resp = self.client.get(self.url) self.assertSuccess(resp) + def test_regular_user_get_similiar(self): + self.create_user("test", "test123") + url = self.reverse("contest_get_similar_api") + resp = self.client.get(url + "?contest_id=" + str(self.contest.id)) + self.assertEqual(resp.data["data"]["similarity_check_result"], ["aaa", "bbb", "ccc"]) + class ContestAnnouncementAdminAPITest(APITestCase): def setUp(self): diff --git a/contest/views/oj.py b/contest/views/oj.py index 376c6867..ce35ea31 100644 --- a/contest/views/oj.py +++ b/contest/views/oj.py @@ -17,6 +17,7 @@ from ..models import ContestAnnouncement, Contest, OIContestRank, ACMContestRank from ..serializers import ContestAnnouncementSerializer from ..serializers import ContestSerializer, ContestPasswordVerifySerializer from ..serializers import OIContestRankSerializer, ACMContestRankSerializer +from ..serializers import ContestSimilarResultSerializer class ContestAnnouncementListAPI(APIView): @@ -189,4 +190,6 @@ class ContestRankAPI(APIView): class ContestGetSimilarAPI(APIView): def get(self, request): - return self.success() + contest_id = request.GET.get("contest_id") + contest = Contest.objects.get(id=contest_id, visible=True) + return self.success(ContestSimilarResultSerializer(contest).data)