feat: logos endpoint

This commit is contained in:
Alexandre Teles 2022-11-17 01:46:05 -03:00
parent 81c4e306b3
commit b5057f04e2
5 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,3 @@
[ZoneTransfer]
ZoneId=3
HostUrl=https://rjylmqmyfc-496ff2e9c6d22116-0-colab.googleusercontent.com/

View File

@ -28,6 +28,7 @@ import app.models.GeneralErrors as GeneralErrors
from app.routers import root from app.routers import root
from app.routers import auth from app.routers import auth
from app.routers import items
"""Implements an API for our polling app""" """Implements an API for our polling app"""
@ -61,6 +62,7 @@ app.add_middleware(SlowAPIMiddleware)
# Setup routes # Setup routes
app.include_router(root.router) app.include_router(root.router)
app.include_router(items.router)
app.include_router(auth.router) app.include_router(auth.router)
# Setup cache # Setup cache

21
app/models/ItemFields.py Normal file
View File

@ -0,0 +1,21 @@
from pydantic import BaseModel
class LogoFields(BaseModel):
"""Implements the fields for the logos.
Args:
BaseModel (pydantic.BaseModel): BaseModel from pydantic
"""
id: str
filename: str
gdrive_direct_url: str
class ItemFields(BaseModel):
"""Implements the fields for the items.
Args:
BaseModel (pydantic.BaseModel): BaseModel from pydantic
"""
logos: list[LogoFields]

12
app/models/ItemModels.py Normal file
View File

@ -0,0 +1,12 @@
from pydantic import BaseModel
from app.models.ItemFields import ItemFields
class ItemModel(BaseModel):
"""Implements the model for the items.
Args:
BaseModel (pydantic.BaseModel): BaseModel from pydantic
"""
__root__: dict[str, ItemFields]

25
app/routers/items.py Normal file
View File

@ -0,0 +1,25 @@
import json
import aiofiles
from fastapi import APIRouter, Request, Response
from fastapi_cache.decorator import cache
from app.dependencies import load_config
from app.models.ItemModels import ItemModel
router = APIRouter()
config: dict = load_config()
@router.get('/logos', response_model=ItemModel, tags=['Logos'])
@cache(config['cache']['expire'])
async def logos(request: Request, response: Response) -> dict:
"""Get logos.
Returns:
json: list of logos
"""
async with aiofiles.open('app/data/processed.json', 'r') as json_file:
data: dict = {}
data = json.loads(await json_file.read())
return data