|
|
|
@ -13,7 +13,7 @@ from constants import * |
|
|
|
|
from config import * |
|
|
|
|
from constants import PublishedStatus |
|
|
|
|
from typing import Union |
|
|
|
|
from backend.constants import UserRole |
|
|
|
|
from db.model import UserRole |
|
|
|
|
|
|
|
|
|
course = Blueprint('course', __name__) |
|
|
|
|
|
|
|
|
@ -28,13 +28,19 @@ def list_all_courses(): |
|
|
|
|
if category_uuid is not None: |
|
|
|
|
category_uuid: uuid.UUID = uuid.UUID(request.args.get('category_uuid')) |
|
|
|
|
# Build the query as required |
|
|
|
|
query: select = select(Course).limit(limit).offset(offset) |
|
|
|
|
query: select = select(Course) |
|
|
|
|
if search_q != '': |
|
|
|
|
query = query.where(or_(Course.name.like(f'%{search_q}%'), Course.description.like(f'%{search_q}%'), |
|
|
|
|
Course.author.firstName.like(f'%{search_q}%'))) |
|
|
|
|
User.firstName.like(f'%{search_q}%'))) |
|
|
|
|
if category_uuid is not None: |
|
|
|
|
query = query.where(Course.categoryID == category_uuid) |
|
|
|
|
total_pages_for_offset: int = db.session.execute(func.count(Course.id).select_from(Course)).scalar()/limit |
|
|
|
|
|
|
|
|
|
#total_pages_for_offset: int = db.session.execute(func.count(Course.id).select_from(Course)).scalar()/limit |
|
|
|
|
total_pages_for_offset: int = db.session.execute( |
|
|
|
|
select(func.count()).select_from(query.subquery()) |
|
|
|
|
).scalar() / limit |
|
|
|
|
|
|
|
|
|
query = query.limit(limit).offset(offset) |
|
|
|
|
total_pages: int = math.ceil(total_pages_for_offset) |
|
|
|
|
if sort_by in available_sorts: |
|
|
|
|
if sort_by == 'date_asc': |
|
|
|
@ -107,7 +113,7 @@ def enroll_user(): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@course.route('/create', methods=['POST']) |
|
|
|
|
@course.route('/createCourse', methods=['POST']) |
|
|
|
|
@auth_required() |
|
|
|
|
def create_course(): |
|
|
|
|
form_data: dict = request.form |
|
|
|
|