Update code in endpoints/api/v1/endpoint.post.py
This commit is contained in:
parent
f86e48c0d4
commit
6ee6f691c5
48
endpoints/api/v1/endpoint.post.py
Normal file
48
endpoints/api/v1/endpoint.post.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
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"
|
||||||
|
]
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user