- Updated test functions in various test files to enhance code clarity by formatting long lines and improving indentation. - Adjusted assertions to use multi-line formatting for better readability. - Added new test cases for theme settings API to ensure proper functionality. - Ensured consistent use of line breaks and spacing across test files for uniformity.
39 lines
939 B
Python
39 lines
939 B
Python
from typing import List, Optional
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from pydantic import BaseModel, ConfigDict
|
|
from sqlalchemy.orm import Session
|
|
|
|
from models.equipment import Equipment
|
|
from routes.dependencies import get_db
|
|
|
|
router = APIRouter(prefix="/api/equipment", tags=["Equipment"])
|
|
# Pydantic schemas
|
|
|
|
|
|
class EquipmentCreate(BaseModel):
|
|
scenario_id: int
|
|
name: str
|
|
description: Optional[str] = None
|
|
|
|
|
|
class EquipmentRead(EquipmentCreate):
|
|
id: int
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
@router.post("/", response_model=EquipmentRead)
|
|
async def create_equipment(
|
|
item: EquipmentCreate, db: Session = Depends(get_db)
|
|
):
|
|
db_item = Equipment(**item.model_dump())
|
|
db.add(db_item)
|
|
db.commit()
|
|
db.refresh(db_item)
|
|
return db_item
|
|
|
|
|
|
@router.get("/", response_model=List[EquipmentRead])
|
|
async def list_equipment(db: Session = Depends(get_db)):
|
|
return db.query(Equipment).all()
|