baseddata.io/backend/routes/route.py

49 lines
1.8 KiB
Python
Raw Normal View History

2024-09-20 17:49:31 +01:00
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
2024-09-22 14:27:43 +01:00
import ast
2024-09-20 17:49:31 +01:00
router = APIRouter()
2024-09-22 14:27:43 +01:00
@router.get("/mangrove_by_country_latest")
async def mangrove_by_country_latest():
2024-09-20 17:49:31 +01:00
db = client.baseddata
collection_name = db["final__protected_mangroves_summary_stats_by_country_agg"]
2024-09-22 14:27:43 +01:00
schema = schemas.mangrove_by_country_latest_schema
pipeline = pipelines.mangrove_by_country_latest()
2024-09-20 17:49:31 +01:00
serializer = DataSerializer(schema)
handler = MongoDBHandler(collection_name)
2024-09-22 14:27:43 +01:00
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)
2024-09-20 17:49:31 +01:00
serializedData = serializer.serialize_many(rawData)
return serializedData