50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
from datetime import datetime, time, timedelta
|
|
from fastapi import APIRouter, HTTPException, status
|
|
from pydantic import BaseModel, EmailStr, Field
|
|
from typing import Dict, List, Optional, Set, Union
|
|
|
|
from ..lib_general import *
|
|
from ..log import *
|
|
from app.config import settings
|
|
from app.db import *
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
class Image(BaseModel):
|
|
url: str
|
|
name: str
|
|
|
|
|
|
class Item(BaseModel):
|
|
name: str
|
|
description: Optional[str] = Field(None, example='A very nice Item')
|
|
price: float
|
|
tax: Optional[float] = None
|
|
is_offer: Optional[bool] = None
|
|
#tags: List[str] = [] # not unique tags
|
|
tags: Set[str] = set() # unique tags
|
|
image: Optional[Image] = None # one image
|
|
images: Optional[List[Image]] = None # or as a list of images
|
|
|
|
|
|
@router.get('/')
|
|
async def read_items():
|
|
return [{'name': 'Item Foo'}, {'name': 'item Bar'}]
|
|
|
|
|
|
@router.get('/{item_id}')
|
|
async def read_item(item_id: str):
|
|
return {'name': 'Fake Specific Item', 'item_id': item_id}
|
|
|
|
|
|
@router.put(
|
|
'/{item_id}',
|
|
tags=['Extra Tag'],
|
|
responses={403: {'description': 'Operation forbidden'}},
|
|
)
|
|
async def update_item(item_id: str):
|
|
if item_id != 'foo':
|
|
raise HTTPException(status_code=403, detail='You can only update the item: foo')
|
|
return {'item_id': item_id, 'name': 'The Fighters'}
|