from fastapi import APIRouter from config.database import client from models.mongodb_handler import MongoDBHandler import models.pipelines as pipelines import schema.schemas as schemas from schema.schemas import DataSerializer router = APIRouter() @router.get("/mangrove_country_data") async def mangrove_country_data(): db = client.baseddata collection_name = db["final__protected_mangroves_summary_stats_by_country_agg"] schema = schemas.mangrove_country_schema query = pipelines.aggregate_mangrove_by_country serializer = DataSerializer(schema) handler = MongoDBHandler(collection_name) rawData = handler.aggregate(query) serializedData = serializer.serialize_many(rawData) return serializedData