mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: implement youtube backend and partial front
This commit is contained in:
parent
cdd1ca46d3
commit
77d4f5fa1c
6 changed files with 51 additions and 20 deletions
|
|
@ -99,21 +99,19 @@ async def api_create_video_activity(
|
|||
async def api_create_external_video_activity(
|
||||
request: Request,
|
||||
external_video: ExternalVideo,
|
||||
coursechapter_id: str = Form(),
|
||||
current_user: PublicUser = Depends(get_current_user),
|
||||
):
|
||||
"""
|
||||
Create new activity
|
||||
"""
|
||||
return await create_external_video_activity(
|
||||
request, coursechapter_id, current_user, external_video
|
||||
request, current_user, external_video
|
||||
)
|
||||
|
||||
|
||||
@router.post("/documentpdf")
|
||||
async def api_create_documentpdf_activity(
|
||||
request: Request,
|
||||
org_id: str,
|
||||
name: str = Form(),
|
||||
coursechapter_id: str = Form(),
|
||||
current_user: PublicUser = Depends(get_current_user),
|
||||
|
|
|
|||
|
|
@ -28,6 +28,12 @@ async def create_video_activity(
|
|||
{"chapters_content.coursechapter_id": coursechapter_id}
|
||||
)
|
||||
|
||||
if not coursechapter:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_409_CONFLICT,
|
||||
detail="CourseChapter : No coursechapter found",
|
||||
)
|
||||
|
||||
org_id = coursechapter["org_id"]
|
||||
|
||||
# check if video_file is not None
|
||||
|
|
@ -101,12 +107,14 @@ class ExternalVideo(BaseModel):
|
|||
name: str
|
||||
uri: str
|
||||
type: Literal["youtube", "vimeo"]
|
||||
coursechapter_id: str
|
||||
|
||||
class ExternalVideoInDB(BaseModel):
|
||||
activity_id: str
|
||||
|
||||
|
||||
async def create_external_video_activity(
|
||||
request: Request,
|
||||
coursechapter_id: str,
|
||||
current_user: PublicUser,
|
||||
data: ExternalVideo,
|
||||
):
|
||||
|
|
@ -118,15 +126,21 @@ async def create_external_video_activity(
|
|||
|
||||
# get org_id from course
|
||||
coursechapter = await courses.find_one(
|
||||
{"chapters_content.coursechapter_id": coursechapter_id}
|
||||
{"chapters_content.coursechapter_id": data.coursechapter_id}
|
||||
)
|
||||
|
||||
if not coursechapter:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_409_CONFLICT,
|
||||
detail="CourseChapter : No coursechapter found",
|
||||
)
|
||||
|
||||
org_id = coursechapter["org_id"]
|
||||
|
||||
activity_object = ActivityInDB(
|
||||
org_id=org_id,
|
||||
activity_id=activity_id,
|
||||
coursechapter_id=coursechapter_id,
|
||||
coursechapter_id=data.coursechapter_id,
|
||||
name=data.name,
|
||||
type="video",
|
||||
content={
|
||||
|
|
@ -157,7 +171,7 @@ async def create_external_video_activity(
|
|||
# todo : choose whether to update the chapter or not
|
||||
# update chapter
|
||||
await courses.update_one(
|
||||
{"chapters_content.coursechapter_id": coursechapter_id},
|
||||
{"chapters_content.coursechapter_id": data.coursechapter_id},
|
||||
{"$addToSet": {"chapters_content.$.activities": activity_id}},
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue