mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: user init & refactors
This commit is contained in:
parent
b4dcc14749
commit
a50fc67104
25 changed files with 356 additions and 358 deletions
0
apps/api/src/db/__init__.py
Normal file
0
apps/api/src/db/__init__.py
Normal file
58
apps/api/src/db/activities.py
Normal file
58
apps/api/src/db/activities.py
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
from typing import Literal, Optional
|
||||
from sqlalchemy import JSON, Column
|
||||
from sqlmodel import Field, Session, SQLModel, create_engine, select
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class ActivityTypeEnum(str, Enum):
|
||||
VIDEO = "VIDEO"
|
||||
DOCUMENT = "DOCUMENT"
|
||||
DYNAMIC = "DYNAMIC"
|
||||
ASSESSMENT = "ASSESSMENT"
|
||||
CUSTOM = "CUSTOM"
|
||||
|
||||
|
||||
class ActivitySubTypeEnum(str, Enum):
|
||||
# Dynamic
|
||||
DYNAMIC_PAGE = "DYNAMIC_PAGE"
|
||||
# Video
|
||||
VIDEO_YOUTUBE = "VIDEO_YOUTUBE"
|
||||
VIDEO_HOSTED = "VIDEO_HOSTED"
|
||||
# Document
|
||||
DOCUMENT_PDF = "DOCUMENT_PDF"
|
||||
DOCUMENT_DOC = "DOCUMENT_GDOC"
|
||||
# Assessment
|
||||
ASSESSMENT_QUIZ = "ASSESSMENT_QUIZ"
|
||||
# Custom
|
||||
CUSTOM = "CUSTOM"
|
||||
|
||||
|
||||
class ActivityBase(SQLModel):
|
||||
name: str
|
||||
activity_type: ActivityTypeEnum = ActivityTypeEnum.CUSTOM
|
||||
activity_sub_type: ActivitySubTypeEnum = ActivitySubTypeEnum.CUSTOM
|
||||
slug: str
|
||||
content: dict = Field(default={}, sa_column=Column(JSON))
|
||||
published_version: int
|
||||
version: int
|
||||
org_id: int = Field(default=None, foreign_key="organization.id")
|
||||
course_id: int = Field(default=None, foreign_key="course.id")
|
||||
|
||||
|
||||
class Activity(ActivityBase, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
activity_uuid: str
|
||||
creation_date: str
|
||||
update_date: str
|
||||
|
||||
|
||||
class ActivityCreate(ActivityBase):
|
||||
pass
|
||||
|
||||
|
||||
class ActivityRead(ActivityBase):
|
||||
id: int
|
||||
activity_uuid: str
|
||||
creation_date: str
|
||||
update_date: str
|
||||
pass
|
||||
44
apps/api/src/db/blocks.py
Normal file
44
apps/api/src/db/blocks.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
from typing import Optional
|
||||
from sqlalchemy import JSON, Column
|
||||
from sqlmodel import Field, SQLModel
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class BlockTypeEnum(str, Enum):
|
||||
QUIZ_BLOCK = "QUIZ_BLOCK"
|
||||
VIDEO_BLOCK = "VIDEO_BLOCK"
|
||||
DOCUMENT_PDF_BLOCK = "DOCUMENT_PDF_BLOCK"
|
||||
IMAGE_BLOCK = "IMAGE_BLOCK"
|
||||
CUSTOM = "CUSTOM"
|
||||
|
||||
|
||||
class BlockBase(SQLModel):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
block_type: BlockTypeEnum = BlockTypeEnum.CUSTOM
|
||||
content: dict = Field(default={}, sa_column=Column(JSON))
|
||||
|
||||
|
||||
class Block(BlockBase, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
content: dict = Field(default={}, sa_column=Column(JSON))
|
||||
org_id: int = Field(default=None, foreign_key="organization.id")
|
||||
course_id: int = Field(default=None, foreign_key="course.id")
|
||||
chapter_id: int = Field(default=None, foreign_key="chapter.id")
|
||||
activity_id: int = Field(default=None, foreign_key="activity.id")
|
||||
block_uuid: str
|
||||
creation_date: str
|
||||
update_date: str
|
||||
|
||||
class BlockCreate(BlockBase):
|
||||
pass
|
||||
|
||||
class BlockRead(BlockBase):
|
||||
id: int
|
||||
org_id: int = Field(default=None, foreign_key="organization.id")
|
||||
course_id: int = Field(default=None, foreign_key="course.id")
|
||||
chapter_id: int = Field(default=None, foreign_key="chapter.id")
|
||||
activity_id: int = Field(default=None, foreign_key="activity.id")
|
||||
block_uuid: str
|
||||
creation_date: str
|
||||
update_date: str
|
||||
pass
|
||||
13
apps/api/src/db/chapter_activities.py
Normal file
13
apps/api/src/db/chapter_activities.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
from typing import Optional
|
||||
from sqlmodel import Field, SQLModel
|
||||
from enum import Enum
|
||||
|
||||
class ChapterActivity(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
order: int
|
||||
chapter_id: int = Field(default=None, foreign_key="chapter.id")
|
||||
activity_id: int = Field(default=None, foreign_key="activity.id")
|
||||
course_id : int = Field(default=None, foreign_key="course.id")
|
||||
org_id : int = Field(default=None, foreign_key="organization.id")
|
||||
creation_date: str
|
||||
update_date: str
|
||||
30
apps/api/src/db/chapters.py
Normal file
30
apps/api/src/db/chapters.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
from typing import Optional
|
||||
from sqlmodel import Field, SQLModel
|
||||
|
||||
|
||||
class ChapterBase(SQLModel):
|
||||
name: str
|
||||
description: Optional[str] = ""
|
||||
thumbnail_image: Optional[str] = ""
|
||||
org_id: int = Field(default=None, foreign_key="organization.id")
|
||||
creation_date: str
|
||||
update_date: str
|
||||
|
||||
|
||||
class Chapter(ChapterBase, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
chapter_uuid: str
|
||||
creation_date: str
|
||||
update_date: str
|
||||
|
||||
|
||||
class ChapterCreate(ChapterBase):
|
||||
pass
|
||||
|
||||
|
||||
class ChapterRead(ChapterBase):
|
||||
id: int
|
||||
chapter_uuid: str
|
||||
creation_date: str
|
||||
update_date: str
|
||||
pass
|
||||
3
apps/api/src/db/collections.py
Normal file
3
apps/api/src/db/collections.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from typing import Optional
|
||||
from sqlmodel import Field, SQLModel
|
||||
from enum import Enum
|
||||
18
apps/api/src/db/course_authors.py
Normal file
18
apps/api/src/db/course_authors.py
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
from typing import Optional
|
||||
from sqlmodel import Field, SQLModel
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class CourseAuthorshipEnum(str, Enum):
|
||||
CREATOR = "CREATOR"
|
||||
MAINTAINER = "MAINTAINER"
|
||||
REPORTER = "REPORTER"
|
||||
|
||||
|
||||
class CourseAuthor(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
course_id: int = Field(default=None, foreign_key="course.id")
|
||||
user_id: int = Field(default=None, foreign_key="user.id")
|
||||
authorship: CourseAuthorshipEnum = CourseAuthorshipEnum.CREATOR
|
||||
creation_date: str
|
||||
update_date: str
|
||||
12
apps/api/src/db/course_chapters.py
Normal file
12
apps/api/src/db/course_chapters.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
from typing import Optional
|
||||
from sqlmodel import Field, SQLModel
|
||||
from enum import Enum
|
||||
|
||||
class CourseChapter(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
order: int
|
||||
course_id: int = Field(default=None, foreign_key="course.id")
|
||||
chapter_id: int = Field(default=None, foreign_key="chapter.id")
|
||||
org_id : int = Field(default=None, foreign_key="organization.id")
|
||||
creation_date: str
|
||||
update_date: str
|
||||
29
apps/api/src/db/courses.py
Normal file
29
apps/api/src/db/courses.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
from typing import Optional
|
||||
from sqlmodel import Field, SQLModel
|
||||
|
||||
class CourseBase(SQLModel):
|
||||
name: str
|
||||
description: Optional[str] = ""
|
||||
about: Optional[str] = ""
|
||||
course_slug: str
|
||||
learnings: Optional[str] = ""
|
||||
tags: Optional[str] = ""
|
||||
thumbnail_image: Optional[str] = ""
|
||||
public: bool
|
||||
|
||||
class Course(CourseBase, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
org_id: int = Field(default=None, foreign_key="organization.id")
|
||||
course_uuid: str
|
||||
creation_date: str
|
||||
update_date: str
|
||||
|
||||
class CourseCreate(CourseBase):
|
||||
pass
|
||||
|
||||
class CourseRead(CourseBase):
|
||||
id: int
|
||||
course_uuid: str
|
||||
creation_date: str
|
||||
update_date: str
|
||||
pass
|
||||
17
apps/api/src/db/organization_settings.py
Normal file
17
apps/api/src/db/organization_settings.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
from typing import Optional
|
||||
from sqlmodel import Field, SQLModel
|
||||
from enum import Enum
|
||||
|
||||
class HeaderTypeEnum(str, Enum):
|
||||
LOGO_MENU_SETTINGS = "LOGO_MENU_SETTINGS"
|
||||
MENU_LOGO_SETTINGS = "MENU_LOGO_SETTINGS"
|
||||
|
||||
|
||||
class OrganizationSettings(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
org_id: int = Field(default=None, foreign_key="organization.id")
|
||||
logo_image: Optional[str] = ""
|
||||
header_type: HeaderTypeEnum = HeaderTypeEnum.LOGO_MENU_SETTINGS
|
||||
color: str = ""
|
||||
creation_date: str
|
||||
update_date: str
|
||||
26
apps/api/src/db/organizations.py
Normal file
26
apps/api/src/db/organizations.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
from typing import Optional
|
||||
from sqlmodel import Field, SQLModel
|
||||
|
||||
|
||||
class OrganizationBase(SQLModel):
|
||||
name: str
|
||||
description: Optional[str] = ""
|
||||
slug: str
|
||||
email: str
|
||||
logo_image: Optional[str] = ""
|
||||
|
||||
|
||||
class Organization(OrganizationBase, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
org_uuid: str
|
||||
creation_date: str
|
||||
update_date: str
|
||||
|
||||
|
||||
class OrganizationCreate(OrganizationBase):
|
||||
pass
|
||||
|
||||
|
||||
class OrganizationRead(OrganizationBase):
|
||||
id: int
|
||||
org_uuid: str
|
||||
30
apps/api/src/db/roles.py
Normal file
30
apps/api/src/db/roles.py
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
from enum import Enum
|
||||
from typing import Optional
|
||||
from sqlalchemy import JSON, Column
|
||||
from sqlmodel import Field, SQLModel
|
||||
|
||||
|
||||
class RoleTypeEnum(str, Enum):
|
||||
ORGANIZATION = "ORGANIZATION"
|
||||
ORGANIZATION_API_TOKEN = "ORGANIZATION_API_TOKEN"
|
||||
GLOBAL = "GLOBAL"
|
||||
|
||||
|
||||
class RoleBase(SQLModel):
|
||||
name: str
|
||||
description: Optional[str] = ""
|
||||
rights: dict = Field(default={}, sa_column=Column(JSON))
|
||||
|
||||
|
||||
class Role(RoleBase, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
org_id: int = Field(default=None, foreign_key="organization.id")
|
||||
role_type: RoleTypeEnum = RoleTypeEnum.GLOBAL
|
||||
role_uuid: str
|
||||
creation_date: str
|
||||
update_date: str
|
||||
|
||||
|
||||
class RoleCreate(RoleBase):
|
||||
org_id: int = Field(default=None, foreign_key="organization.id")
|
||||
pass
|
||||
11
apps/api/src/db/user_organizations.py
Normal file
11
apps/api/src/db/user_organizations.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
from typing import Optional
|
||||
from sqlmodel import Field, SQLModel
|
||||
|
||||
|
||||
class UserOrganization(SQLModel, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
user_id: int = Field(default=None, foreign_key="user.id")
|
||||
org_id: int = Field(default=None, foreign_key="organization.id")
|
||||
role_id: int = Field(default=None, foreign_key="role.id")
|
||||
creation_date: str
|
||||
update_date: str
|
||||
43
apps/api/src/db/users.py
Normal file
43
apps/api/src/db/users.py
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
from typing import Optional
|
||||
from sqlmodel import Field, SQLModel
|
||||
|
||||
|
||||
class UserBase(SQLModel):
|
||||
username: str
|
||||
first_name: str
|
||||
last_name: str
|
||||
email: str
|
||||
avatar_image: Optional[str] = ""
|
||||
bio: Optional[str] = ""
|
||||
|
||||
|
||||
class UserCreate(UserBase):
|
||||
password: str
|
||||
|
||||
|
||||
class UserUpdate(UserBase):
|
||||
username: str
|
||||
first_name: Optional[str]
|
||||
last_name: Optional[str]
|
||||
email: str
|
||||
avatar_image: Optional[str] = ""
|
||||
bio: Optional[str] = ""
|
||||
|
||||
|
||||
class UserUpdatePassword(SQLModel):
|
||||
user_id: int
|
||||
old_password: str
|
||||
new_password: str
|
||||
|
||||
|
||||
class UserRead(UserBase):
|
||||
id: int
|
||||
|
||||
|
||||
class User(UserBase, table=True):
|
||||
id: Optional[int] = Field(default=None, primary_key=True)
|
||||
password: str = ""
|
||||
user_uuid: str = ""
|
||||
email_verified: bool = False
|
||||
creation_date: str = ""
|
||||
update_date: str = ""
|
||||
Loading…
Add table
Add a link
Reference in a new issue