From 3c5accfc6e66e423ea83da1f5455702a4a60d01d Mon Sep 17 00:00:00 2001 From: dominik24c Date: Thu, 27 Oct 2022 12:05:50 +0200 Subject: [PATCH] add mode to examination schedule model and add endpoints list of examination schedule for students and project supervisors --- .../schemas/examination_schedule.py | 2 ++ backend/app/examination_schedule/models.py | 1 + .../examination_schedule/routes/__init__.py | 2 ++ .../routes/examination_schedule.py | 32 +++++++++++++++++++ backend/app/examination_schedule/schemas.py | 9 ++++++ .../{97c55960cd98_.py => 64ad410af362_.py} | 7 ++-- 6 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 backend/app/examination_schedule/routes/examination_schedule.py rename backend/migrations/versions/{97c55960cd98_.py => 64ad410af362_.py} (94%) diff --git a/backend/app/coordinator/schemas/examination_schedule.py b/backend/app/coordinator/schemas/examination_schedule.py index 5863c21..c66073b 100644 --- a/backend/app/coordinator/schemas/examination_schedule.py +++ b/backend/app/coordinator/schemas/examination_schedule.py @@ -5,6 +5,7 @@ from ..validators import validate_datetime_greater_than_now class ExaminationScheduleSchema(Schema): title = fields.Str(validate=validate.Length(min=1, max=100), required=True) + mode = fields.Boolean(required=True) class ExaminationScheduleUpdateSchema(Schema): @@ -15,6 +16,7 @@ class ExaminationScheduleUpdateSchema(Schema): class ExaminationScheduleListItemSchema(Schema): id = fields.Integer(required=True) title = fields.Str(validate=validate.Length(min=1, max=100), required=True) + mode = fields.Boolean(required=True) start_date = fields.DateTime(validate=validate_datetime_greater_than_now, required=True) end_date = fields.DateTime(validate=validate_datetime_greater_than_now, required=True) diff --git a/backend/app/examination_schedule/models.py b/backend/app/examination_schedule/models.py index f1692c1..d0bd5a9 100644 --- a/backend/app/examination_schedule/models.py +++ b/backend/app/examination_schedule/models.py @@ -6,6 +6,7 @@ class ExaminationSchedule(Base): __tablename__ = 'examination_schedules' title = db.Column(db.String(100), unique=True, nullable=False) + mode = db.Column(db.Boolean, default=True, nullable=False) # True - stationary, False - non-stationary start_date = db.Column(db.DateTime) end_date = db.Column(db.DateTime) diff --git a/backend/app/examination_schedule/routes/__init__.py b/backend/app/examination_schedule/routes/__init__.py index 30893a6..d4cecbb 100644 --- a/backend/app/examination_schedule/routes/__init__.py +++ b/backend/app/examination_schedule/routes/__init__.py @@ -1,7 +1,9 @@ from flask import Blueprint from .enrollments import bp as enrollments_bp +from .examination_schedule import bp as examination_schedule_bp bp = Blueprint("examination_schedule", __name__, url_prefix="/examination_schedule") bp.register_blueprint(enrollments_bp) +bp.register_blueprint(examination_schedule_bp) diff --git a/backend/app/examination_schedule/routes/examination_schedule.py b/backend/app/examination_schedule/routes/examination_schedule.py new file mode 100644 index 0000000..69d9cc4 --- /dev/null +++ b/backend/app/examination_schedule/routes/examination_schedule.py @@ -0,0 +1,32 @@ +import datetime + +from apiflask import APIBlueprint +from flask import abort + +from ...dependencies import db +from ..models import ExaminationSchedule +from ..schemas import ExaminationScheduleListSchema + +bp = APIBlueprint("list_of_examination_schedule", __name__, url_prefix="/") + + +@bp.get('/project-supervisor-view/') +@bp.output(ExaminationScheduleListSchema) +def list_examination_schedule_for_project_supervisors() -> dict: + now = datetime.datetime.utcnow() + examination_schedules = db.session.query(ExaminationSchedule). \ + filter(ExaminationSchedule.start_date > now). \ + all() + return {'examination_schedules': examination_schedules} + + +@bp.get('/students-view/') +@bp.output(ExaminationScheduleListSchema) +def list_examination_schedule_for_students() -> dict: + # in the future filter after the mode of examination schedule if we will have authorization module + now = datetime.datetime.utcnow() + examination_schedules = db.session.query(ExaminationSchedule).\ + filter(ExaminationSchedule.start_date < now).\ + filter(ExaminationSchedule.end_date > now).\ + all() + return {'examination_schedules': examination_schedules} diff --git a/backend/app/examination_schedule/schemas.py b/backend/app/examination_schedule/schemas.py index e220f56..ad69647 100644 --- a/backend/app/examination_schedule/schemas.py +++ b/backend/app/examination_schedule/schemas.py @@ -29,3 +29,12 @@ class EnrollmentPaginationSchema(Schema): class EnrollmentQuerySchema(Schema): page = fields.Integer() per_page = fields.Integer() + + +class ExaminationScheduleSchema(Schema): + id = fields.Integer() + title = fields.Str() + + +class ExaminationScheduleListSchema(Schema): + examination_schedules = fields.List(fields.Nested(ExaminationScheduleSchema)) diff --git a/backend/migrations/versions/97c55960cd98_.py b/backend/migrations/versions/64ad410af362_.py similarity index 94% rename from backend/migrations/versions/97c55960cd98_.py rename to backend/migrations/versions/64ad410af362_.py index df2a874..64f0593 100644 --- a/backend/migrations/versions/97c55960cd98_.py +++ b/backend/migrations/versions/64ad410af362_.py @@ -1,8 +1,8 @@ """empty message -Revision ID: 97c55960cd98 +Revision ID: 64ad410af362 Revises: ceaefb33117e -Create Date: 2022-10-26 13:00:18.439990 +Create Date: 2022-10-27 09:44:53.799889 """ from alembic import op @@ -10,7 +10,7 @@ import sqlalchemy as sa # revision identifiers, used by Alembic. -revision = '97c55960cd98' +revision = '64ad410af362' down_revision = 'ceaefb33117e' branch_labels = None depends_on = None @@ -21,6 +21,7 @@ def upgrade(): op.create_table('examination_schedules', sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), sa.Column('title', sa.String(length=100), nullable=False), + sa.Column('mode', sa.Boolean(), nullable=False), sa.Column('start_date', sa.DateTime(), nullable=True), sa.Column('end_date', sa.DateTime(), nullable=True), sa.PrimaryKeyConstraint('id'),