Files
TallerCiCd/backend/app/main.py
jose-rZM c3f7af7379 Init
2025-12-15 11:42:17 +01:00

58 lines
1.1 KiB
Python

import time
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.services.menu import build_menu
from app.services.prices import prices_payload, random_price
from app.settings import settings
START_TIME = time.time()
def uptime() -> int:
return int(time.time() - START_TIME)
app = FastAPI(
title="Cafetería API",
description="Devuelve precios y el menú del día.",
version="0.1.0",
)
# Frontend and API will likely run on different ports; allow everything to keep the workshop simple.
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/health")
def health():
return {
"status": "ok",
"version": settings.app_version,
"commit": settings.git_commit,
"build": settings.build_number,
"author": settings.commit_author,
"uptime_seconds": uptime()
}
@app.get("/menu")
def menu():
return build_menu()
@app.get("/prices")
def prices():
return prices_payload()
@app.get("/prices/{item}")
def price_for_item(item: str):
return random_price(item)