mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
fix: block issues
This commit is contained in:
parent
759c68babb
commit
573b9a43fc
14 changed files with 214 additions and 176 deletions
|
|
@ -28,14 +28,14 @@ router = APIRouter()
|
|||
async def api_create_image_file_block(
|
||||
request: Request,
|
||||
file_object: UploadFile,
|
||||
activity_id: str = Form(),
|
||||
activity_uuid: str = Form(),
|
||||
db_session=Depends(get_db_session),
|
||||
current_user: PublicUser = Depends(get_current_user),
|
||||
) -> BlockRead:
|
||||
"""
|
||||
Create new image file
|
||||
"""
|
||||
return await create_image_block(request, file_object, activity_id, db_session)
|
||||
return await create_image_block(request, file_object, activity_uuid, db_session)
|
||||
|
||||
|
||||
@router.get("/image")
|
||||
|
|
@ -60,14 +60,14 @@ async def api_get_image_file_block(
|
|||
async def api_create_video_file_block(
|
||||
request: Request,
|
||||
file_object: UploadFile,
|
||||
activity_id: str = Form(),
|
||||
activity_uuid: str = Form(),
|
||||
db_session=Depends(get_db_session),
|
||||
current_user: PublicUser = Depends(get_current_user),
|
||||
) -> BlockRead:
|
||||
"""
|
||||
Create new video file
|
||||
"""
|
||||
return await create_video_block(request, file_object, activity_id, db_session)
|
||||
return await create_video_block(request, file_object, activity_uuid, db_session)
|
||||
|
||||
|
||||
@router.get("/video")
|
||||
|
|
@ -92,14 +92,14 @@ async def api_get_video_file_block(
|
|||
async def api_create_pdf_file_block(
|
||||
request: Request,
|
||||
file_object: UploadFile,
|
||||
activity_id: str = Form(),
|
||||
activity_uuid: str = Form(),
|
||||
db_session=Depends(get_db_session),
|
||||
current_user: PublicUser = Depends(get_current_user),
|
||||
) -> BlockRead:
|
||||
"""
|
||||
Create new pdf file
|
||||
"""
|
||||
return await create_pdf_block(request, file_object, activity_id, db_session)
|
||||
return await create_pdf_block(request, file_object, activity_uuid, db_session)
|
||||
|
||||
|
||||
@router.get("/pdf")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from datetime import datetime
|
||||
from uuid import uuid4
|
||||
from src.db.organizations import Organization
|
||||
from fastapi import HTTPException, status, UploadFile, Request
|
||||
from sqlmodel import Session, select
|
||||
from src.db.activities import Activity
|
||||
|
|
@ -10,9 +11,9 @@ from src.services.users.users import PublicUser
|
|||
|
||||
|
||||
async def create_image_block(
|
||||
request: Request, image_file: UploadFile, activity_id: str, db_session: Session
|
||||
request: Request, image_file: UploadFile, activity_uuid: str, 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:
|
||||
|
|
@ -22,8 +23,9 @@ async def create_image_block(
|
|||
|
||||
block_type = "imageBlock"
|
||||
|
||||
# get org_id from activity
|
||||
org_id = activity.org_id
|
||||
# get org_uuid
|
||||
statement = select(Organization).where(Organization.id == activity.org_id)
|
||||
org = db_session.exec(statement).first()
|
||||
|
||||
# get course
|
||||
statement = select(Course).where(Course.id == activity.course_id)
|
||||
|
|
@ -40,12 +42,12 @@ async def create_image_block(
|
|||
block_data = await upload_file_and_return_file_object(
|
||||
request,
|
||||
image_file,
|
||||
activity_id,
|
||||
activity_uuid,
|
||||
block_uuid,
|
||||
["jpg", "jpeg", "png", "gif"],
|
||||
block_type,
|
||||
str(org_id),
|
||||
str(course.id),
|
||||
org.org_uuid,
|
||||
str(course.course_uuid),
|
||||
)
|
||||
|
||||
# create block
|
||||
|
|
@ -53,7 +55,7 @@ async def create_image_block(
|
|||
activity_id=activity.id if activity.id else 0,
|
||||
block_type=BlockTypeEnum.BLOCK_IMAGE,
|
||||
content=block_data.dict(),
|
||||
org_id=org_id,
|
||||
org_id=org.id if org.id else 0,
|
||||
course_id=course.id if course.id else 0,
|
||||
block_uuid=block_uuid,
|
||||
creation_date=str(datetime.now()),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from datetime import datetime
|
||||
from uuid import uuid4
|
||||
from src.db.organizations import Organization
|
||||
from fastapi import HTTPException, status, UploadFile, Request
|
||||
from sqlmodel import Session, select
|
||||
from src.db.activities import Activity
|
||||
|
|
@ -11,9 +12,9 @@ from src.services.users.users import PublicUser
|
|||
|
||||
|
||||
async def create_pdf_block(
|
||||
request: Request, pdf_file: UploadFile, activity_id: str, db_session: Session
|
||||
request: Request, pdf_file: UploadFile, activity_uuid: str, 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:
|
||||
|
|
@ -23,8 +24,9 @@ async def create_pdf_block(
|
|||
|
||||
block_type = "pdfBlock"
|
||||
|
||||
# get org_id from activity
|
||||
org_id = activity.org_id
|
||||
# get org_uuid
|
||||
statement = select(Organization).where(Organization.id == activity.org_id)
|
||||
org = db_session.exec(statement).first()
|
||||
|
||||
# get course
|
||||
statement = select(Course).where(Course.id == activity.course_id)
|
||||
|
|
@ -41,12 +43,12 @@ async def create_pdf_block(
|
|||
block_data = await upload_file_and_return_file_object(
|
||||
request,
|
||||
pdf_file,
|
||||
activity_id,
|
||||
activity_uuid,
|
||||
block_uuid,
|
||||
["pdf"],
|
||||
block_type,
|
||||
str(org_id),
|
||||
str(course.id),
|
||||
org.org_uuid,
|
||||
str(course.course_uuid),
|
||||
)
|
||||
|
||||
# create block
|
||||
|
|
@ -54,7 +56,7 @@ async def create_pdf_block(
|
|||
activity_id=activity.id if activity.id else 0,
|
||||
block_type=BlockTypeEnum.BLOCK_DOCUMENT_PDF,
|
||||
content=block_data.dict(),
|
||||
org_id=org_id,
|
||||
org_id=org.id if org.id else 0,
|
||||
course_id=course.id if course.id else 0,
|
||||
block_uuid=block_uuid,
|
||||
creation_date=str(datetime.now()),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from datetime import datetime
|
||||
from uuid import uuid4
|
||||
from src.db.organizations import Organization
|
||||
from fastapi import HTTPException, status, UploadFile, Request
|
||||
from sqlmodel import Session, select
|
||||
from src.db.activities import Activity
|
||||
|
|
@ -11,9 +12,9 @@ from src.services.users.users import PublicUser
|
|||
|
||||
|
||||
async def create_video_block(
|
||||
request: Request, video_file: UploadFile, activity_id: str, db_session: Session
|
||||
request: Request, video_file: UploadFile, activity_uuid: str, 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:
|
||||
|
|
@ -23,8 +24,9 @@ async def create_video_block(
|
|||
|
||||
block_type = "videoBlock"
|
||||
|
||||
# get org_id from activity
|
||||
org_id = activity.org_id
|
||||
# get org_uuid
|
||||
statement = select(Organization).where(Organization.id == activity.org_id)
|
||||
org = db_session.exec(statement).first()
|
||||
|
||||
# get course
|
||||
statement = select(Course).where(Course.id == activity.course_id)
|
||||
|
|
@ -41,12 +43,12 @@ async def create_video_block(
|
|||
block_data = await upload_file_and_return_file_object(
|
||||
request,
|
||||
video_file,
|
||||
activity_id,
|
||||
activity_uuid,
|
||||
block_uuid,
|
||||
["mp4", "webm", "ogg"],
|
||||
block_type,
|
||||
str(org_id),
|
||||
str(course.id),
|
||||
org.org_uuid,
|
||||
str(course.course_uuid),
|
||||
)
|
||||
|
||||
# create block
|
||||
|
|
@ -54,7 +56,7 @@ async def create_video_block(
|
|||
activity_id=activity.id if activity.id else 0,
|
||||
block_type=BlockTypeEnum.BLOCK_VIDEO,
|
||||
content=block_data.dict(),
|
||||
org_id=org_id,
|
||||
org_id=org.id if org.id else 0,
|
||||
course_id=course.id if course.id else 0,
|
||||
block_uuid=block_uuid,
|
||||
creation_date=str(datetime.now()),
|
||||
|
|
|
|||
|
|
@ -7,4 +7,4 @@ class BlockFile(BaseModel):
|
|||
file_name: str
|
||||
file_size: int
|
||||
file_type: str
|
||||
activity_id: str
|
||||
activity_uuid: str
|
||||
|
|
@ -7,12 +7,12 @@ from src.services.utils.upload_content import upload_content
|
|||
async def upload_file_and_return_file_object(
|
||||
request: Request,
|
||||
file: UploadFile,
|
||||
activity_id: str,
|
||||
activity_uuid: str,
|
||||
block_id: str,
|
||||
list_of_allowed_file_formats: list,
|
||||
type_of_block: str,
|
||||
org_id: str,
|
||||
course_id: str,
|
||||
org_uuid: str,
|
||||
course_uuid: str,
|
||||
):
|
||||
# get file id
|
||||
file_id = str(uuid.uuid4())
|
||||
|
|
@ -45,12 +45,12 @@ async def upload_file_and_return_file_object(
|
|||
file_name=file_name,
|
||||
file_size=file_size,
|
||||
file_type=file_type,
|
||||
activity_id=activity_id,
|
||||
activity_uuid=activity_uuid,
|
||||
)
|
||||
|
||||
await upload_content(
|
||||
f"courses/{course_id}/activities/{activity_id}/dynamic/blocks/{type_of_block}/{block_id}",
|
||||
org_id=org_id,
|
||||
f"courses/{course_uuid}/activities/{activity_uuid}/dynamic/blocks/{type_of_block}/{block_id}",
|
||||
org_uuid=org_uuid,
|
||||
file_binary=file_binary,
|
||||
file_and_format=f"{file_id}.{file_format}",
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue