Implement EditAccount in Backend
This commit is contained in:
@ -175,3 +175,29 @@ func (q *Queries) SearchAccounts(ctx context.Context, arg SearchAccountsParams)
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateAccount = `-- name: UpdateAccount :one
|
||||
UPDATE accounts
|
||||
SET name = $1,
|
||||
on_budget = $2
|
||||
WHERE accounts.id = $3
|
||||
RETURNING id, budget_id, name, on_budget
|
||||
`
|
||||
|
||||
type UpdateAccountParams struct {
|
||||
Name string
|
||||
OnBudget bool
|
||||
ID uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateAccount(ctx context.Context, arg UpdateAccountParams) (Account, error) {
|
||||
row := q.db.QueryRowContext(ctx, updateAccount, arg.Name, arg.OnBudget, arg.ID)
|
||||
var i Account
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.BudgetID,
|
||||
&i.Name,
|
||||
&i.OnBudget,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
@ -25,4 +25,11 @@ ORDER BY accounts.name;
|
||||
SELECT accounts.id, accounts.budget_id, accounts.name, true as is_account FROM accounts
|
||||
WHERE accounts.budget_id = @budget_id
|
||||
AND accounts.name LIKE @search
|
||||
ORDER BY accounts.name;
|
||||
ORDER BY accounts.name;
|
||||
|
||||
-- name: UpdateAccount :one
|
||||
UPDATE accounts
|
||||
SET name = $1,
|
||||
on_budget = $2
|
||||
WHERE accounts.id = $3
|
||||
RETURNING *;
|
Reference in New Issue
Block a user