Add edit purchase feature (date, amount, price)
Backend: PUT /purchases/{id} endpoint accepts updated amount_eur,
price_eur, and created_at. Frontend: inline edit row in PurchaseList
with date picker and number inputs, Save/Cancel actions.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -16,6 +16,12 @@ class PurchaseCreate(BaseModel):
|
||||
price_eur: float
|
||||
|
||||
|
||||
class PurchaseUpdate(BaseModel):
|
||||
amount_eur: float
|
||||
price_eur: float
|
||||
created_at: datetime
|
||||
|
||||
|
||||
class PurchaseOut(BaseModel):
|
||||
id: int
|
||||
amount_eur: float
|
||||
@@ -51,6 +57,27 @@ def add_purchase(
|
||||
return purchase
|
||||
|
||||
|
||||
@router.put("/purchases/{purchase_id}", response_model=PurchaseOut)
|
||||
def update_purchase(
|
||||
purchase_id: int,
|
||||
purchase_in: PurchaseUpdate,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: models.User = Depends(get_current_user),
|
||||
):
|
||||
purchase = db.query(models.Purchase).filter(
|
||||
models.Purchase.id == purchase_id,
|
||||
models.Purchase.user_id == current_user.id,
|
||||
).first()
|
||||
if not purchase:
|
||||
raise HTTPException(status_code=404, detail="Purchase not found")
|
||||
purchase.amount_eur = purchase_in.amount_eur
|
||||
purchase.price_eur = purchase_in.price_eur
|
||||
purchase.created_at = purchase_in.created_at
|
||||
db.commit()
|
||||
db.refresh(purchase)
|
||||
return purchase
|
||||
|
||||
|
||||
@router.delete("/purchases/{purchase_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
def delete_purchase(
|
||||
purchase_id: int,
|
||||
|
||||
Reference in New Issue
Block a user