
- 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.2 KiB
Python
68 lines
2.2 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.subject import Subject, SubjectCreate, SubjectUpdate
|
|
from app.services.subject import subject_service
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/", response_model=List[Subject])
|
|
def read_subjects(
|
|
db: Session = Depends(deps.get_db),
|
|
skip: int = 0,
|
|
limit: int = 100,
|
|
current_user: User = Depends(deps.get_current_active_user),
|
|
) -> Any:
|
|
subjects = subject_service.get_multi(db, skip=skip, limit=limit)
|
|
return subjects
|
|
|
|
@router.post("/", response_model=Subject)
|
|
def create_subject(
|
|
*,
|
|
db: Session = Depends(deps.get_db),
|
|
subject_in: SubjectCreate,
|
|
current_user: User = Depends(deps.get_current_admin_user),
|
|
) -> Any:
|
|
subject = subject_service.create(db, obj_in=subject_in)
|
|
return subject
|
|
|
|
@router.put("/{subject_id}", response_model=Subject)
|
|
def update_subject(
|
|
*,
|
|
db: Session = Depends(deps.get_db),
|
|
subject_id: int,
|
|
subject_in: SubjectUpdate,
|
|
current_user: User = Depends(deps.get_current_admin_user),
|
|
) -> Any:
|
|
subject = subject_service.get(db, id=subject_id)
|
|
if not subject:
|
|
raise HTTPException(status_code=404, detail="Subject not found")
|
|
subject = subject_service.update(db, db_obj=subject, obj_in=subject_in)
|
|
return subject
|
|
|
|
@router.get("/{subject_id}", response_model=Subject)
|
|
def read_subject(
|
|
*,
|
|
db: Session = Depends(deps.get_db),
|
|
subject_id: int,
|
|
current_user: User = Depends(deps.get_current_active_user),
|
|
) -> Any:
|
|
subject = subject_service.get(db, id=subject_id)
|
|
if not subject:
|
|
raise HTTPException(status_code=404, detail="Subject not found")
|
|
return subject
|
|
|
|
@router.delete("/{subject_id}", response_model=Subject)
|
|
def delete_subject(
|
|
*,
|
|
db: Session = Depends(deps.get_db),
|
|
subject_id: int,
|
|
current_user: User = Depends(deps.get_current_admin_user),
|
|
) -> Any:
|
|
subject = subject_service.get(db, id=subject_id)
|
|
if not subject:
|
|
raise HTTPException(status_code=404, detail="Subject not found")
|
|
subject = subject_service.remove(db, id=subject_id)
|
|
return subject |