Files
projekt-plattform/server/register/app.py

36 lines
1.1 KiB
Python

"""FastAPI-Anwendung des Registers. Kein Login in dieser Fassung (kommt mit #1022); gebunden wird nur an lokale Adressen, siehe run.py."""
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel, Field
from .db import Register
from .normalize import normalisiere
class Anfrage(BaseModel):
name: str = Field(min_length=1, max_length=200)
git_adresse: str = Field(min_length=1, max_length=500)
rechner: str = Field(min_length=1, max_length=200)
def erzeuge_app(db_pfad: str) -> FastAPI:
reg = Register(db_pfad)
app = FastAPI(title="Register", docs_url=None, redoc_url=None, openapi_url=None)
@app.get("/api/health")
def health():
return {"ok": True}
@app.post("/api/register")
def register(a: Anfrage):
try:
norm = normalisiere(a.git_adresse)
except ValueError as e:
raise HTTPException(status_code=422, detail=str(e))
return reg.anfrage(a.name.strip(), norm, a.git_adresse.strip(), a.rechner.strip())
@app.get("/api/projekte")
def projekte():
return reg.liste()
return app