48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
from core.database import fake_users_db
|
|
import uuid
|
|
from pydantic import BaseModel
|
|
|
|
router = APIRouter()
|
|
|
|
class StudentCreate(BaseModel):
|
|
name: str
|
|
email: str
|
|
age: int
|
|
grade: str
|
|
|
|
@router.post("/api/v1/endpoint")
|
|
async def create_student(
|
|
student: StudentCreate
|
|
):
|
|
"""Create new student record"""
|
|
student_id = str(uuid.uuid4())
|
|
|
|
# Check if email already exists
|
|
for existing_student in fake_users_db.values():
|
|
if existing_student.get("email") == student.email:
|
|
raise HTTPException(
|
|
status_code=400,
|
|
detail="Student with this email already exists"
|
|
)
|
|
|
|
student_data = {
|
|
"id": student_id,
|
|
"name": student.name,
|
|
"email": student.email,
|
|
"age": student.age,
|
|
"grade": student.grade,
|
|
"created_at": "2024-01-01T00:00:00" # Demo timestamp
|
|
}
|
|
|
|
fake_users_db[student_id] = student_data
|
|
|
|
return {
|
|
"message": "Student created successfully",
|
|
"student_id": student_id,
|
|
"data": student_data,
|
|
"next_steps": [
|
|
"Complete student profile",
|
|
"Upload required documents"
|
|
]
|
|
} |