diff --git a/backend/blueprints/profile/__init__.py b/backend/blueprints/profile/__init__.py index edc594a..f87c59e 100644 --- a/backend/blueprints/profile/__init__.py +++ b/backend/blueprints/profile/__init__.py @@ -98,3 +98,20 @@ def register(): except Exception as e: db.session.rollback() return jsonify({"error": "Registration failed, please try again later."}), 500 + +# TODO: Implement laters +@profile.route('/update', methhods=['UPDATE', 'DELETE']) +def update(): + if request.method == 'DELETE': + pass + if request.method == 'UPDATE': + pass + +@profile.route('/me') +def my_profile(): + pass + +@profile.route('/info/') +def profile_info(user_uuid): + return user_uuid + diff --git a/backend/db/model.py b/backend/db/model.py index 6e64434..be44ffe 100644 --- a/backend/db/model.py +++ b/backend/db/model.py @@ -29,6 +29,7 @@ class User(db.Model): chats: Mapped[List["Chat"]] = relationship(back_populates="user", cascade="all, delete-orphan") notifications: Mapped[List["Notification"]] = relationship(back_populates="user", cascade="all, delete-orphan") user_badges: Mapped[List["UserBadge"]] = relationship(back_populates="user", cascade="all, delete-orphan") + publications: Mapped[List["Course"]] = relationship(back_populates="author", cascade="all, delete-orphan") dob: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=datetime.fromisocalendar(2002, 1, 1)) pfpFilename: Mapped[str] = mapped_column(String(256), nullable=False, default=DEFAULT_PROFILE_FILE) joinedDate: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=func.now()) @@ -75,6 +76,8 @@ class Course(db.Model): creationDate: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=func.now()) coverImage: Mapped[str] = mapped_column(String(256), nullable=False, default=DEFAULT_COURSE_COVER) serverFilename: Mapped[str] = mapped_column(String(256), nullable=False, default='') + authorID: Mapped[uuid.UUID] = mapped_column(ForeignKey("user.id")) + author: Mapped["User"] = relationship(back_populates="publications") class Enrollment(db.Model): diff --git a/backend/utils/auth.py b/backend/utils/auth.py index fb490cd..fe60db9 100644 --- a/backend/utils/auth.py +++ b/backend/utils/auth.py @@ -3,9 +3,8 @@ from flask import request, jsonify from sqlalchemy import select, and_ from ..db.model import User, Session, db from ..constants import UserRole -from typing import Union -def requires_role(roles: Union[None, UserRole] = None): +def requires_role(roles=None): if roles is None: roles = [UserRole.USER] roles = [int(r) for r in roles]