This repository has been archived by the owner on Jan 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed is_teacher and is_admin, changed to role enum (#127)
* Removed is_teacher and is_admin, changed to role enum * sql enum type * usage of enum and fixed sql * made role serializable * clean * docs * fixed user patch * args vs json * test
- Loading branch information
Showing
10 changed files
with
158 additions
and
138 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,17 +1,30 @@ | ||
"""User model""" | ||
|
||
from enum import Enum | ||
from dataclasses import dataclass | ||
from sqlalchemy import Boolean, Column, String | ||
from sqlalchemy import Column, String, Enum as EnumField | ||
from project.db_in import db | ||
|
||
class Role(Enum): | ||
"""This class defines the roles of a user""" | ||
STUDENT = 0 | ||
TEACHER = 1 | ||
ADMIN = 2 | ||
|
||
@dataclass | ||
class User(db.Model): | ||
"""This class defines the users table, | ||
a user has a uid, | ||
is_teacher and is_admin booleans because a user | ||
a user has a uid and a role, a user | ||
can be either a student,admin or teacher""" | ||
|
||
__tablename__ = "users" | ||
uid: str = Column(String(255), primary_key=True) | ||
is_teacher: bool = Column(Boolean) | ||
is_admin: bool = Column(Boolean) | ||
role: Role = Column(EnumField(Role), nullable=False) | ||
def to_dict(self): | ||
""" | ||
Converts a User to a serializable dict | ||
""" | ||
return { | ||
'uid': self.uid, | ||
'role': self.role.name, # Convert the enum to a string | ||
} |
Oops, something went wrong.