class Coach(db.Model): """ Coach model in the database """ __tablename__ = "coach" id = db.Column(db.Integer, primary_key=True, autoincrement=True) email = db.Column(db.String(255), unique=True, nullable=False) username = db.Column(db.String(100), nullable=False) public_id = db.Column(db.String(100), nullable=False) password_hash = db.Column(db.String(100), nullable=False) registered_on = db.Column(db.DateTime, nullable=False) phone_number = db.Column(db.String(20)) teams = db.relationship('Team', backref='coach', lazy=True) memo = db.relationship('Memo', backref='coach', lazy=True) @property def password(self): raise AttributeError('password: write-only field') @password.setter def password(self, password): self.password_hash = flask_bcrypt.generate_password_hash( password).decode('utf-8') def check_password(self, password): return flask_bcrypt.check_password_hash(self.password_hash, password) def __repr__(self): return "Coach {}".format(self.username)
class Athlete(db.Model): """ Athlete model in the database """ __tablename__ = "athlete" id = db.Column(db.Integer, primary_key=True, autoincrement=True) email = db.Column(db.String(100), unique=True) username = db.Column(db.String(100), nullable=False) registered_on = db.Column(db.DateTime, nullable=False) public_id = db.Column(db.String(100), nullable=False) team_id = db.Column(db.Integer, db.ForeignKey('team.id')) password_hash = db.Column(db.String(100), nullable=False) phone_number = db.Column(db.String(20)), jersey_number = db.Column(db.Integer) @property def password(self): raise AttributeError('password: write-only field') @password.setter def password(self, password): self.password_hash = flask_bcrypt.generate_password_hash( password).decode('utf-8') def check_password(self, password): return flask_bcrypt.check_password_hash(self.password_hash, password) def __repr__(self): return "Coach {}".format(self.username)
class Memo(db.Model): __tablename__ = 'memo' id = db.Column(db.Integer, primary_key=True, autoincrement=True) type = db.Column(db.String(50), nullable=False) duration = db.Column(db.Integer, nullable=False) date = db.Column(db.DateTime, nullable=False) location = db.Column(db.String(100), nullable=False) coach = db.Column(db.Integer, db.ForeignKey('coach.id')) team = db.Column(db.Integer, db.ForeignKey('team.id'))
class Team(db.Model): __tablename__ = 'team' id = db.Column(db.Integer, primary_key=True, autoincrement=True) name = db.Column(db.String(100), nullable=False) owner_id = db.Column(db.Integer, db.ForeignKey('coach.id')) logo = db.Column(db.String(255), nullable=False, unique=True) public_id = db.Column(db.String(100), unique=True) invite_code = db.Column(db.String(5), unique=True) created_at = db.Column(db.DateTime, nullable=False) squad = db.relationship('Athlete', backref='team', lazy=True) memo = db.relationship('Memo', backref='team', lazy=True)
class BlacklistToken(db.Model): """ token model for storing jwt token """ __tablename__ = 'blacklist_token' id = db.Column(db.Integer, primary_key=True, autoincrement=True) token = db.Column(db.String(500), unique=True, nullable=False) blacklisted_on = db.Column(db.DateTime, nullable=False) def __init__(self, token): self.token = token self.blacklisted_on = datetime.datetime.now() def __repr__(self): return '<id: token: {}>'.format(self.token) @staticmethod def check_blacklist(auth_token): # check whether Auth token has been blacklisted res = BlacklistToken.query.filter_by(token=str(auth_token)).first() if res: return True else: return False