from flask_sqlalchemy import SQLAlchemy from flask_bcrypt import Bcrypt import uuid db = SQLAlchemy() bcrypt = Bcrypt() class Event(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) description = db.Column(db.String(200)) location = db.Column(db.String(100)) deleted = db.Column(db.Boolean, default=False) duedate = db.Column(db.DateTime) created_at = db.Column(db.DateTime, default=db.func.now()) def to_dict(self): return { 'id': self.id, 'title': self.title, 'description': self.description, 'location': self.location, 'duedate': self.duedate.isoformat() if self.duedate else None, 'created_at': self.created_at.isoformat() } class User(db.Model): id = db.Column(db.String(36), primary_key=True, default=lambda: str(uuid.uuid4())) name = db.Column(db.String(100)) email = db.Column(db.String(120), unique=True, nullable=False) password_hash = db.Column(db.String(128)) location = db.Column(db.String(100), nullable=False) def set_password(self, password): self.password_hash = bcrypt.generate_password_hash(password).decode('utf-8') def check_password(self, password): return bcrypt.check_password_hash(self.password_hash, password) def to_dict(self): return { 'id': self.id, 'name': self.name, 'email': self.email, 'location': self.location }