diff --git a/src/aggregate/__init__.py b/src/aggregate/__init__.py new file mode 100644 index 0000000..c55c18d --- /dev/null +++ b/src/aggregate/__init__.py @@ -0,0 +1,4 @@ +from src.example.router import router as example_router +from .aggregate_router import router as aggregate_router + +__all__ = ["example_router", "aggregate_router"] diff --git a/src/aggregate/aggregate_router.py b/src/aggregate/aggregate_router.py new file mode 100644 index 0000000..b33556b --- /dev/null +++ b/src/aggregate/aggregate_router.py @@ -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) diff --git a/src/aggregate/aggregate_schema.py b/src/aggregate/aggregate_schema.py new file mode 100644 index 0000000..4edd30a --- /dev/null +++ b/src/aggregate/aggregate_schema.py @@ -0,0 +1,8 @@ +# contains the schema definitions for aggregates +from pydantic import BaseModel + + +class AggregateSchema(BaseModel): + aggregate: str + node: str + available: str diff --git a/src/aggregate/aggregate_service.py b/src/aggregate/aggregate_service.py new file mode 100644 index 0000000..0a40557 --- /dev/null +++ b/src/aggregate/aggregate_service.py @@ -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 diff --git a/src/example/__init__.py b/src/example/__init__.py index 1f780dd..e69de29 100644 --- a/src/example/__init__.py +++ b/src/example/__init__.py @@ -1,3 +0,0 @@ -from .router import router as example_router - -__all__ = ["example_router"] diff --git a/src/example/router.py b/src/example/router.py index bfad513..4c5096d 100644 --- a/src/example/router.py +++ b/src/example/router.py @@ -1,8 +1,8 @@ -# contains the router for the example endpoint +# contains the router for the aggregate endpoint from fastapi import APIRouter from .schema import ExampleSchema -router = APIRouter(tags=["example"]) +router = APIRouter(tags=["aggregate"]) @router.get("/example") diff --git a/src/example/schema.py b/src/example/schema.py index 254a309..47392d6 100644 --- a/src/example/schema.py +++ b/src/example/schema.py @@ -1,4 +1,4 @@ -# contains the schema definitions for the example service +# contains the schema definitions for the aggregate service from pydantic import BaseModel diff --git a/src/example/service.py b/src/example/service.py index 0553df7..cd81419 100644 --- a/src/example/service.py +++ b/src/example/service.py @@ -1,3 +1,3 @@ -# contains the business logic for the example service +# contains the business logic for the aggregate service async def example_service() -> str: - return "This is an example service" + return "This is an aggregate service" diff --git a/src/main.py b/src/main.py index 69a9d2d..8e902bf 100644 --- a/src/main.py +++ b/src/main.py @@ -1,6 +1,7 @@ from src.service import load_config from fastapi import FastAPI import logging +from src.aggregate import aggregate_router logger = logging.getLogger("uvicorn") @@ -8,6 +9,7 @@ logger.info("Starting application") config = load_config() app = FastAPI() +app.include_router(aggregate_router) @app.get("/")