mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: init chapters, coursechapters. fix courses
This commit is contained in:
parent
eca819b896
commit
4fcc8aa77c
8 changed files with 151 additions and 36 deletions
|
|
@ -2,6 +2,7 @@ import stat
|
|||
from typing import Literal
|
||||
from pydantic import BaseModel
|
||||
from sqlmodel import Session, select
|
||||
from src.db.chapters import Chapter
|
||||
from src.db.organizations import Organization
|
||||
from src import db
|
||||
from src.db.activities import ActivityCreate, Activity, ActivityRead, ActivityUpdate
|
||||
|
|
@ -49,15 +50,26 @@ async def create_activity(
|
|||
db_session.commit()
|
||||
db_session.refresh(activity)
|
||||
|
||||
# Find the last activity in the Chapter and add it to the list
|
||||
statement = (
|
||||
select(ChapterActivity)
|
||||
.where(ChapterActivity.chapter_id == activity_object.chapter_id)
|
||||
.order_by(ChapterActivity.order)
|
||||
)
|
||||
chapter_activities = db_session.exec(statement).all()
|
||||
|
||||
last_order = chapter_activities[-1].order if chapter_activities else 0
|
||||
to_be_used_order = last_order + 1
|
||||
|
||||
# Add activity to chapter
|
||||
activity_chapter = ChapterActivity(
|
||||
chapter_id=activity_object.chapter_id,
|
||||
activity_id=activity.id is not None,
|
||||
activity_id=activity.id if activity.id else 0,
|
||||
course_id=activity_object.course_id,
|
||||
org_id=activity_object.org_id,
|
||||
creation_date=str(datetime.now()),
|
||||
update_date=str(datetime.now()),
|
||||
order=activity_object.order,
|
||||
order=to_be_used_order,
|
||||
)
|
||||
|
||||
# Insert ChapterActivity link in DB
|
||||
|
|
|
|||
|
|
@ -54,7 +54,6 @@ async def get_course_meta(
|
|||
async def create_course(
|
||||
request: Request,
|
||||
course_object: CourseCreate,
|
||||
org_id: int,
|
||||
current_user: PublicUser,
|
||||
db_session: Session,
|
||||
thumbnail_file: UploadFile | None = None,
|
||||
|
|
@ -62,7 +61,7 @@ async def create_course(
|
|||
course = Course.from_orm(course_object)
|
||||
|
||||
# Complete course object
|
||||
course.org_id = org_id
|
||||
course.org_id = course.org_id
|
||||
course.course_uuid = str(uuid4())
|
||||
course.creation_date = str(datetime.now())
|
||||
course.update_date = str(datetime.now())
|
||||
|
|
@ -70,7 +69,7 @@ async def create_course(
|
|||
# Upload thumbnail
|
||||
if thumbnail_file and thumbnail_file.filename:
|
||||
name_in_disk = f"{course.course_uuid}_thumbnail_{uuid4()}.{thumbnail_file.filename.split('.')[-1]}"
|
||||
await upload_thumbnail(thumbnail_file, name_in_disk, org_id, course.course_uuid)
|
||||
await upload_thumbnail(thumbnail_file, name_in_disk, course_object.org_id, course.course_uuid)
|
||||
course_object.thumbnail = name_in_disk
|
||||
|
||||
# Insert course
|
||||
|
|
@ -80,7 +79,7 @@ async def create_course(
|
|||
|
||||
# Make the user the creator of the course
|
||||
course_author = CourseAuthor(
|
||||
course_id=course.id is not None,
|
||||
course_id=course.id if course.id else 0,
|
||||
user_id=current_user.id,
|
||||
authorship=CourseAuthorshipEnum.CREATOR,
|
||||
creation_date=str(datetime.now()),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue