From 0a4f3920a980eca63123ef44b659581857cf89c1 Mon Sep 17 00:00:00 2001 From: Andrei Duvakin Date: Sun, 26 Jan 2025 15:20:08 +0500 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BB=20=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D1=8B=D0=B5=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86?= =?UTF-8?q?=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../database/models/course_students.py | 2 +- .../infrastructure/database/models/courses.py | 1 + .../database/models/notification_types.py | 14 ++++++++++++ .../database/models/notifications.py | 22 +++++++++++++++++++ .../infrastructure/database/models/users.py | 1 + 5 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 API/app/infrastructure/database/models/notification_types.py create mode 100644 API/app/infrastructure/database/models/notifications.py diff --git a/API/app/infrastructure/database/models/course_students.py b/API/app/infrastructure/database/models/course_students.py index c7030ff..c761c1f 100644 --- a/API/app/infrastructure/database/models/course_students.py +++ b/API/app/infrastructure/database/models/course_students.py @@ -1,4 +1,4 @@ -from sqlalchemy import Column, Integer, VARCHAR, String, ForeignKey, Date, Boolean +from sqlalchemy import Column, Integer, ForeignKey, Date, Boolean from sqlalchemy.sql import func from sqlalchemy.orm import relationship diff --git a/API/app/infrastructure/database/models/courses.py b/API/app/infrastructure/database/models/courses.py index 4a6ccd2..4fcb2a3 100644 --- a/API/app/infrastructure/database/models/courses.py +++ b/API/app/infrastructure/database/models/courses.py @@ -18,3 +18,4 @@ class Course(Base): owner_user = relationship('User', back_populates='owned_courses') students = relationship('CourseStudent', back_populates='course') + notifications = relationship('Notification', back_populates='course') diff --git a/API/app/infrastructure/database/models/notification_types.py b/API/app/infrastructure/database/models/notification_types.py new file mode 100644 index 0000000..67c5672 --- /dev/null +++ b/API/app/infrastructure/database/models/notification_types.py @@ -0,0 +1,14 @@ +from sqlalchemy import Column, Integer, VARCHAR, String +from sqlalchemy.orm import relationship + +from app.infrastructure.database.models import Base + + +class NotificationType(Base): + __tablename__ = 'notification_types' + + id = Column(Integer, primary_key=True, autoincrement=True) + title = Column(VARCHAR(100), nullable=False) + description = Column(String, nullable=False) + + notifications = relationship('Notification', back_populates='type') diff --git a/API/app/infrastructure/database/models/notifications.py b/API/app/infrastructure/database/models/notifications.py new file mode 100644 index 0000000..1707fed --- /dev/null +++ b/API/app/infrastructure/database/models/notifications.py @@ -0,0 +1,22 @@ +from sqlalchemy import Column, Integer, Boolean, String, DateTime, ForeignKey +from sqlalchemy.sql import func +from sqlalchemy.orm import relationship + +from app.infrastructure.database.models import Base + + +class Notification(Base): + __tablename__ = 'notifications' + + id = Column(Integer, primary_key=True, autoincrement=True) + text = Column(String, nullable=False) + datetime_notification = Column(DateTime, nullable=False, default=func.utcnow) + is_read = Column(Boolean, nullable=False, default=False) + + user_id = Column(Integer, ForeignKey('users.id'), nullable=False) + type_id = Column(Integer, ForeignKey('notification_types.id'), nullable=False) + course_id = Column(Integer, ForeignKey('courses.id')) + + user = relationship('User', back_populates='notifications') + type = relationship('NotificationType', back_populates='notifications') + course = relationship('Course', back_populates='notifications') diff --git a/API/app/infrastructure/database/models/users.py b/API/app/infrastructure/database/models/users.py index 0498078..4310f90 100644 --- a/API/app/infrastructure/database/models/users.py +++ b/API/app/infrastructure/database/models/users.py @@ -35,6 +35,7 @@ class User(Base): appeals = relationship('Appeal', back_populates='user') owned_courses = relationship('Course', back_populates='owned_courses') enrolled_courses = relationship('CourseStudent', back_populates='user') + notifications = relationship('Notification', back_populates='user') def check_password(self, password): return check_password_hash(self.password, password)