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)