Automated Action 5a02fb8b1f Implement comprehensive school portal API with FastAPI
- Complete authentication system with JWT and role-based access control
- User management for Admin, Teacher, Student, and Parent roles
- Student management with CRUD operations
- Class management and assignment system
- Subject and grade tracking functionality
- Daily attendance marking and viewing
- Notification system for announcements
- SQLite database with Alembic migrations
- Comprehensive API documentation with Swagger/ReDoc
- Proper project structure with services, models, and schemas
- Environment variable configuration
- CORS support and security features

🤖 Generated with BackendIM

Co-Authored-By: BackendIM <noreply@anthropic.com>
2025-06-25 13:31:56 +00:00

35 lines
1.6 KiB
Python

from sqlalchemy import Column, Integer, String, Boolean, DateTime, Enum, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func
import enum
from app.db.base import Base
class UserRole(str, enum.Enum):
ADMIN = "admin"
TEACHER = "teacher"
STUDENT = "student"
PARENT = "parent"
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True, index=True)
email = Column(String, unique=True, index=True, nullable=False)
hashed_password = Column(String, nullable=False)
first_name = Column(String, nullable=False)
last_name = Column(String, nullable=False)
role = Column(Enum(UserRole), nullable=False)
is_active = Column(Boolean, default=True)
created_at = Column(DateTime(timezone=True), server_default=func.now())
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
parent_id = Column(Integer, ForeignKey("users.id"), nullable=True)
class_id = Column(Integer, ForeignKey("classes.id"), nullable=True)
parent = relationship("User", remote_side=[id], backref="children")
assigned_class = relationship("Class", back_populates="students")
taught_classes = relationship("Class", secondary="teacher_classes", back_populates="teachers")
grades = relationship("Grade", back_populates="student")
attendance_records = relationship("Attendance", back_populates="student")
sent_notifications = relationship("Notification", foreign_keys="Notification.sender_id", back_populates="sender")
received_notifications = relationship("Notification", secondary="notification_recipients", back_populates="recipients")