feat: Add 4 endpoints via editor
This commit is contained in:
parent
55e7daf081
commit
89b7486e36
20
endpoints/names.post.py
Normal file
20
endpoints/names.post.py
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
from fastapi import APIRouter, Depends, status, HTTPException
|
||||
# TODO: Import db session, schemas, models as needed
|
||||
# from pydantic import BaseModel # Example
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
# TODO: Define request body schema if needed
|
||||
# class name_Create(BaseModel):
|
||||
# name: str # Example field
|
||||
|
||||
@router.post("/names", status_code=status.HTTP_201_CREATED)
|
||||
async def create_name(
|
||||
# item: name_Create, # Example request body
|
||||
# db: Session = Depends(get_db) # Example dependency
|
||||
):
|
||||
"""first rest: Create new item"""
|
||||
# TODO: Implement logic to create a new name
|
||||
print(f"Creating new name") # with data: {item.dict()}")
|
||||
return {"message": "name created successfully"} # Placeholder
|
15
endpoints/names/{name_id}.delete.py
Normal file
15
endpoints/names/{name_id}.delete.py
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.delete("/names/{name_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
async def delete_name_item(
|
||||
name_id: Any, # TODO: Adjust type hint
|
||||
# db: Session = Depends(get_db) # Example dependency
|
||||
):
|
||||
"""first rest: Delete item by ID"""
|
||||
# TODO: Implement logic to delete name with id: {name_id}
|
||||
print(f"Deleting name with id: {name_id}")
|
||||
# Example: Check if found, perform deletion, raise 404 if not
|
||||
return None # Return No Content on success
|
18
endpoints/names/{name_id}.get.py
Normal file
18
endpoints/names/{name_id}.get.py
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
# TODO: Import db session, schemas, models as needed
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/names/{name_id}")
|
||||
async def get_name_item(
|
||||
name_id: Any, # TODO: Adjust type hint (e.g., int, str, UUID)
|
||||
# db: Session = Depends(get_db) # Example dependency
|
||||
):
|
||||
"""first rest: Get item by ID"""
|
||||
# TODO: Implement logic to fetch name with id: {name_id}
|
||||
print(f"Fetching name with id: {name_id}")
|
||||
# Example: Check if found, raise 404 if not
|
||||
# if not found:
|
||||
# raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="name not found")
|
||||
return {"name_id": name_id} # Placeholder
|
22
endpoints/names/{name_id}.put.py
Normal file
22
endpoints/names/{name_id}.put.py
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
# TODO: Import db session, schemas, models as needed
|
||||
# from pydantic import BaseModel # Example
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
# TODO: Define request body schema if needed
|
||||
# class name_Update(BaseModel):
|
||||
# name: str # Example field
|
||||
|
||||
@router.put("/names/{name_id}")
|
||||
async def update_name_item(
|
||||
name_id: Any, # TODO: Adjust type hint
|
||||
# item: name_Update, # Example request body
|
||||
# db: Session = Depends(get_db) # Example dependency
|
||||
):
|
||||
"""first rest: Update item by ID"""
|
||||
# TODO: Implement logic to update name with id: {name_id}
|
||||
print(f"Updating name with id: {name_id}") # with data: {item.dict()}")
|
||||
# Example: Check if found, raise 404 if not
|
||||
return {"message": "name updated successfully"} # Placeholder
|
Loading…
x
Reference in New Issue
Block a user