feat: add GET /aggregates

This commit is contained in:
Magel, Denis
2025-09-18 10:10:30 +02:00
parent d564710004
commit 63bcd9b931
5 changed files with 56 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
from .router import router as example_router from .router import router as example_router
from .aggregate_router import router as aggregate_router
__all__ = ["example_router"] __all__ = ["example_router", "aggregate_router"]

View File

@@ -0,0 +1,21 @@
# contains the router for the aggregates endpoint
from fastapi import APIRouter, Query
from enum import Enum
from typing import List
from .aggregate_schema import AggregateSchema
from .aggregate_service import get_aggregates
class MetricEnum(str, Enum):
relative = "relative"
absolute = "absolute"
router = APIRouter(tags=["aggregates"])
@router.get("/aggregates", response_model=List[AggregateSchema])
async def aggregates_endpoint(
metric: MetricEnum = Query(MetricEnum.relative, description="Metric type")
):
return await get_aggregates(metric)

View File

@@ -0,0 +1,7 @@
# contains the schema definitions for aggregates
from pydantic import BaseModel
class AggregateSchema(BaseModel):
aggregate: str
node: str
available: str

View File

@@ -0,0 +1,24 @@
# contains the business logic for aggregates
from typing import List
from .aggregate_schema import AggregateSchema
async def get_aggregates(metric: str = "relative") -> List[AggregateSchema]:
# Dummy data for demonstration
# You can use the metric parameter to filter or modify results as needed
# For now, just return the same data and show metric usage
print(f"Metric used: {metric}")
aggregates: list = [
AggregateSchema(
aggregate="Aggregate A", node="cluster01-01", available="100.0TB"
),
AggregateSchema(
aggregate="Aggregate B", node="cluster01-01", available="200.5GB"
),
AggregateSchema(
aggregate="Aggregate C", node="cluster01-02", available="300.75MB"
),
]
return aggregates

View File

@@ -1,6 +1,7 @@
from src.service import load_config from src.service import load_config
from fastapi import FastAPI from fastapi import FastAPI
import logging import logging
from src.example import aggregate_router
logger = logging.getLogger("uvicorn") logger = logging.getLogger("uvicorn")
@@ -8,7 +9,7 @@ logger.info("Starting application")
config = load_config() config = load_config()
app = FastAPI() app = FastAPI()
app.include_router(aggregate_router)
@app.get("/") @app.get("/")
async def main(): async def main():