Implement EditAccount in Backend
This commit is contained in:
@@ -35,3 +35,37 @@ type TransactionsResponse struct {
|
||||
Account postgres.Account
|
||||
Transactions []postgres.GetTransactionsForAccountRow
|
||||
}
|
||||
|
||||
type EditAccountRequest struct {
|
||||
Name string `json:"name"`
|
||||
OnBudget bool `json:"onBudget"`
|
||||
}
|
||||
|
||||
func (h *Handler) editAccount(c *gin.Context) {
|
||||
accountID := c.Param("accountid")
|
||||
accountUUID, err := uuid.Parse(accountID)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
var request EditAccountRequest
|
||||
err = c.BindJSON(&request)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
updateParams := postgres.UpdateAccountParams{
|
||||
Name: request.Name,
|
||||
OnBudget: request.OnBudget,
|
||||
ID: accountUUID,
|
||||
}
|
||||
account, err := h.Service.UpdateAccount(c.Request.Context(), updateParams)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusNotFound, err)
|
||||
return
|
||||
}
|
||||
|
||||
h.returnBudgetingData(c, account.BudgetID)
|
||||
}
|
||||
|
Reference in New Issue
Block a user