Add ability to change is_open from API
This commit is contained in:
parent
4fb3c2a335
commit
f26ee8f472
@ -196,19 +196,26 @@ func (q *Queries) SearchAccounts(ctx context.Context, arg SearchAccountsParams)
|
||||
const updateAccount = `-- name: UpdateAccount :one
|
||||
UPDATE accounts
|
||||
SET name = $1,
|
||||
on_budget = $2
|
||||
WHERE accounts.id = $3
|
||||
on_budget = $2,
|
||||
is_open = $3
|
||||
WHERE accounts.id = $4
|
||||
RETURNING id, budget_id, name, on_budget, is_open
|
||||
`
|
||||
|
||||
type UpdateAccountParams struct {
|
||||
Name string
|
||||
OnBudget bool
|
||||
IsOpen 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)
|
||||
row := q.db.QueryRowContext(ctx, updateAccount,
|
||||
arg.Name,
|
||||
arg.OnBudget,
|
||||
arg.IsOpen,
|
||||
arg.ID,
|
||||
)
|
||||
var i Account
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
|
@ -35,6 +35,7 @@ ORDER BY accounts.name;
|
||||
-- name: UpdateAccount :one
|
||||
UPDATE accounts
|
||||
SET name = $1,
|
||||
on_budget = $2
|
||||
WHERE accounts.id = $3
|
||||
on_budget = $2,
|
||||
is_open = $3
|
||||
WHERE accounts.id = $4
|
||||
RETURNING *;
|
@ -39,6 +39,7 @@ type TransactionsResponse struct {
|
||||
type EditAccountRequest struct {
|
||||
Name string `json:"name"`
|
||||
OnBudget bool `json:"onBudget"`
|
||||
IsOpen bool `json:"isOpen"`
|
||||
}
|
||||
|
||||
func (h *Handler) editAccount(c *gin.Context) {
|
||||
@ -59,6 +60,7 @@ func (h *Handler) editAccount(c *gin.Context) {
|
||||
updateParams := postgres.UpdateAccountParams{
|
||||
Name: request.Name,
|
||||
OnBudget: request.OnBudget,
|
||||
IsOpen: request.IsOpen,
|
||||
ID: accountUUID,
|
||||
}
|
||||
account, err := h.Service.UpdateAccount(c.Request.Context(), updateParams)
|
||||
|
Loading…
x
Reference in New Issue
Block a user