import os from fastapi import FastAPI, Header, status from fastapi.middleware.cors import CORSMiddleware from supabase import create_client, Client from decouple import config from schema import WalletSchema from pydantic import BaseModel from authcheck import auth_check url = os.environ.get('SUPABASE_URL') key = os.environ.get('SUPABASE_KEY') app = FastAPI() supabase: Client = create_client(url, key) origins = ["*"] app.add_middleware( CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], # Allow all methods or be specific e.g., ["GET", "POST"] allow_headers=["*"], # Allow all headers or be specific e.g., ["Content-Type"] ) @app.get("/") async def read_root(): return {"message": "Welcome to hushh's Wallet API"} @app.get("/wallet/") async def get_wallet(id: str = Header(None), authentication: str = Header(None)): """ Use this endpoint to get wallet card information! Authorization token : Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 """ # Checking for authentication valid_auth = auth_check(authentication) if valid_auth.get("status") != 1: return valid_auth try: wallets = supabase.table('wallets').select('*').eq('id',id).execute() return wallets except: return {"message": f"An unexpected error occured for the specified ID '{id}'."} class WalletSchema(BaseModel): id: int brand_name: str bg_image: str logo: str font_color: str bg_color: str @app.post("/add_wallet/", status_code=status.HTTP_201_CREATED) async def add_wallet(wallet: WalletSchema, authentication: str = Header(None)): """ Use this endpoint to add wallet cards! Authorization token : Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9 """ # Checking for authentication valid_auth = auth_check(authentication) if valid_auth.get("status") != 1: return valid_auth try: wallet = supabase.table('wallets').insert({ "id": wallet.id, "brand_name": wallet.brand_name, "bg_image": wallet.bg_image, "logo": wallet.logo, "font_color": wallet.font_color, "bg_color": wallet.bg_color }).execute() return wallet except: return {"message": f"An unexpected error occured for the specified ID '{id}'."} if __name__ == "__main__": import uvicorn uvicorn.run(app, host="0.0.0.0", port=8000)