i am new to fastapi, and i want to be able to update my bank account information when a deposit is made. i am not sure how to do this as i am not sure how patch works. the logic used in deposit is that i used in create a bank account (obviously they should not work the same). this is my model:
class Account(Base):
__tablename__ = "accounts"
id = Column(Integer, primary_key=True, index=True)
name = Column(String)
deposits_made = Column(Integer)
total = Column(Integer)
class PaymentRequest(BaseModel):
bank_id: str
amount: int
def get_db():
try:
db = SessionLocal()
yield db
finally:
db.close()
@app.patch("/deposit")
def deposit(request: PaymentRequest, db: Session = Depends(get_db)):
account = db.query(Account)
account = accounts[request.id]
account.total += request.amount
account.deposits_made += 1
db.add(account)
db.commit()
return{
"code":"success",
"message":"donation made"
}