создал новые таблицы
This commit is contained in:
parent
6ddc4d0e78
commit
afb348167d
32
API/app/infrastructure/database/models/appeals.py
Normal file
32
API/app/infrastructure/database/models/appeals.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
from enum import Enum as PyEnum
|
||||||
|
|
||||||
|
from sqlalchemy import Column, Integer, String, DateTime, Enum, ForeignKey
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
from sqlalchemy.sql import func
|
||||||
|
|
||||||
|
from app.infrastructure.database.models import Base
|
||||||
|
|
||||||
|
|
||||||
|
class AppealStatusEnum(PyEnum):
|
||||||
|
NEW = 'новое'
|
||||||
|
IN_PROGRESS = 'в работе'
|
||||||
|
WAITING_FOR_USER_RESPONSE = 'ожидание ответа пользователя'
|
||||||
|
WAITING_FOR_SPECIALIST_RESPONSE = 'ожидание ответа специалиста'
|
||||||
|
RESOLVED = 'решено'
|
||||||
|
CLOSED = 'закрыто'
|
||||||
|
REJECTED = 'отклонено'
|
||||||
|
|
||||||
|
|
||||||
|
class Appeal(Base):
|
||||||
|
__tablename__ = 'appeals'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
message = Column(String, nullable=False)
|
||||||
|
created_date = Column(DateTime, nullable=False, default=func.utcnow)
|
||||||
|
status = Column(Enum(AppealStatusEnum), nullable=False, default=AppealStatusEnum.NEW)
|
||||||
|
|
||||||
|
topic_id = Column(Integer, ForeignKey('appeals_topics.id'), nullable=False)
|
||||||
|
user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
|
||||||
|
|
||||||
|
topic = relationship('AppealsTopic', back_populates='appeals')
|
||||||
|
user = relationship('User', back_populates='appeals')
|
||||||
13
API/app/infrastructure/database/models/appeals_topics.py
Normal file
13
API/app/infrastructure/database/models/appeals_topics.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
from sqlalchemy import Column, Integer, VARCHAR
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
|
from app.infrastructure.database.models import Base
|
||||||
|
|
||||||
|
|
||||||
|
class AppealsTopic(Base):
|
||||||
|
__tablename__ = 'appeals_topics'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
title = Column(VARCHAR(500), nullable=False)
|
||||||
|
|
||||||
|
appeals = relationship('Appeal', back_populates='topic')
|
||||||
14
API/app/infrastructure/database/models/categories.py
Normal file
14
API/app/infrastructure/database/models/categories.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from sqlalchemy import Column, Integer, VARCHAR, String
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
|
from app.infrastructure.database.models import Base
|
||||||
|
|
||||||
|
|
||||||
|
class Category(Base):
|
||||||
|
__tablename__ = 'categories'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
title = Column(VARCHAR(200), nullable=False)
|
||||||
|
description = Column(String, nullable=False)
|
||||||
|
|
||||||
|
courses = relationship('Course', back_populates='category')
|
||||||
20
API/app/infrastructure/database/models/course_students.py
Normal file
20
API/app/infrastructure/database/models/course_students.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from sqlalchemy import Column, Integer, VARCHAR, String, ForeignKey, Date, Boolean
|
||||||
|
from sqlalchemy.sql import func
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
|
from app.infrastructure.database.models import Base
|
||||||
|
|
||||||
|
|
||||||
|
class CourseStudent(Base):
|
||||||
|
__tablename__ = 'course_students'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
enrollment_date = Column(Date, nullable=False, default=func.utcnow)
|
||||||
|
is_finished = Column(Boolean, nullable=False, default=False)
|
||||||
|
|
||||||
|
course_id = Column(Integer, ForeignKey('courses.id'), nullable=False)
|
||||||
|
user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
|
||||||
|
|
||||||
|
course = relationship('Course', back_populates='students')
|
||||||
|
user = relationship('User', back_populates='enrolled_courses')
|
||||||
|
|
||||||
20
API/app/infrastructure/database/models/courses.py
Normal file
20
API/app/infrastructure/database/models/courses.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from sqlalchemy import Column, Integer, VARCHAR, String, ForeignKey
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
|
from app.infrastructure.database.models import Base
|
||||||
|
|
||||||
|
|
||||||
|
class Course(Base):
|
||||||
|
__tablename__ = 'courses'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
|
title = Column(VARCHAR(200), nullable=False)
|
||||||
|
description = Column(String, nullable=False)
|
||||||
|
|
||||||
|
category_id = Column(Integer, ForeignKey('categories.id'), nullable=False)
|
||||||
|
owner_user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
|
||||||
|
|
||||||
|
category = relationship('Category', back_populates='courses')
|
||||||
|
owner_user = relationship('User', back_populates='owned_courses')
|
||||||
|
|
||||||
|
students = relationship('CourseStudent', back_populates='course')
|
||||||
@ -9,3 +9,5 @@ class Role(Base):
|
|||||||
|
|
||||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
title = Column(VARCHAR(100), nullable=False)
|
title = Column(VARCHAR(100), nullable=False)
|
||||||
|
|
||||||
|
users = relationship('User', back_populates='role')
|
||||||
|
|||||||
@ -1,13 +1,12 @@
|
|||||||
import datetime
|
|
||||||
|
|
||||||
from sqlalchemy import Column, Integer, VARCHAR, Enum, DateTime, Date, String
|
|
||||||
from sqlalchemy.sql import func
|
|
||||||
|
|
||||||
from enum import Enum as PyEnum
|
from enum import Enum as PyEnum
|
||||||
|
|
||||||
from app.infrastructure.database.models import Base
|
from sqlalchemy import Column, Integer, VARCHAR, Enum, DateTime, Date, String, ForeignKey
|
||||||
|
from sqlalchemy.orm import relationship
|
||||||
|
from sqlalchemy.sql import func
|
||||||
from werkzeug.security import check_password_hash, generate_password_hash
|
from werkzeug.security import check_password_hash, generate_password_hash
|
||||||
|
|
||||||
|
from app.infrastructure.database.models import Base
|
||||||
|
|
||||||
|
|
||||||
class UserGenderEnum(PyEnum):
|
class UserGenderEnum(PyEnum):
|
||||||
MALE = 'мужской'
|
MALE = 'мужской'
|
||||||
@ -29,6 +28,14 @@ class User(Base):
|
|||||||
password = Column(String, nullable=False)
|
password = Column(String, nullable=False)
|
||||||
email = Column(VARCHAR(200), nullable=False)
|
email = Column(VARCHAR(200), nullable=False)
|
||||||
|
|
||||||
|
role_id = Column(Integer, ForeignKey('roles.id'), nullable=False)
|
||||||
|
|
||||||
|
role = relationship('Role', back_populates='users')
|
||||||
|
|
||||||
|
appeals = relationship('Appeal', back_populates='user')
|
||||||
|
owned_courses = relationship('Course', back_populates='owned_courses')
|
||||||
|
enrolled_courses = relationship('CourseStudent', back_populates='user')
|
||||||
|
|
||||||
def check_password(self, password):
|
def check_password(self, password):
|
||||||
return check_password_hash(self.password, password)
|
return check_password_hash(self.password, password)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user