From 98aeec397e26ef0a38c9f94208e13e98f5632708 Mon Sep 17 00:00:00 2001 From: minseo999 Date: Sun, 26 Dec 2021 16:36:15 +0900 Subject: [PATCH] [Student] Add bookmark course API - add bookmark field to Registration model - edit CourseAPI for bookmark course list --- .../migrations/0018_auto_20211226_1458.py | 38 +++++++++++++ .../migrations/0004_alter_announcement_id.py | 2 +- .../migrations/0002_alter_assignment_id.py | 18 +++++++ .../migrations/0005_alter_judgeserver_id.py | 2 +- .../migrations/0011_auto_20211226_1458.py | 48 +++++++++++++++++ .../migrations/0003_auto_20211226_1458.py | 23 ++++++++ .../migrations/0004_registration_bookmark.py | 18 +++++++ backend/course/models.py | 1 + backend/course/serializers.py | 6 ++- backend/course/urls/student.py | 3 +- backend/course/views/student.py | 38 ++++++++++++- .../migrations/0004_auto_20211226_1458.py | 23 ++++++++ .../migrations/0018_auto_20211226_1458.py | 54 +++++++++++++++++++ .../migrations/0016_auto_20211226_1458.py | 23 ++++++++ 14 files changed, 291 insertions(+), 6 deletions(-) create mode 100644 backend/account/migrations/0018_auto_20211226_1458.py create mode 100644 backend/assignment/migrations/0002_alter_assignment_id.py create mode 100644 backend/contest/migrations/0011_auto_20211226_1458.py create mode 100644 backend/course/migrations/0003_auto_20211226_1458.py create mode 100644 backend/course/migrations/0004_registration_bookmark.py create mode 100644 backend/options/migrations/0004_auto_20211226_1458.py create mode 100644 backend/problem/migrations/0018_auto_20211226_1458.py create mode 100644 backend/submission/migrations/0016_auto_20211226_1458.py diff --git a/backend/account/migrations/0018_auto_20211226_1458.py b/backend/account/migrations/0018_auto_20211226_1458.py new file mode 100644 index 000000000..908339cce --- /dev/null +++ b/backend/account/migrations/0018_auto_20211226_1458.py @@ -0,0 +1,38 @@ +# Generated by Django 3.2.5 on 2021-12-26 05:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('account', '0017_auto_20210703_1612'), + ] + + operations = [ + migrations.AlterField( + model_name='user', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='user', + name='session_keys', + field=models.JSONField(default=list), + ), + migrations.AlterField( + model_name='userprofile', + name='acm_problems_status', + field=models.JSONField(default=dict), + ), + migrations.AlterField( + model_name='userprofile', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='userprofile', + name='oi_problems_status', + field=models.JSONField(default=dict), + ), + ] diff --git a/backend/announcement/migrations/0004_alter_announcement_id.py b/backend/announcement/migrations/0004_alter_announcement_id.py index 9386c655e..f5e45b086 100644 --- a/backend/announcement/migrations/0004_alter_announcement_id.py +++ b/backend/announcement/migrations/0004_alter_announcement_id.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.4 on 2021-10-30 06:35 +# Generated by Django 3.2.5 on 2021-12-26 05:58 from django.db import migrations, models diff --git a/backend/assignment/migrations/0002_alter_assignment_id.py b/backend/assignment/migrations/0002_alter_assignment_id.py new file mode 100644 index 000000000..f85089fd1 --- /dev/null +++ b/backend/assignment/migrations/0002_alter_assignment_id.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.5 on 2021-12-26 05:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('assignment', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='assignment', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + ] diff --git a/backend/conf/migrations/0005_alter_judgeserver_id.py b/backend/conf/migrations/0005_alter_judgeserver_id.py index b76a58fd4..b5d27f55c 100644 --- a/backend/conf/migrations/0005_alter_judgeserver_id.py +++ b/backend/conf/migrations/0005_alter_judgeserver_id.py @@ -1,4 +1,4 @@ -# Generated by Django 3.2.4 on 2021-10-30 06:35 +# Generated by Django 3.2.5 on 2021-12-26 05:58 from django.db import migrations, models diff --git a/backend/contest/migrations/0011_auto_20211226_1458.py b/backend/contest/migrations/0011_auto_20211226_1458.py new file mode 100644 index 000000000..7e7d2e1ca --- /dev/null +++ b/backend/contest/migrations/0011_auto_20211226_1458.py @@ -0,0 +1,48 @@ +# Generated by Django 3.2.5 on 2021-12-26 05:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('contest', '0010_auto_20190326_0201'), + ] + + operations = [ + migrations.AlterField( + model_name='acmcontestrank', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='acmcontestrank', + name='submission_info', + field=models.JSONField(default=dict), + ), + migrations.AlterField( + model_name='contest', + name='allowed_ip_ranges', + field=models.JSONField(default=list), + ), + migrations.AlterField( + model_name='contest', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='contestannouncement', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='oicontestrank', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='oicontestrank', + name='submission_info', + field=models.JSONField(default=dict), + ), + ] diff --git a/backend/course/migrations/0003_auto_20211226_1458.py b/backend/course/migrations/0003_auto_20211226_1458.py new file mode 100644 index 000000000..bc8f2bbc7 --- /dev/null +++ b/backend/course/migrations/0003_auto_20211226_1458.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.5 on 2021-12-26 05:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('course', '0002_auto_20210808_1709'), + ] + + operations = [ + migrations.AlterField( + model_name='course', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='registration', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + ] diff --git a/backend/course/migrations/0004_registration_bookmark.py b/backend/course/migrations/0004_registration_bookmark.py new file mode 100644 index 000000000..512ba8ea4 --- /dev/null +++ b/backend/course/migrations/0004_registration_bookmark.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.5 on 2021-12-26 07:28 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('course', '0003_auto_20211226_1458'), + ] + + operations = [ + migrations.AddField( + model_name='registration', + name='bookmark', + field=models.BooleanField(default=True), + ), + ] diff --git a/backend/course/models.py b/backend/course/models.py index 1a91ddb72..941fcec75 100644 --- a/backend/course/models.py +++ b/backend/course/models.py @@ -19,6 +19,7 @@ class Meta: class Registration(models.Model): course = models.ForeignKey(Course, on_delete=models.CASCADE) user = models.ForeignKey(User, on_delete=models.CASCADE) + bookmark = models.BooleanField(default=True) class Meta: db_table = "registration" diff --git a/backend/course/serializers.py b/backend/course/serializers.py index f3b2b7a24..b38ce3a42 100644 --- a/backend/course/serializers.py +++ b/backend/course/serializers.py @@ -63,9 +63,13 @@ class CourseStudentSerializer(serializers.ModelSerializer): class Meta: model = Registration - fields = ("course",) + fields = ("course", "bookmark",) +class BookmarkCourseSerializer(serializers.Serializer): + course_id = serializers.IntegerField() + bookmark = serializers.BooleanField() + class UserListSerializer(serializers.ModelSerializer): user = UserAdminSerializer() diff --git a/backend/course/urls/student.py b/backend/course/urls/student.py index 611a5f1a4..30eed5702 100644 --- a/backend/course/urls/student.py +++ b/backend/course/urls/student.py @@ -1,7 +1,8 @@ from django.urls import path -from ..views.student import CourseAPI +from ..views.student import BookmarkCourseAPI, CourseAPI urlpatterns = [ path("course/", CourseAPI.as_view(), name="course_api"), + path("bookmark_course/", BookmarkCourseAPI.as_view(), name="bookmark_course_api"), ] diff --git a/backend/course/views/student.py b/backend/course/views/student.py index 5155a9e51..6efbc394b 100644 --- a/backend/course/views/student.py +++ b/backend/course/views/student.py @@ -1,9 +1,9 @@ -from utils.api import APIView +from utils.api import APIView, validate_serializer from utils.decorators import login_required from drf_yasg.utils import swagger_auto_schema from drf_yasg import openapi from ..models import Course, Registration -from ..serializers import CourseStudentSerializer +from ..serializers import BookmarkCourseSerializer, CourseStudentSerializer class CourseAPI(APIView): @@ -16,6 +16,12 @@ class CourseAPI(APIView): requied=True, type=openapi.TYPE_INTEGER, ), + openapi.Parameter( + name="bookmark", + in_=openapi.IN_QUERY, + description="True for get bookmark list", + type=openapi.TYPE_BOOLEAN + ), openapi.Parameter( name="limit", in_=openapi.IN_QUERY, @@ -51,4 +57,32 @@ def get(self, request): courses = Registration.objects.filter(user_id=user_id) + if request.GET.get("bookmark") == "true": + courses = courses.filter(bookmark=True) + return self.success(self.paginate_data(request, courses, CourseStudentSerializer)) + + +class BookmarkCourseAPI(APIView): + @swagger_auto_schema( + request_body=BookmarkCourseSerializer, + operation_description="Bookmark a course" + ) + @validate_serializer(BookmarkCourseSerializer) + @login_required + def put(self, request): + data = request.data + course_id = data["course_id"] + + try: + Course.objects.get(id=course_id) + registration = Registration.objects.get(user_id=request.user.id, course_id=course_id) + except Course.DoesNotExist: + return self.error("Course does not exist") + except Registration.DoesNotExist: + return self.error("Invalid access, not registered course") + + registration.bookmark = data["bookmark"] + + registration.save() + return self.success(BookmarkCourseSerializer(registration).data) diff --git a/backend/options/migrations/0004_auto_20211226_1458.py b/backend/options/migrations/0004_auto_20211226_1458.py new file mode 100644 index 000000000..eba5593f6 --- /dev/null +++ b/backend/options/migrations/0004_auto_20211226_1458.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.5 on 2021-12-26 05:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('options', '0003_migrate_languages_options'), + ] + + operations = [ + migrations.AlterField( + model_name='sysoptions', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='sysoptions', + name='value', + field=models.JSONField(), + ), + ] diff --git a/backend/problem/migrations/0018_auto_20211226_1458.py b/backend/problem/migrations/0018_auto_20211226_1458.py new file mode 100644 index 000000000..3a6a1b00d --- /dev/null +++ b/backend/problem/migrations/0018_auto_20211226_1458.py @@ -0,0 +1,54 @@ +# Generated by Django 3.2.5 on 2021-12-26 05:58 + +from django.db import migrations, models +import problem.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('problem', '0017_auto_20210814_1415'), + ] + + operations = [ + migrations.AlterField( + model_name='problem', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + migrations.AlterField( + model_name='problem', + name='io_mode', + field=models.JSONField(default=problem.models._default_io_mode), + ), + migrations.AlterField( + model_name='problem', + name='languages', + field=models.JSONField(), + ), + migrations.AlterField( + model_name='problem', + name='samples', + field=models.JSONField(), + ), + migrations.AlterField( + model_name='problem', + name='statistic_info', + field=models.JSONField(default=dict), + ), + migrations.AlterField( + model_name='problem', + name='template', + field=models.JSONField(), + ), + migrations.AlterField( + model_name='problem', + name='test_case_score', + field=models.JSONField(), + ), + migrations.AlterField( + model_name='problemtag', + name='id', + field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), + ), + ] diff --git a/backend/submission/migrations/0016_auto_20211226_1458.py b/backend/submission/migrations/0016_auto_20211226_1458.py new file mode 100644 index 000000000..6a2e6ee82 --- /dev/null +++ b/backend/submission/migrations/0016_auto_20211226_1458.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.5 on 2021-12-26 05:58 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('submission', '0015_remove_submission_score'), + ] + + operations = [ + migrations.AlterField( + model_name='submission', + name='info', + field=models.JSONField(default=dict), + ), + migrations.AlterField( + model_name='submission', + name='statistic_info', + field=models.JSONField(default=dict), + ), + ]