add PATCH update delivery status by id

This commit is contained in:
Egor Pozharov
2026-04-14 15:46:32 +06:00
parent d3cd92b9f3
commit b36a6fb262
5 changed files with 61 additions and 1 deletions

View File

@@ -16,4 +16,7 @@ DELETE FROM deliveries WHERE id = $1;
UPDATE deliveries SET date = $1, pickup_location = $2, product_name = $3, address = $4, phone = $5, additional_phone = $6, has_elevator = $7, comment = $8, updated_at = NOW() WHERE id = $9;
-- name: GetDeliveryCount :many
SELECT COUNT(*) as count, date FROM deliveries WHERE date >= DATE_TRUNC('month', CURRENT_DATE) GROUP BY date;
SELECT COUNT(*) as count, date FROM deliveries WHERE date >= DATE_TRUNC('month', CURRENT_DATE) GROUP BY date;
-- name: UpdateDeliveryStatus :exec
UPDATE deliveries SET status = $1, updated_at = NOW() WHERE id = $2;

View File

@@ -17,6 +17,7 @@ type Querier interface {
GetDeliveryByID(ctx context.Context, id pgtype.UUID) (Delivery, error)
GetDeliveryCount(ctx context.Context) ([]GetDeliveryCountRow, error)
UpdateDelivery(ctx context.Context, arg UpdateDeliveryParams) error
UpdateDeliveryStatus(ctx context.Context, arg UpdateDeliveryStatusParams) error
}
var _ Querier = (*Queries)(nil)

View File

@@ -186,3 +186,17 @@ func (q *Queries) UpdateDelivery(ctx context.Context, arg UpdateDeliveryParams)
)
return err
}
const updateDeliveryStatus = `-- name: UpdateDeliveryStatus :exec
UPDATE deliveries SET status = $1, updated_at = NOW() WHERE id = $2
`
type UpdateDeliveryStatusParams struct {
Status string `db:"status" json:"status"`
ID pgtype.UUID `db:"id" json:"id"`
}
func (q *Queries) UpdateDeliveryStatus(ctx context.Context, arg UpdateDeliveryStatusParams) error {
_, err := q.db.Exec(ctx, updateDeliveryStatus, arg.Status, arg.ID)
return err
}