feat: Updated endpoint endpoints/names.post.py via AI
This commit is contained in:
parent
2e587279d8
commit
dba0d9b0f3
@ -1,11 +1,16 @@
|
|||||||
from fastapi import APIRouter, status
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
from typing import List
|
from typing import List
|
||||||
from helpers.ship_helpers import get_ship_names
|
from core.database import get_db
|
||||||
|
from schemas.ship import ShipSchema
|
||||||
|
from helpers.ship_helpers import get_all_ships
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@router.post("/names", status_code=status.HTTP_200_OK, response_model=List[str])
|
@router.post("/names", status_code=200, response_model=List[ShipSchema])
|
||||||
async def get_names():
|
async def get_all_ship_details(db: Session = Depends(get_db)):
|
||||||
"""Get list of ship names"""
|
"""Return all ships"""
|
||||||
names = get_ship_names()
|
ships = get_all_ships(db)
|
||||||
return names
|
if not ships:
|
||||||
|
raise HTTPException(status_code=404, detail="No ships found")
|
||||||
|
return ships
|
@ -3,7 +3,7 @@ from uuid import UUID
|
|||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
from sqlalchemy.exc import SQLAlchemyError
|
from sqlalchemy.exc import SQLAlchemyError
|
||||||
from models.ship import Ship
|
from models.ship import Ship
|
||||||
from schemas.ship import ShipCreate, ShipUpdate, ShipSchema
|
from schemas.ship import ShipCreate, ShipUpdate
|
||||||
|
|
||||||
def get_all_ships(db: Session) -> List[Ship]:
|
def get_all_ships(db: Session) -> List[Ship]:
|
||||||
"""
|
"""
|
||||||
@ -33,6 +33,8 @@ def get_ship_by_id(db: Session, ship_id: UUID) -> Optional[Ship]:
|
|||||||
def get_ship_names(db: Session) -> List[str]:
|
def get_ship_names(db: Session) -> List[str]:
|
||||||
"""
|
"""
|
||||||
Retrieves a list of all ship names.
|
Retrieves a list of all ship names.
|
||||||
|
|
||||||
|
Note: This function is deprecated. Use get_all_ships() instead to get full ship objects.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
db (Session): The database session.
|
db (Session): The database session.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user