mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
fix: activitiy issues
This commit is contained in:
parent
669270441b
commit
53f40f3f34
20 changed files with 138 additions and 105 deletions
|
|
@ -63,6 +63,7 @@ class FullCourseReadWithTrail(CourseBase):
|
|||
course_uuid: str
|
||||
creation_date: str
|
||||
update_date: str
|
||||
org_id: int = Field(default=None, foreign_key="organization.id")
|
||||
authors: List[UserRead]
|
||||
# Chapters, Activities
|
||||
chapters: List[ChapterRead]
|
||||
|
|
|
|||
|
|
@ -62,11 +62,11 @@ async def api_get_chapter_activities(
|
|||
return await get_activities(request, chapter_id, current_user, db_session)
|
||||
|
||||
|
||||
@router.put("/{activity_id}")
|
||||
@router.put("/{activity_uuid}")
|
||||
async def api_update_activity(
|
||||
request: Request,
|
||||
activity_object: ActivityUpdate,
|
||||
activity_id: int,
|
||||
activity_uuid: str,
|
||||
current_user: PublicUser = Depends(get_current_user),
|
||||
db_session=Depends(get_db_session),
|
||||
) -> ActivityRead:
|
||||
|
|
@ -74,7 +74,7 @@ async def api_update_activity(
|
|||
Update activity by activity_id
|
||||
"""
|
||||
return await update_activity(
|
||||
request, activity_object, activity_id, current_user, db_session
|
||||
request, activity_object, activity_uuid, current_user, db_session
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -82,11 +82,11 @@ async def create_activity(
|
|||
|
||||
async def get_activity(
|
||||
request: Request,
|
||||
activity_id: str,
|
||||
activity_uuid: str,
|
||||
current_user: PublicUser,
|
||||
db_session: Session,
|
||||
):
|
||||
statement = select(Activity).where(Activity.id == activity_id)
|
||||
statement = select(Activity).where(Activity.activity_uuid == activity_uuid)
|
||||
activity = db_session.exec(statement).first()
|
||||
|
||||
if not activity:
|
||||
|
|
@ -106,11 +106,11 @@ async def get_activity(
|
|||
async def update_activity(
|
||||
request: Request,
|
||||
activity_object: ActivityUpdate,
|
||||
activity_id: int,
|
||||
activity_uuid: str,
|
||||
current_user: PublicUser | AnonymousUser,
|
||||
db_session: Session,
|
||||
):
|
||||
statement = select(Activity).where(Activity.id == activity_id)
|
||||
statement = select(Activity).where(Activity.activity_uuid == activity_uuid)
|
||||
activity = db_session.exec(statement).first()
|
||||
|
||||
if not activity:
|
||||
|
|
@ -140,11 +140,11 @@ async def update_activity(
|
|||
|
||||
async def delete_activity(
|
||||
request: Request,
|
||||
activity_id: str,
|
||||
activity_uuid: str,
|
||||
current_user: PublicUser | AnonymousUser,
|
||||
db_session: Session,
|
||||
):
|
||||
statement = select(Activity).where(Activity.id == activity_id)
|
||||
statement = select(Activity).where(Activity.activity_uuid == activity_uuid)
|
||||
activity = db_session.exec(statement).first()
|
||||
|
||||
if not activity:
|
||||
|
|
@ -160,7 +160,7 @@ async def delete_activity(
|
|||
|
||||
# Delete activity from chapter
|
||||
statement = select(ChapterActivity).where(
|
||||
ChapterActivity.activity_id == activity_id
|
||||
ChapterActivity.activity_id == activity.id
|
||||
)
|
||||
activity_chapter = db_session.exec(statement).first()
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
from typing import Literal
|
||||
from src.db.courses import Course
|
||||
from src.db.organizations import Organization
|
||||
from sqlmodel import Session, select
|
||||
from src.security.rbac.rbac import (
|
||||
authorization_verify_based_on_roles_and_authorship,
|
||||
|
|
@ -53,6 +55,14 @@ async def create_documentpdf_activity(
|
|||
# get org_id
|
||||
org_id = coursechapter.org_id
|
||||
|
||||
# Get org_uuid
|
||||
statement = select(Organization).where(Organization.id == coursechapter.org_id)
|
||||
organization = db_session.exec(statement).first()
|
||||
|
||||
# Get course_uuid
|
||||
statement = select(Course).where(Course.id == coursechapter.course_id)
|
||||
course = db_session.exec(statement).first()
|
||||
|
||||
# create activity uuid
|
||||
activity_uuid = f"activity_{uuid4()}"
|
||||
|
||||
|
|
@ -113,7 +123,12 @@ async def create_documentpdf_activity(
|
|||
# upload pdf
|
||||
if pdf_file:
|
||||
# get pdffile format
|
||||
await upload_pdf(pdf_file, activity.id, org_id, coursechapter.course_id)
|
||||
await upload_pdf(
|
||||
pdf_file,
|
||||
activity.activity_uuid,
|
||||
organization.org_uuid,
|
||||
course.course_uuid,
|
||||
)
|
||||
|
||||
# Insert ChapterActivity link in DB
|
||||
db_session.add(activity_chapter)
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
|
||||
from src.services.utils.upload_content import upload_content
|
||||
|
||||
|
||||
async def upload_pdf(pdf_file, activity_id, org_id, course_id):
|
||||
async def upload_pdf(pdf_file, activity_uuid, org_uuid, course_uuid):
|
||||
contents = pdf_file.file.read()
|
||||
pdf_format = pdf_file.filename.split(".")[-1]
|
||||
|
||||
try:
|
||||
await upload_content(
|
||||
f"courses/{course_id}/activities/{activity_id}/documentpdf",
|
||||
org_id,
|
||||
f"courses/{course_uuid}/activities/{activity_uuid}/documentpdf",
|
||||
org_uuid,
|
||||
contents,
|
||||
f"documentpdf.{pdf_format}",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@
|
|||
from src.services.utils.upload_content import upload_content
|
||||
|
||||
|
||||
async def upload_video(video_file, activity_id, org_id, course_id):
|
||||
async def upload_video(video_file, activity_uuid, org_uuid, course_uuid):
|
||||
contents = video_file.file.read()
|
||||
video_format = video_file.filename.split(".")[-1]
|
||||
|
||||
try:
|
||||
await upload_content(
|
||||
f"courses/{course_id}/activities/{activity_id}/video",
|
||||
org_id,
|
||||
f"courses/{course_uuid}/activities/{activity_uuid}/video",
|
||||
org_uuid,
|
||||
contents,
|
||||
f"video.{video_format}",
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
from typing import Literal
|
||||
from src.db.courses import Course
|
||||
from src.db.organizations import Organization
|
||||
|
||||
from pydantic import BaseModel
|
||||
from sqlmodel import Session, select
|
||||
|
|
@ -52,6 +54,14 @@ async def create_video_activity(
|
|||
detail="CourseChapter not found",
|
||||
)
|
||||
|
||||
# Get org_uuid
|
||||
statement = select(Organization).where(Organization.id == coursechapter.org_id)
|
||||
organization = db_session.exec(statement).first()
|
||||
|
||||
# Get course_uuid
|
||||
statement = select(Course).where(Course.id == coursechapter.course_id)
|
||||
course = db_session.exec(statement).first()
|
||||
|
||||
# generate activity_uuid
|
||||
activity_uuid = str(f"activity_{uuid4()}")
|
||||
|
||||
|
|
@ -104,7 +114,10 @@ async def create_video_activity(
|
|||
if video_file:
|
||||
# get videofile format
|
||||
await upload_video(
|
||||
video_file, activity.id, coursechapter.org_id, coursechapter.course_id
|
||||
video_file,
|
||||
activity.activity_uuid,
|
||||
organization.org_uuid,
|
||||
course.course_uuid,
|
||||
)
|
||||
|
||||
# update chapter
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue