from fastapi import FastAPI,Request,HTTPException,Response from typing import Optional from fastapi.responses import JSONResponse from fastapi.middleware.cors import CORSMiddleware from pydantic import BaseModel from components.dbconnection import provideClient from fastapi.responses import HTMLResponse origins=["*"] app=FastAPI() app.add_middleware( CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) client = provideClient() db = client["pahalgam_pd"] coll = db["ponyworkers"] class PPD(BaseModel): name:str registration_number:str phone_number:str address:str aadhar:str parentage:str total_ponies:str stand:str license:bool renewal:bool @app.post("/dataingestion") async def Ingest(request:PPD): payload={ "name":request.name, "registration_number":request.registration_number, "phone_number":request.phone_number, "address":request.address, "aadhar":request.aadhar, "parentage":request.parentage, "total_ponies":request.total_ponies, "stand":request.stand, "license":request.license, "renewal":request.renewal } result = coll.insert_one(payload) print(f"Inserted ID: {result.inserted_id}") return {"success":True} @app.get("/", response_class=HTMLResponse) async def static_page(): return """