
- 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>
68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
from typing import Any, List
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
from sqlalchemy.orm import Session
|
|
from app.api import deps
|
|
from app.models.user import User
|
|
from app.schemas.class_schema import Class, ClassCreate, ClassUpdate
|
|
from app.services.class_service import class_service
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/", response_model=List[Class])
|
|
def read_classes(
|
|
db: Session = Depends(deps.get_db),
|
|
skip: int = 0,
|
|
limit: int = 100,
|
|
current_user: User = Depends(deps.get_current_active_user),
|
|
) -> Any:
|
|
classes = class_service.get_multi(db, skip=skip, limit=limit)
|
|
return classes
|
|
|
|
@router.post("/", response_model=Class)
|
|
def create_class(
|
|
*,
|
|
db: Session = Depends(deps.get_db),
|
|
class_in: ClassCreate,
|
|
current_user: User = Depends(deps.get_current_admin_user),
|
|
) -> Any:
|
|
class_obj = class_service.create(db, obj_in=class_in)
|
|
return class_obj
|
|
|
|
@router.put("/{class_id}", response_model=Class)
|
|
def update_class(
|
|
*,
|
|
db: Session = Depends(deps.get_db),
|
|
class_id: int,
|
|
class_in: ClassUpdate,
|
|
current_user: User = Depends(deps.get_current_admin_user),
|
|
) -> Any:
|
|
class_obj = class_service.get(db, id=class_id)
|
|
if not class_obj:
|
|
raise HTTPException(status_code=404, detail="Class not found")
|
|
class_obj = class_service.update(db, db_obj=class_obj, obj_in=class_in)
|
|
return class_obj
|
|
|
|
@router.get("/{class_id}", response_model=Class)
|
|
def read_class(
|
|
*,
|
|
db: Session = Depends(deps.get_db),
|
|
class_id: int,
|
|
current_user: User = Depends(deps.get_current_active_user),
|
|
) -> Any:
|
|
class_obj = class_service.get(db, id=class_id)
|
|
if not class_obj:
|
|
raise HTTPException(status_code=404, detail="Class not found")
|
|
return class_obj
|
|
|
|
@router.delete("/{class_id}", response_model=Class)
|
|
def delete_class(
|
|
*,
|
|
db: Session = Depends(deps.get_db),
|
|
class_id: int,
|
|
current_user: User = Depends(deps.get_current_admin_user),
|
|
) -> Any:
|
|
class_obj = class_service.get(db, id=class_id)
|
|
if not class_obj:
|
|
raise HTTPException(status_code=404, detail="Class not found")
|
|
class_obj = class_service.remove(db, id=class_id)
|
|
return class_obj |