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 import ast router = APIRouter() @router.get("/mangrove_by_country_latest") async def mangrove_by_country_latest(): db = client.baseddata collection_name = db["final__protected_mangroves_summary_stats_by_country_agg"] schema = schemas.mangrove_by_country_latest_schema pipeline = pipelines.mangrove_by_country_latest() serializer = DataSerializer(schema) handler = MongoDBHandler(collection_name) rawData = handler.aggregate(pipeline) serializedData = serializer.serialize_many(rawData) return serializedData @router.get("/mangrove_by_country_agg") async def mangrove_by_country_agg(query: str): query = ast.literal_eval(query) db = client.baseddata collection_name = db["final__protected_mangroves_summary_stats_by_country_agg"] schema = schemas.mangrove_by_country_agg_schema pipeline = pipelines.mangrove_by_country_agg(query) serializer = DataSerializer(schema) handler = MongoDBHandler(collection_name) rawData = handler.aggregate(pipeline) serializedData = serializer.serialize_many(rawData) return serializedData @router.get("/bitcoin_business_growth") async def bitcoin_business_growth(query: str): query = ast.literal_eval(query) db = client.baseddata collection_name = db["final__bitcoin_business_growth_by_country"] schema = schemas.bitcoin_business_growth pipeline = pipelines.bitcoin_business_growth(query) serializer = DataSerializer(schema) handler = MongoDBHandler(collection_name) rawData = handler.aggregate(pipeline) serializedData = serializer.serialize_many(rawData) return serializedData