-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/models #8
Closed
Closed
Feat/models #8
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
"""models | ||
|
||
Revision ID: f880265a392e | ||
Revises: 4098f76764d4 | ||
Create Date: 2023-12-09 05:40:57.506690 | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'f880265a392e' | ||
down_revision = '4098f76764d4' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table('achievement', | ||
sa.Column('name', sa.String(length=100), nullable=False), | ||
sa.Column('description', sa.Text(), nullable=True), | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.PrimaryKeyConstraint('id'), | ||
sa.UniqueConstraint('name') | ||
) | ||
op.create_table('course', | ||
sa.Column('name', sa.String(length=100), nullable=False), | ||
sa.Column('description', sa.Text(), nullable=True), | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.PrimaryKeyConstraint('id'), | ||
sa.UniqueConstraint('name') | ||
) | ||
op.create_table('examination', | ||
sa.Column('name', sa.String(length=100), nullable=False), | ||
sa.Column('description', sa.Text(), nullable=True), | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.PrimaryKeyConstraint('id'), | ||
sa.UniqueConstraint('name') | ||
) | ||
op.create_table('group', | ||
sa.Column('name', sa.String(length=100), nullable=False), | ||
sa.Column('description', sa.Text(), nullable=True), | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.PrimaryKeyConstraint('id'), | ||
sa.UniqueConstraint('name') | ||
) | ||
op.create_table('notification', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_table('tariff', | ||
sa.Column('name', sa.String(length=100), nullable=False), | ||
sa.Column('description', sa.Text(), nullable=True), | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.PrimaryKeyConstraint('id'), | ||
sa.UniqueConstraint('name') | ||
) | ||
op.create_table('task', | ||
sa.Column('name', sa.String(length=100), nullable=False), | ||
sa.Column('description', sa.Text(), nullable=True), | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.PrimaryKeyConstraint('id'), | ||
sa.UniqueConstraint('name') | ||
) | ||
op.create_table('course_tariff_association', | ||
sa.Column('course_id', sa.Integer(), nullable=True), | ||
sa.Column('tariff_id', sa.Integer(), nullable=True), | ||
sa.ForeignKeyConstraint(['course_id'], ['course.id'], ), | ||
sa.ForeignKeyConstraint(['tariff_id'], ['tariff.id'], ) | ||
) | ||
op.create_table('course_task_association', | ||
sa.Column('course_id', sa.Integer(), nullable=True), | ||
sa.Column('task_id', sa.Integer(), nullable=True), | ||
sa.ForeignKeyConstraint(['course_id'], ['course.id'], ), | ||
sa.ForeignKeyConstraint(['task_id'], ['task.id'], ) | ||
) | ||
op.create_table('group_user_association', | ||
sa.Column('user_id', sa.Integer(), nullable=True), | ||
sa.Column('group_id', sa.Integer(), nullable=True), | ||
sa.ForeignKeyConstraint(['group_id'], ['group.id'], ), | ||
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ) | ||
) | ||
op.create_table('profile', | ||
sa.Column('first_name', sa.String(length=100), nullable=True), | ||
sa.Column('second_name', sa.String(length=100), nullable=True), | ||
sa.Column('age', sa.SmallInteger(), nullable=True), | ||
sa.Column('user_id', sa.Integer(), nullable=True), | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), | ||
sa.PrimaryKeyConstraint('id') | ||
) | ||
op.create_table('user_notification_association', | ||
sa.Column('user_id', sa.Integer(), nullable=True), | ||
sa.Column('notification_id', sa.Integer(), nullable=True), | ||
sa.ForeignKeyConstraint(['notification_id'], ['notification.id'], ), | ||
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ) | ||
) | ||
op.create_table('usercourse', | ||
sa.Column('user_id', sa.Integer(), nullable=False), | ||
sa.Column('course_id', sa.Integer(), nullable=False), | ||
sa.Column('progress', sa.SmallInteger(), nullable=True), | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.ForeignKeyConstraint(['course_id'], ['course.id'], ), | ||
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), | ||
sa.PrimaryKeyConstraint('user_id', 'course_id', 'id') | ||
) | ||
op.create_table('userexamination', | ||
sa.Column('user_id', sa.Integer(), nullable=False), | ||
sa.Column('examination_id', sa.Integer(), nullable=False), | ||
sa.Column('progress', sa.SmallInteger(), nullable=True), | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.ForeignKeyConstraint(['examination_id'], ['examination.id'], ), | ||
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ), | ||
sa.PrimaryKeyConstraint('user_id', 'examination_id', 'id') | ||
) | ||
op.create_table('achievement_profile_association', | ||
sa.Column('profile_id', sa.Integer(), nullable=True), | ||
sa.Column('achievement_id', sa.Integer(), nullable=True), | ||
sa.ForeignKeyConstraint(['achievement_id'], ['achievement.id'], ), | ||
sa.ForeignKeyConstraint(['profile_id'], ['profile.id'], ) | ||
) | ||
with op.batch_alter_table('user', schema=None) as batch_op: | ||
batch_op.add_column(sa.Column('role', sa.Enum('user', 'manager', 'admin', name='userroleenum'), nullable=False)) | ||
batch_op.add_column(sa.Column('username', sa.String(length=100), nullable=False)) | ||
batch_op.add_column(sa.Column('tariff_id', sa.Integer(), nullable=True)) | ||
batch_op.create_foreign_key('fk_user_tariff_id_tariff', 'tariff', ['tariff_id'], ['id']) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table('user', schema=None) as batch_op: | ||
batch_op.drop_constraint(None, type_='foreignkey') | ||
batch_op.drop_column('tariff_id') | ||
batch_op.drop_column('username') | ||
batch_op.drop_column('role') | ||
|
||
op.drop_table('achievement_profile_association') | ||
op.drop_table('userexamination') | ||
op.drop_table('usercourse') | ||
op.drop_table('user_notification_association') | ||
op.drop_table('profile') | ||
op.drop_table('group_user_association') | ||
op.drop_table('course_task_association') | ||
op.drop_table('course_tariff_association') | ||
op.drop_table('task') | ||
op.drop_table('tariff') | ||
op.drop_table('notification') | ||
op.drop_table('group') | ||
op.drop_table('examination') | ||
op.drop_table('course') | ||
op.drop_table('achievement') | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .user import router as user_router # noqa | ||
from .group import router as group_router # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from typing import List | ||
|
||
from fastapi import APIRouter, Depends | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
|
||
from app.schemas.group import GroupRead, GroupCreate | ||
from app.core.db import get_async_session | ||
from app.crud import group_crud | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get('/', response_model=List[GroupRead]) | ||
async def get_all_groups( | ||
session: AsyncSession = Depends(get_async_session) | ||
) -> List[GroupRead]: | ||
"""Возвращает все группы.""" | ||
return await group_crud.get_multi(session) | ||
|
||
|
||
@router.post('/', response_model=GroupRead) | ||
async def create_group( | ||
group: GroupCreate, | ||
session: AsyncSession = Depends(get_async_session) | ||
): | ||
"""Создать группу""" # For admin? | ||
# TODO Check name duplicate | ||
group = await group_crud.create( | ||
obj_in=group, session=session | ||
) | ||
session.add(group) | ||
await session.commit() | ||
await session.refresh(group) | ||
return group |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
from fastapi import APIRouter | ||
|
||
from app.api.endpoints import ( | ||
user_router, | ||
user_router, group_router | ||
) | ||
|
||
main_router = APIRouter() | ||
|
||
main_router.include_router(user_router) | ||
main_router.include_router( | ||
group_router, prefix='/group', tags=['Group'] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .group import group_crud # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from app.crud.base import CRUDBase | ||
from app.models.group import Group | ||
|
||
|
||
class CRUDGroup(CRUDBase): | ||
pass | ||
|
||
|
||
group_crud = CRUDGroup(Group) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
from .user import User # noqa | ||
from .group import Group # noqa | ||
from .achievements import Achievement # noqa | ||
from .courses import Course # noqa | ||
from .examinations import Examination # noqa | ||
from .notifications import Notification # noqa | ||
from .profiles import Profile # noqa | ||
from .tariffs import Tariff # noqa | ||
from .tasks import Task # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from sqlalchemy.orm import relationship | ||
|
||
from app.core.db import Base | ||
from app.models.base import AbstractBaseMixin | ||
from app.models.associations import achievement_profile_association | ||
|
||
|
||
class Achievement(AbstractBaseMixin, Base): | ||
profiles = relationship( | ||
'Profile', | ||
secondary=achievement_profile_association, | ||
back_populates='profiles' | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
внутри метода базвого круда уже есть add, commit и refresh
crud/base: 35-37
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
группы проверял. создавал. но связь с юзером не проверял. тут понять какая ручка будет. К юзеру добавлем группу или к группе юзера? И кто это делает: сам юзер или менеджер или оба могут сделать?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
я в новом пр поправил это дело,
У нас же многие ко многим через связующую модельку )