mirror of
https://github.com/acedanger/finance.git
synced 2025-12-05 22:50:12 -08:00
37 lines
1.0 KiB
Python
37 lines
1.0 KiB
Python
from fastapi import FastAPI, HTTPException
|
|
from pydantic import BaseModel
|
|
from datetime import datetime
|
|
from typing import List, Optional
|
|
|
|
app = FastAPI(title="Finance MCP Server")
|
|
|
|
class Transaction(BaseModel):
|
|
id: Optional[int]
|
|
amount: float
|
|
description: str
|
|
timestamp: datetime = datetime.now()
|
|
category: str
|
|
|
|
# In-memory storage (replace with database in production)
|
|
transactions: List[Transaction] = []
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {"status": "running", "service": "Finance MCP Server"}
|
|
|
|
@app.get("/transactions")
|
|
async def get_transactions():
|
|
return transactions
|
|
|
|
@app.post("/transactions")
|
|
async def create_transaction(transaction: Transaction):
|
|
transaction.id = len(transactions) + 1
|
|
transactions.append(transaction)
|
|
return transaction
|
|
|
|
@app.get("/transactions/{transaction_id}")
|
|
async def get_transaction(transaction_id: int):
|
|
for tx in transactions:
|
|
if tx.id == transaction_id:
|
|
return tx
|
|
raise HTTPException(status_code=404, detail="Transaction not found") |