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