Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add profileSubmissionListAPI in Profile Page #308

Merged
merged 15 commits into from
Mar 1, 2022
18 changes: 18 additions & 0 deletions backend/submission/migrations/0014_submission_code_length.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.12 on 2022-02-10 10:37

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('submission', '0013_auto_20211030_1535'),
]

operations = [
migrations.AddField(
model_name='submission',
name='code_length',
field=models.IntegerField(default=0),
),
]
18 changes: 18 additions & 0 deletions backend/submission/migrations/0015_submission_title.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.12 on 2022-02-11 07:18

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('submission', '0014_submission_code_length'),
]

operations = [
migrations.AddField(
model_name='submission',
name='title',
field=models.TextField(null=True),
),
]
2 changes: 2 additions & 0 deletions backend/submission/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ class Submission(models.Model):
id = models.TextField(default=rand_str, primary_key=True, db_index=True)
contest = models.ForeignKey(Contest, null=True, on_delete=models.CASCADE)
problem = models.ForeignKey(Problem, on_delete=models.CASCADE)
title = models.TextField(null=True)
create_time = models.DateTimeField(auto_now_add=True)
user_id = models.IntegerField(db_index=True)
username = models.TextField()
code = models.TextField()
code_length = models.IntegerField(default=0)
result = models.IntegerField(db_index=True, default=JudgeStatus.PENDING)
# Judgment details returned from JudgeServer
info = JSONField(default=dict)
Expand Down
3 changes: 2 additions & 1 deletion backend/submission/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from django.urls import path

from .views import SubmissionAPI, SubmissionListAPI, ContestSubmissionListAPI, SubmissionExistsAPI
from .views import ProfileSubmissionListAPI, SubmissionAPI, SubmissionListAPI, ContestSubmissionListAPI, SubmissionExistsAPI

urlpatterns = [
path("submission/", SubmissionAPI.as_view(), name="submission_api"),
path("submissions/", SubmissionListAPI.as_view(), name="submission_list_api"),
path("submission_exists/", SubmissionExistsAPI.as_view(), name="submission_exists"),
path("contest_submissions/", ContestSubmissionListAPI.as_view(), name="contest_submission_list_api"),
path("profile_submissions/", ProfileSubmissionListAPI.as_view(), name="profile_submission_list_api"),
]
22 changes: 22 additions & 0 deletions backend/submission/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# from judge.dispatcher import JudgeDispatcher
from problem.models import Problem, ProblemRuleType
from account.models import User, AdminType
from django.db.models import Q
from utils.api import APIView, validate_serializer
from utils.cache import cache
from utils.captcha import Captcha
Expand Down Expand Up @@ -70,7 +71,9 @@ def post(self, request):
username=request.user.username,
language=data["language"],
code=data["code"],
code_length=len(data["code"].encode("utf-8")),
problem_id=problem.id,
title=problem.title,
ip=request.session["ip"],
contest_id=data.get("contest_id"))
# use this for debug
Expand Down Expand Up @@ -312,3 +315,22 @@ def get(self, request):
return self.success(request.user.is_authenticated and
Submission.objects.filter(problem_id=request.GET["problem_id"],
user_id=request.user.id).exists())


class ProfileSubmissionListAPI(APIView):
def get(self, request):
submissions = Submission.objects.filter(user_id=request.user.id)
# keyword search, 문제 번호로 검색 안됨
keyword = request.GET.get("keyword", "").strip()
if keyword:
submissions = submissions.filter(Q(title__icontains=keyword))
# result search
result = request.GET.get("result")
if result:
if result == "AC":
submissions = submissions.filter(result=0)
elif result == "NAC":
submissions = submissions.exclude(result=0)
data = self.paginate_data(request, submissions)
data["results"] = SubmissionListSerializer(data["results"], many=True, user=request.user).data
return self.success(data)
1 change: 1 addition & 0 deletions frontend/skku-coding-platform
Submodule skku-coding-platform added at 62983c
7 changes: 7 additions & 0 deletions frontend/src/pages/oj/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ export default {
params
})
},
getProfileSubmissionList (offset, limit, params) {
params.limit = limit
params.offset = offset
return ajax('profile_submissions/', 'get', {
params
})
},
getSubmission (id) {
return ajax('submission/', 'get', {
params: {
Expand Down
Loading