Renamed folder from example -> aggregate
This commit is contained in:
4
src/aggregate/__init__.py
Normal file
4
src/aggregate/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from .router import router as example_router
|
||||
from .aggregate_router import router as aggregate_router
|
||||
|
||||
__all__ = ["example_router", "aggregate_router"]
|
||||
21
src/aggregate/aggregate_router.py
Normal file
21
src/aggregate/aggregate_router.py
Normal 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)
|
||||
8
src/aggregate/aggregate_schema.py
Normal file
8
src/aggregate/aggregate_schema.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# contains the schema definitions for aggregates
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class AggregateSchema(BaseModel):
|
||||
aggregate: str
|
||||
node: str
|
||||
available: str
|
||||
24
src/aggregate/aggregate_service.py
Normal file
24
src/aggregate/aggregate_service.py
Normal 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
|
||||
2
src/aggregate/constants.py
Normal file
2
src/aggregate/constants.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# contains a constant definition
|
||||
FOO: int = 42
|
||||
10
src/aggregate/router.py
Normal file
10
src/aggregate/router.py
Normal file
@@ -0,0 +1,10 @@
|
||||
# contains the router for the aggregate endpoint
|
||||
from fastapi import APIRouter
|
||||
from .schema import ExampleSchema
|
||||
|
||||
router = APIRouter(tags=["aggregate"])
|
||||
|
||||
|
||||
@router.get("/example")
|
||||
async def example_endpoint() -> ExampleSchema:
|
||||
return ExampleSchema(example_field="foo", another_field=42)
|
||||
7
src/aggregate/schema.py
Normal file
7
src/aggregate/schema.py
Normal file
@@ -0,0 +1,7 @@
|
||||
# contains the schema definitions for the aggregate service
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class ExampleSchema(BaseModel):
|
||||
example_field: str
|
||||
another_field: int
|
||||
3
src/aggregate/service.py
Normal file
3
src/aggregate/service.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# contains the business logic for the aggregate service
|
||||
async def example_service() -> str:
|
||||
return "This is an aggregate service"
|
||||
Reference in New Issue
Block a user