Update code in endpoints/api/v1/endpoint.post.py
This commit is contained in:
parent
2acafa0c3a
commit
30772e40a5
@ -1,46 +1,60 @@
|
|||||||
from fastapi import APIRouter, Depends, HTTPException
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
|
from pydantic import BaseModel
|
||||||
|
from typing import List, Optional
|
||||||
from core.database import fake_users_db
|
from core.database import fake_users_db
|
||||||
from typing import Dict, List
|
|
||||||
import uuid
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
class BakingInstructions(BaseModel):
|
||||||
|
recipe_name: str
|
||||||
|
temperature: int
|
||||||
|
baking_time: int
|
||||||
|
ingredients: List[str]
|
||||||
|
steps: List[str]
|
||||||
|
notes: Optional[str] = None
|
||||||
|
|
||||||
@router.post("/api/v1/endpoint")
|
@router.post("/api/v1/endpoint")
|
||||||
async def custom_endpoint_handler(
|
async def bake_code(
|
||||||
data: Dict = {
|
instructions: BakingInstructions
|
||||||
"title": "Sample Title",
|
|
||||||
"tags": ["tag1", "tag2"],
|
|
||||||
"content": "Sample content"
|
|
||||||
}
|
|
||||||
):
|
):
|
||||||
"""Process custom endpoint request"""
|
"""Create baking instructions for coding concepts"""
|
||||||
request_id = str(uuid.uuid4())
|
|
||||||
|
|
||||||
if not data.get("title"):
|
if instructions.temperature < 0 or instructions.temperature > 500:
|
||||||
raise HTTPException(status_code=400, detail="Title is required")
|
raise HTTPException(
|
||||||
|
status_code=400,
|
||||||
|
detail="Temperature must be between 0 and 500 degrees"
|
||||||
|
)
|
||||||
|
|
||||||
processed_data = {
|
if instructions.baking_time < 1:
|
||||||
"id": request_id,
|
raise HTTPException(
|
||||||
"title": data["title"],
|
status_code=400,
|
||||||
"tags": data.get("tags", []),
|
detail="Baking time must be at least 1 minute"
|
||||||
"content": data.get("content", ""),
|
)
|
||||||
"status": "processed"
|
|
||||||
|
recipe_id = len(fake_users_db) + 1
|
||||||
|
|
||||||
|
recipe = {
|
||||||
|
"id": recipe_id,
|
||||||
|
"recipe_name": instructions.recipe_name,
|
||||||
|
"temperature": instructions.temperature,
|
||||||
|
"baking_time": instructions.baking_time,
|
||||||
|
"ingredients": instructions.ingredients,
|
||||||
|
"steps": instructions.steps,
|
||||||
|
"notes": instructions.notes
|
||||||
}
|
}
|
||||||
|
|
||||||
fake_users_db[request_id] = processed_data
|
fake_users_db[recipe_id] = recipe
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"message": "Request processed successfully",
|
"message": "Recipe created successfully",
|
||||||
"request_id": request_id,
|
"recipe": recipe,
|
||||||
"data": processed_data,
|
"tips": [
|
||||||
|
"Make sure to follow each step carefully",
|
||||||
|
"Check understanding before moving to next step",
|
||||||
|
"Practice makes perfect!"
|
||||||
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"timestamp": "2024-01-20T12:00:00Z",
|
"difficulty_level": "beginner",
|
||||||
"version": "1.0",
|
"estimated_completion_time": f"{instructions.baking_time} minutes"
|
||||||
"processing_status": "complete"
|
}
|
||||||
},
|
|
||||||
"next_steps": [
|
|
||||||
"Review processed data",
|
|
||||||
"Update if needed",
|
|
||||||
"Publish changes"
|
|
||||||
]
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user