chore: import MCTF services
- Added all seven issued service trees without omissions. - Preserved the supplied runtime configuration, binaries, and assets.
This commit is contained in:
commit
13f936bee9
1222 files changed
+21280
No files matched your search
Executable
+24
@@ -0,0 +1,24 @@
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import APIRouter
|
||||
|
||||
from backend.app.db import operations
|
||||
from backend.app.api.schemas import CheckStart, CheckCommit, CheckAnswer
|
||||
|
||||
router = APIRouter(prefix="/api/chat", tags=["chat"])
|
||||
|
||||
@router.get("/greeting")
|
||||
async def greeting():
|
||||
return await operations.chat_greeting()
|
||||
|
||||
@router.post("/checks", status_code=201)
|
||||
async def check_start(body: CheckStart):
|
||||
return await operations.check_start(body.reading_id)
|
||||
|
||||
@router.post("/checks/{check_id}/commit")
|
||||
async def check_commit(check_id: UUID, body: CheckCommit):
|
||||
return await operations.check_commit(check_id, body.round, body.values)
|
||||
|
||||
@router.post("/checks/{check_id}/answer")
|
||||
async def check_answer(check_id: UUID, body: CheckAnswer):
|
||||
return await operations.check_answer(check_id, body.round, body.data)
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from backend.app.db import operations
|
||||
|
||||
router = APIRouter(prefix="/api", tags=["system"])
|
||||
|
||||
@router.get("/health")
|
||||
async def health():
|
||||
return {"ok": await operations.ping() == 1}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from backend.app.db import operations
|
||||
from backend.app.api.schemas import ReadingIn
|
||||
|
||||
router = APIRouter(prefix="/api", tags=["readings"])
|
||||
|
||||
@router.get("/resources")
|
||||
async def resources():
|
||||
return await operations.resources()
|
||||
|
||||
@router.get("/readings")
|
||||
async def readings():
|
||||
return await operations.readings()
|
||||
|
||||
@router.get("/readings/{reading_id}")
|
||||
async def reading_public(reading_id: int):
|
||||
return await operations.reading_public(reading_id)
|
||||
|
||||
@router.post("/readings", status_code=201)
|
||||
async def reading_add(body: ReadingIn):
|
||||
return await operations.add_reading(body.serial, body.kind, body.model_dump(mode="json")["metrics"])
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from backend.app.db import operations
|
||||
from backend.app.api.schemas import ReceiptOpen
|
||||
|
||||
router = APIRouter(prefix="/api/receipts", tags=["receipts"])
|
||||
|
||||
@router.get("")
|
||||
async def receipts():
|
||||
return await operations.receipts()
|
||||
|
||||
@router.post("/{receipt_id}/open")
|
||||
async def receipt_open(receipt_id: int, body: ReceiptOpen):
|
||||
return await operations.open_receipt(receipt_id, body.calculation_id)
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
import csv
|
||||
import io
|
||||
|
||||
from fastapi import APIRouter, Query
|
||||
from fastapi.responses import Response
|
||||
|
||||
from backend.app.api.schemas import ReportQueryIn
|
||||
from backend.app.db import operations
|
||||
from backend.app.db.connection import QueryError
|
||||
|
||||
router = APIRouter(prefix="/api/reports", tags=["reports"])
|
||||
|
||||
@router.get("/finance/fields")
|
||||
async def finance_fields():
|
||||
return await operations.report_fields("finance")
|
||||
|
||||
@router.get("/finance/summary")
|
||||
async def finance_summary(period: str | None = None, fields: list[str] = Query(default=[]),
|
||||
sort: str = "", group_by: str = "", filter: str = "", having: str = ""):
|
||||
selected = [field.strip() for item in fields for field in item.split(",") if field.strip()]
|
||||
return await operations.finance_report(period, selected, sort, group_by, filter, having)
|
||||
|
||||
@router.post("/export")
|
||||
async def export_report(body: ReportQueryIn):
|
||||
fields = body.fields
|
||||
if not fields:
|
||||
fields = [field["id"] for field in await operations.report_fields(body.report)]
|
||||
if not fields:
|
||||
raise QueryError("P0400", "Unknown report type.")
|
||||
report = await operations.finance_report(body.period, fields, body.sort, body.group_by, body.filter, body.having)
|
||||
output = io.StringIO(newline="")
|
||||
writer = csv.writer(output)
|
||||
writer.writerow([column["title"] for column in report["columns"]])
|
||||
writer.writerows(report["rows"])
|
||||
return Response(output.getvalue(), media_type="text/csv; charset=utf-8",
|
||||
headers={"Content-Disposition": f'attachment; filename="finance-{report["period"]}.csv"'})
|
||||
Executable
+43
@@ -0,0 +1,43 @@
|
||||
from decimal import Decimal
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
class ReadingIn(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid", allow_inf_nan=False)
|
||||
|
||||
serial: str = Field(min_length=1, max_length=128)
|
||||
kind: str = Field(min_length=1, max_length=16)
|
||||
metrics: dict[str, Decimal] = Field(min_length=4, max_length=4)
|
||||
|
||||
class CheckStart(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
reading_id: int = Field(gt=0)
|
||||
|
||||
class CheckCommit(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
round: int = Field(ge=1, le=10)
|
||||
values: list[str] = Field(min_length=3, max_length=3)
|
||||
|
||||
class CheckAnswer(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
round: int = Field(ge=1, le=10)
|
||||
data: dict = Field(min_length=2, max_length=2)
|
||||
|
||||
class ReceiptOpen(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid", str_strip_whitespace=True)
|
||||
|
||||
calculation_id: str = Field(min_length=44, max_length=44, pattern=r"^[A-Za-z0-9+/]{43}=$")
|
||||
|
||||
class ReportQueryIn(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
report: str
|
||||
period: str
|
||||
fields: list[str] = []
|
||||
sort: str = ""
|
||||
group_by: str = ""
|
||||
filter: str = ""
|
||||
having: str = ""
|
||||
Reference in new issue
Block a user