70 lines
2.4 KiB
Python
70 lines
2.4 KiB
Python
"""Číselníky CPL API + informace o verzích a stavu API.
|
|
|
|
Všechny číselníky jsou GET s povinným stránkováním (Limit/Offset) a vracejí
|
|
X-Paging-* hlavičky, které služba předává dál.
|
|
"""
|
|
from enum import Enum
|
|
|
|
from fastapi import APIRouter, Depends, Query
|
|
|
|
from ..cpl_client import cpl_request, relay_json
|
|
from ..credentials import Credentials, get_credentials
|
|
|
|
router = APIRouter(tags=["codelists"])
|
|
|
|
|
|
class Codelist(str, Enum):
|
|
"""Názvy číselníků dle CPL API (tvoří cestu /codelist/{name})."""
|
|
|
|
ageCheck = "ageCheck"
|
|
product = "product"
|
|
externalNumber = "externalNumber"
|
|
country = "country"
|
|
currency = "currency"
|
|
service = "service"
|
|
servicePriceLimit = "servicePriceLimit"
|
|
shipmentPhase = "shipmentPhase"
|
|
status = "status"
|
|
validationMessage = "validationMessage"
|
|
proofOfIdentityType = "proofOfIdentityType"
|
|
documentFileType = "documentFileType"
|
|
|
|
|
|
@router.get("/codelists/{codelist}", summary="Číselník CPL API")
|
|
async def get_codelist(
|
|
codelist: Codelist,
|
|
limit: int = Query(default=1000, ge=1, le=1000),
|
|
offset: int = Query(default=0, ge=0),
|
|
creds: Credentials = Depends(get_credentials),
|
|
):
|
|
"""`GET codelist/{name}` — např. product (produkty), country (země + povolení COD),
|
|
currency (měny), service (služby), servicePriceLimit (min/max hodnoty služeb),
|
|
status (statusy zásilky), validationMessage (chybové kódy)."""
|
|
resp = await cpl_request(
|
|
creds,
|
|
"GET",
|
|
f"/codelist/{codelist.value}",
|
|
params={"Limit": limit, "Offset": offset},
|
|
)
|
|
return relay_json(resp)
|
|
|
|
|
|
@router.get("/version-information", summary="Novinky a změny verzí CPL API")
|
|
async def version_information(
|
|
limit: int = Query(default=100, ge=1, le=1000),
|
|
offset: int = Query(default=0, ge=0),
|
|
creds: Credentials = Depends(get_credentials),
|
|
):
|
|
"""`GET versionInformation` — přehled novinek/změn API publikovaných PPL."""
|
|
resp = await cpl_request(
|
|
creds, "GET", "/versionInformation", params={"Limit": limit, "Offset": offset}
|
|
)
|
|
return relay_json(resp)
|
|
|
|
|
|
@router.get("/cpl-info", summary="Stav a verze CPL API (upstream /info)")
|
|
async def cpl_info(creds: Credentials = Depends(get_credentials)):
|
|
"""`GET info` — rychlé ověření, že PPL CPL API běží (verze, stav, čas serveru)."""
|
|
resp = await cpl_request(creds, "GET", "/info")
|
|
return relay_json(resp)
|