mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: add response models to endpoints
This commit is contained in:
parent
7738316200
commit
71279a1294
20 changed files with 148 additions and 68 deletions
|
|
@ -3,7 +3,7 @@ from uuid import uuid4
|
|||
from fastapi import HTTPException, status, UploadFile, Request
|
||||
from sqlmodel import Session, select
|
||||
from src.db.activities import Activity
|
||||
from src.db.blocks import Block, BlockTypeEnum
|
||||
from src.db.blocks import Block, BlockRead, BlockTypeEnum
|
||||
from src.db.courses import Course
|
||||
from src.services.blocks.utils.upload_files import upload_file_and_return_file_object
|
||||
from src.services.users.users import PublicUser
|
||||
|
|
@ -65,6 +65,8 @@ async def create_image_block(
|
|||
db_session.commit()
|
||||
db_session.refresh(block)
|
||||
|
||||
block = BlockRead.from_orm(block)
|
||||
|
||||
return block
|
||||
|
||||
|
||||
|
|
@ -75,6 +77,9 @@ async def get_image_block(
|
|||
block = db_session.exec(statement).first()
|
||||
|
||||
if block:
|
||||
|
||||
block = BlockRead.from_orm(block)
|
||||
|
||||
return block
|
||||
else:
|
||||
raise HTTPException(
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from uuid import uuid4
|
|||
from fastapi import HTTPException, status, UploadFile, Request
|
||||
from sqlmodel import Session, select
|
||||
from src.db.activities import Activity
|
||||
from src.db.blocks import Block, BlockTypeEnum
|
||||
from src.db.blocks import Block, BlockRead, BlockTypeEnum
|
||||
from src.db.courses import Course
|
||||
from src.services.blocks.utils.upload_files import upload_file_and_return_file_object
|
||||
|
||||
|
|
@ -66,6 +66,8 @@ async def create_pdf_block(
|
|||
db_session.commit()
|
||||
db_session.refresh(block)
|
||||
|
||||
block = BlockRead.from_orm(block)
|
||||
|
||||
return block
|
||||
|
||||
|
||||
|
|
@ -80,4 +82,6 @@ async def get_pdf_block(
|
|||
status_code=status.HTTP_404_NOT_FOUND, detail="Video file does not exist"
|
||||
)
|
||||
|
||||
block = BlockRead.from_orm(block)
|
||||
|
||||
return block
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from uuid import uuid4
|
|||
from fastapi import HTTPException, status, UploadFile, Request
|
||||
from sqlmodel import Session, select
|
||||
from src.db.activities import Activity
|
||||
from src.db.blocks import Block, BlockTypeEnum
|
||||
from src.db.blocks import Block, BlockRead, BlockTypeEnum
|
||||
from src.db.courses import Course
|
||||
from src.services.blocks.utils.upload_files import upload_file_and_return_file_object
|
||||
|
||||
|
|
@ -66,6 +66,8 @@ async def create_video_block(
|
|||
db_session.commit()
|
||||
db_session.refresh(block)
|
||||
|
||||
block = BlockRead.from_orm(block)
|
||||
|
||||
return block
|
||||
|
||||
|
||||
|
|
@ -79,5 +81,7 @@ async def get_video_block(
|
|||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Video file does not exist"
|
||||
)
|
||||
|
||||
|
||||
block = BlockRead.from_orm(block)
|
||||
|
||||
return block
|
||||
|
|
|
|||
|
|
@ -96,6 +96,8 @@ async def get_activity(
|
|||
# RBAC check
|
||||
await rbac_check(request, activity.activity_uuid, current_user, "read", db_session)
|
||||
|
||||
activity = ActivityRead.from_orm(activity)
|
||||
|
||||
return activity
|
||||
|
||||
|
||||
|
|
@ -130,6 +132,8 @@ async def update_activity(
|
|||
db_session.commit()
|
||||
db_session.refresh(activity)
|
||||
|
||||
activity = ActivityRead.from_orm(activity)
|
||||
|
||||
return activity
|
||||
|
||||
|
||||
|
|
@ -182,7 +186,7 @@ async def get_activities(
|
|||
coursechapter_id: str,
|
||||
current_user: PublicUser | AnonymousUser,
|
||||
db_session: Session,
|
||||
):
|
||||
) -> list[ActivityRead]:
|
||||
statement = select(ChapterActivity).where(
|
||||
ChapterActivity.chapter_id == coursechapter_id
|
||||
)
|
||||
|
|
@ -197,6 +201,8 @@ async def get_activities(
|
|||
# RBAC check
|
||||
await rbac_check(request, "activity_x", current_user, "read", db_session)
|
||||
|
||||
activities = [ActivityRead.from_orm(activity) for activity in activities]
|
||||
|
||||
return activities
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ async def get_course(
|
|||
# RBAC check
|
||||
await rbac_check(request, course.course_uuid, current_user, "read", db_session)
|
||||
|
||||
course = CourseRead.from_orm(course)
|
||||
|
||||
return course
|
||||
|
||||
|
||||
|
|
@ -188,6 +190,8 @@ async def update_course_thumbnail(
|
|||
db_session.commit()
|
||||
db_session.refresh(course)
|
||||
|
||||
course = CourseRead.from_orm(course)
|
||||
|
||||
return course
|
||||
|
||||
|
||||
|
|
@ -223,6 +227,8 @@ async def update_course(
|
|||
db_session.commit()
|
||||
db_session.refresh(course)
|
||||
|
||||
course = CourseRead.from_orm(course)
|
||||
|
||||
return course
|
||||
|
||||
|
||||
|
|
@ -277,6 +283,8 @@ async def get_courses_orgslug(
|
|||
|
||||
courses = db_session.exec(statement)
|
||||
|
||||
courses = [CourseRead.from_orm(course) for course in courses]
|
||||
|
||||
return courses
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ from uuid import uuid4
|
|||
from fastapi import HTTPException, Request
|
||||
from sqlalchemy import desc
|
||||
from sqlmodel import Session, select
|
||||
from src.db.install import Install
|
||||
from src.db.install import Install, InstallRead
|
||||
from src.db.organizations import Organization, OrganizationCreate
|
||||
from src.db.roles import Permission, Rights, Role, RoleTypeEnum
|
||||
from src.db.user_organizations import UserOrganization
|
||||
|
|
@ -41,6 +41,8 @@ async def create_install_instance(request: Request, data: dict, db_session: Sess
|
|||
# refresh install instance
|
||||
db_session.refresh(install)
|
||||
|
||||
install = InstallRead.from_orm(install)
|
||||
|
||||
return install
|
||||
|
||||
|
||||
|
|
@ -53,6 +55,8 @@ async def get_latest_install_instance(request: Request, db_session: Session):
|
|||
status_code=404,
|
||||
detail="No install instance found",
|
||||
)
|
||||
|
||||
install = InstallRead.from_orm(install)
|
||||
|
||||
return install
|
||||
|
||||
|
|
@ -78,6 +82,8 @@ async def update_install_instance(
|
|||
# refresh install instance
|
||||
db_session.refresh(install)
|
||||
|
||||
install = InstallRead.from_orm(install)
|
||||
|
||||
return install
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ async def get_organization(
|
|||
# RBAC check
|
||||
await rbac_check(request, org.org_uuid, current_user, "read", db_session)
|
||||
|
||||
org = OrganizationRead.from_orm(org)
|
||||
|
||||
return org
|
||||
|
||||
|
||||
|
|
@ -61,6 +63,8 @@ async def get_organization_by_slug(
|
|||
# RBAC check
|
||||
await rbac_check(request, org.org_uuid, current_user, "read", db_session)
|
||||
|
||||
org = OrganizationRead.from_orm(org)
|
||||
|
||||
return org
|
||||
|
||||
|
||||
|
|
@ -160,6 +164,8 @@ async def update_org(
|
|||
db_session.commit()
|
||||
db_session.refresh(org)
|
||||
|
||||
org = OrganizationRead.from_orm(org)
|
||||
|
||||
return org
|
||||
|
||||
|
||||
|
|
@ -197,6 +203,7 @@ async def update_org_logo(
|
|||
db_session.commit()
|
||||
db_session.refresh(org)
|
||||
|
||||
|
||||
return {"detail": "Logo updated"}
|
||||
|
||||
|
||||
|
|
@ -244,7 +251,7 @@ async def get_orgs_by_user(
|
|||
user_id: str,
|
||||
page: int = 1,
|
||||
limit: int = 10,
|
||||
):
|
||||
) -> list[Organization]:
|
||||
statement = (
|
||||
select(Organization)
|
||||
.join(UserOrganization)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from src.security.rbac.rbac import (
|
|||
authorization_verify_if_user_is_author,
|
||||
)
|
||||
from src.db.users import AnonymousUser, PublicUser
|
||||
from src.db.roles import Role, RoleCreate, RoleUpdate
|
||||
from src.db.roles import Role, RoleCreate, RoleRead, RoleUpdate
|
||||
from fastapi import HTTPException, Request
|
||||
from datetime import datetime
|
||||
|
||||
|
|
@ -32,6 +32,8 @@ async def create_role(
|
|||
db_session.commit()
|
||||
db_session.refresh(role)
|
||||
|
||||
role = RoleRead(**role.dict())
|
||||
|
||||
return role
|
||||
|
||||
|
||||
|
|
@ -52,6 +54,8 @@ async def read_role(
|
|||
# RBAC check
|
||||
await rbac_check(request, current_user, "read", role.role_uuid, db_session)
|
||||
|
||||
role = RoleRead(**role.dict())
|
||||
|
||||
return role
|
||||
|
||||
|
||||
|
|
@ -90,6 +94,8 @@ async def update_role(
|
|||
db_session.commit()
|
||||
db_session.refresh(role)
|
||||
|
||||
role = RoleRead(**role.dict())
|
||||
|
||||
return role
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue