system-pri/backend/app/examination_schedule/routes/enrollments.py

62 lines
2.4 KiB
Python
Raw Normal View History

import datetime
from apiflask import APIBlueprint
from flask import abort
from ..schemas import EnrollmentPaginationSchema, EnrollmentQuerySchema
from ..utils import check_examination_schedule_is_exist, get_list_of_enrollments_response
bp = APIBlueprint("enrollments", __name__, url_prefix="/enrollments")
# list of the exam registration for students
@bp.get('/<int:examination_schedule_id>/student-view')
@bp.input(EnrollmentQuerySchema, location='query')
@bp.output(EnrollmentPaginationSchema)
def list_enrollments_for_students(examination_schedule_id: int, query: dict) -> dict:
page = query.get('page')
per_page = query.get('per_page')
examination_schedule = check_examination_schedule_is_exist(examination_schedule_id)
now = datetime.datetime.utcnow()
if examination_schedule.start_date is None or examination_schedule.end_date is None:
abort(403, "Forbidden! The examination schedule is not available yet")
if examination_schedule.start_date.timestamp() > now.timestamp():
abort(403, "Forbidden! Enrollments haven't just started!")
if examination_schedule.end_date.timestamp() < now.timestamp():
abort(400, "The exam registration has just finished!")
return get_list_of_enrollments_response(examination_schedule_id, page, per_page)
@bp.get('/<int:examination_schedule_id>/coordinator-view/')
@bp.input(EnrollmentQuerySchema, location='query')
@bp.output(EnrollmentPaginationSchema)
def list_enrollments_for_coordinator(examination_schedule_id: int, query: dict) -> dict:
page = query.get('page')
per_page = query.get('per_page')
check_examination_schedule_is_exist(examination_schedule_id)
return get_list_of_enrollments_response(examination_schedule_id, page, per_page)
@bp.get('/<int:examination_schedule_id>/project-supervisor-view/')
@bp.input(EnrollmentQuerySchema, location='query')
@bp.output(EnrollmentPaginationSchema)
def list_enrollments_for_project_supervisor(examination_schedule_id: int, query: dict) -> dict:
page = query.get('page')
per_page = query.get('per_page')
examination_schedule = check_examination_schedule_is_exist(examination_schedule_id)
now = datetime.datetime.utcnow()
if examination_schedule.start_date.timestamp() < now.timestamp():
abort(403, "Forbidden! Enrollment has just started! You cannot assign to the exam committees!")
return get_list_of_enrollments_response(examination_schedule_id, page, per_page)