# CI/CD Workshop # Copyright (C) 2025 OpenBokeron # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import time from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from app.services.builds import build_history 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) @app.get("/builds") def builds(): return build_history()