Skip to content

Commit

Permalink
add input model
Browse files Browse the repository at this point in the history
  • Loading branch information
sepehrsh79 committed Sep 29, 2024
1 parent 4f763ac commit ecd7259
Show file tree
Hide file tree
Showing 11 changed files with 283 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""add deadline and remove specific_fild from Input
Revision ID: be17b4d24c42
Revises: e5f7771cc003
Create Date: 2024-09-29 17:14:22.289155
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'be17b4d24c42'
down_revision: Union[str, None] = 'e5f7771cc003'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('inputs', sa.Column('user_id', sa.UUID(), nullable=False))
op.create_foreign_key(None, 'inputs', 'users', ['user_id'], ['id'], ondelete='CASCADE')
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'inputs', type_='foreignkey')
op.drop_column('inputs', 'user_id')
# ### end Alembic commands ###
58 changes: 58 additions & 0 deletions alembic/versions/d092bc7439de_input_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""input model
Revision ID: d092bc7439de
Revises: e8f17ffb729b
Create Date: 2024-09-29 15:24:58.842708
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = 'd092bc7439de'
down_revision: Union[str, None] = 'e8f17ffb729b'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('inputs',
sa.Column('domain', sa.Enum('backend_development', 'frontend_development', 'data_science', 'machine_learning', 'artificial_intelligence', 'ui_ux', 'ios_development', 'android_development', 'hardware_programming', 'blockchain', 'game_development', 'dev_ops', 'cybersecurity_development', 'others', name='domainenum'), nullable=False),
sa.Column('specific_field', sa.String(), nullable=True),
sa.Column('level', sa.Enum('absolute_beginner', 'beginner', 'intermediate', 'advanced', name='levelenum'), nullable=False),
sa.Column('age', sa.Integer(), nullable=False),
sa.Column('goal', sa.String(), nullable=True),
sa.Column('learnig_style', sa.ARRAY(sa.String()), nullable=True),
sa.Column('cost_type', sa.Enum('free', 'paid', 'both', name='costtypeenum'), nullable=False),
sa.Column('need_certificate', sa.Boolean(), nullable=False),
sa.Column('learning_language', sa.String(), nullable=False),
sa.Column('join_community', sa.Boolean(), nullable=False),
sa.Column('time_commitment', sa.Enum('less_than_5', '_5_10', '_10_20', 'more_than_20', name='timecommitmentenum'), nullable=False),
sa.Column('id', sa.BigInteger(), autoincrement=True, nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_inputs_id'), 'inputs', ['id'], unique=True)
op.add_column('users', sa.Column('email', sa.String(), nullable=True))
op.drop_constraint('users_username_key', 'users', type_='unique')
op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True)
op.create_unique_constraint(None, 'users', ['id'])
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'users', type_='unique')
op.drop_index(op.f('ix_users_username'), table_name='users')
op.drop_index(op.f('ix_users_email'), table_name='users')
op.create_unique_constraint('users_username_key', 'users', ['username'])
op.drop_column('users', 'email')
op.drop_index(op.f('ix_inputs_id'), table_name='inputs')
op.drop_table('inputs')
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""add deadline and remove specific_fild from Input
Revision ID: e5f7771cc003
Revises: d092bc7439de
Create Date: 2024-09-29 16:05:42.511895
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision: str = 'e5f7771cc003'
down_revision: Union[str, None] = 'd092bc7439de'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('inputs', sa.Column('deadline', sa.Integer(), nullable=False))
op.alter_column('inputs', 'learnig_style',
existing_type=postgresql.ARRAY(sa.VARCHAR()),
nullable=False)
op.drop_column('inputs', 'specific_field')
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('inputs', sa.Column('specific_field', sa.VARCHAR(), autoincrement=False, nullable=True))
op.alter_column('inputs', 'learnig_style',
existing_type=postgresql.ARRAY(sa.VARCHAR()),
nullable=True)
op.drop_column('inputs', 'deadline')
# ### end Alembic commands ###
15 changes: 15 additions & 0 deletions src/enums/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from .input import (
LevelEnum,
LearningStyleEnum,
CostTypeEnum,
TimeCommitmentEnum,
DomainEnum,
)

__all__ = [
"LevelEnum",
"LearningStyleEnum",
"CostTypeEnum",
"TimeCommitmentEnum",
"DomainEnum",
]
45 changes: 45 additions & 0 deletions src/enums/input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import enum


class LevelEnum(enum.Enum):
absolute_beginner = "No coding experience"
beginner = "Some experience but limited knowledge"
intermediate = "Comfortable with basic coding concepts"
advanced = "Looking to specialize"


class LearningStyleEnum(enum.Enum):
video_tutorials = "Video tutorials"
articles_and_documentation = "Articles and documentation"
interactive_exercises = "Interactive coding exercises"
community_learning = "Community learning (forums, group projects)"


class CostTypeEnum(enum.Enum):
free = "Free"
paid = "Paid"
both = "Free and Paid"


class TimeCommitmentEnum(enum.Enum):
less_than_5 = "Less than 5 hours per week"
_5_10 = "5 to 10 hours per week"
_10_20 = "10 to 20 hours per week"
more_than_20 = "More than 20 hours per week"


class DomainEnum(enum.Enum):
backend_development = "Back-End Development"
frontend_development = "Front-End Development"
data_science = "Data Science"
machine_learning = "Machine Learning"
artificial_intelligence = "Artificial Intelligence"
ui_ux = "UI/UX"
ios_development = "IOS Development"
android_development = "Android Development"
hardware_programming = "Hardware Programming"
blockchain = "Blockchain"
game_development = "game Development"
dev_ops = "DevOps"
cybersecurity_development = "CyberSecurity Development"
others = "Others"
3 changes: 2 additions & 1 deletion src/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .user import User
from .input import Input

__all__ = ["User"]
__all__ = ["User", "Input"]
46 changes: 46 additions & 0 deletions src/models/input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from sqlalchemy import ARRAY, Enum, String, BigInteger, ForeignKey
from sqlalchemy.orm import Mapped, mapped_column, validates, relationship

from src.core.database.base import SQLBase
from src.core.database.mixin import TimestampMixin, IdMixin

from typing import Annotated, ForwardRef

from src.enums import (
LevelEnum,
LearningStyleEnum,
CostTypeEnum,
TimeCommitmentEnum,
DomainEnum,
)


class Input(SQLBase, IdMixin, TimestampMixin):
__tablename__ = "inputs"

user_id: Mapped[int] = mapped_column(
ForeignKey("users.id", ondelete="CASCADE"),
nullable=False,
)
user: Mapped["User"] = relationship("User", back_populates="inputs")
domain: Mapped[DomainEnum] = mapped_column(default=DomainEnum.others)
level: Mapped[LevelEnum] = mapped_column(default=LevelEnum.beginner)
age: Mapped[int]
goal: Mapped[str | None]
learnig_style: Mapped[str | list] = mapped_column(ARRAY(String()), default=[])
cost_type: Mapped[Annotated[CostTypeEnum, Enum(CostTypeEnum)]] = mapped_column(
default=CostTypeEnum.both
)
need_certificate: Mapped[bool] = mapped_column(default=False)
learning_language: Mapped[str] = mapped_column(default="English")
join_community: Mapped[bool] = mapped_column(default=False)
time_commitment: Mapped[TimeCommitmentEnum] = mapped_column(
default=TimeCommitmentEnum._10_20
) # Time commitment for learning per week
deadline: Mapped[int] = mapped_column(default=28)

@validates("deadline")
def validate_age(self, key, value):
if value <= 14:
raise ValueError(f"The deadline should be more than 14 days!")
return value
41 changes: 41 additions & 0 deletions src/models/roadmap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# from sqlalchemy import ARRAY, Enum, String
# from sqlalchemy.orm import Mapped, mapped_column, validates

# from src.core.database.base import SQLBase
# from src.core.database.mixin import TimestampMixin, IdMixin

# from typing import Annotated

# from src.enums import (
# LevelEnum,
# LearningStyleEnum,
# CostTypeEnum,
# TimeCommitmentEnum,
# DomainEnum,
# )


# class Roadmap(SQLBase, IdMixin, TimestampMixin):
# __tablename__ = "inputs"

# domain: Mapped[DomainEnum] = mapped_column(default=DomainEnum.others)
# level: Mapped[LevelEnum] = mapped_column(default=LevelEnum.beginner)
# age: Mapped[int]
# goal: Mapped[str | None]
# learnig_style: Mapped[str | list] = mapped_column(ARRAY(String()), default=[])
# cost_type: Mapped[Annotated[CostTypeEnum, Enum(CostTypeEnum)]] = mapped_column(
# default=CostTypeEnum.both
# )
# need_certificate: Mapped[bool] = mapped_column(default=False)
# learning_language: Mapped[str] = mapped_column(default="English")
# join_community: Mapped[bool] = mapped_column(default=False)
# time_commitment: Mapped[TimeCommitmentEnum] = mapped_column(
# default=TimeCommitmentEnum._10_20
# ) # Time commitment for learning per week
# deadline: Mapped[int] = mapped_column(default=28)

# @validates("deadline")
# def validate_age(self, key, value):
# if value <= 14:
# raise ValueError(f"The deadline should be more than 14 days!")
# return value
7 changes: 4 additions & 3 deletions src/models/user.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from sqlalchemy.orm import Mapped, mapped_column

from sqlalchemy.orm import Mapped, mapped_column, relationship
from src.core.database.base import SQLBase
from src.core.database.mixin import TimestampMixin, UUIDMixin


class User(SQLBase, UUIDMixin, TimestampMixin):
__tablename__ = "users"

username: Mapped[str] = mapped_column(unique=True, default=None)
username: Mapped[str] = mapped_column(unique=True, default=None, index=True)
password: Mapped[str] = mapped_column(default=None)
gauth: Mapped[str] = mapped_column(default=None)
email: Mapped[str | None] = mapped_column(unique=True, default=None, index=True)
inputs: Mapped[list["Input"]] = relationship(back_populates="users")
3 changes: 2 additions & 1 deletion src/schema/user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import datetime

from pydantic import BaseModel, Field
from pydantic import BaseModel, Field, EmailStr


class CurrentUser(BaseModel):
Expand All @@ -17,6 +17,7 @@ class UserIn(BaseModel):

class UserOut(CurrentUser):
username: str
email: EmailStr
updated_at: datetime.datetime
created_at: datetime.datetime

Expand Down
6 changes: 0 additions & 6 deletions todo.txt

This file was deleted.

0 comments on commit ecd7259

Please sign in to comment.