feat: add invoice-configs management functionality

This commit is contained in:
Tran Anh Tuan
2026-05-12 09:25:03 +07:00
parent 0ff65a18c0
commit eac8a686d1
14 changed files with 1534 additions and 1 deletions

View File

@@ -0,0 +1,172 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: invoice_config.sql
package db
import (
"context"
"time"
"github.com/jackc/pgx/v5/pgtype"
)
const createInvoiceConfig = `-- name: CreateInvoiceConfig :one
INSERT INTO invoice_configs (name, type, description, is_active, metadata, created_at)
VALUES (
$1,
$2,
$3,
$4,
$5,
$6
)
RETURNING id, name, type, description, is_active, metadata, created_at, updated_at
`
type CreateInvoiceConfigParams struct {
Name string `db:"name" json:"name"`
Type InvoiceTypeEnum `db:"type" json:"type"`
Description pgtype.Text `db:"description" json:"description"`
IsActive bool `db:"is_active" json:"isActive"`
Metadata []byte `db:"metadata" json:"metadata"`
CreatedAt time.Time `db:"created_at" json:"createdAt"`
}
func (q *Queries) CreateInvoiceConfig(ctx context.Context, arg CreateInvoiceConfigParams) (InvoiceConfig, error) {
row := q.db.QueryRow(ctx, createInvoiceConfig,
arg.Name,
arg.Type,
arg.Description,
arg.IsActive,
arg.Metadata,
arg.CreatedAt,
)
var i InvoiceConfig
err := row.Scan(
&i.ID,
&i.Name,
&i.Type,
&i.Description,
&i.IsActive,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const deleteInvoiceConfig = `-- name: DeleteInvoiceConfig :execrows
DELETE FROM invoice_configs
WHERE id = $1
`
func (q *Queries) DeleteInvoiceConfig(ctx context.Context, id int64) (int64, error) {
result, err := q.db.Exec(ctx, deleteInvoiceConfig, id)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const getInvoiceConfigByID = `-- name: GetInvoiceConfigByID :one
SELECT id, name, type, description, is_active, metadata, created_at, updated_at FROM invoice_configs
WHERE id = $1
`
func (q *Queries) GetInvoiceConfigByID(ctx context.Context, id int64) (InvoiceConfig, error) {
row := q.db.QueryRow(ctx, getInvoiceConfigByID, id)
var i InvoiceConfig
err := row.Scan(
&i.ID,
&i.Name,
&i.Type,
&i.Description,
&i.IsActive,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const listInvoiceConfigs = `-- name: ListInvoiceConfigs :many
SELECT id, name, type, description, is_active, metadata, created_at, updated_at FROM invoice_configs
ORDER BY created_at DESC
`
func (q *Queries) ListInvoiceConfigs(ctx context.Context) ([]InvoiceConfig, error) {
rows, err := q.db.Query(ctx, listInvoiceConfigs)
if err != nil {
return nil, err
}
defer rows.Close()
var items []InvoiceConfig
for rows.Next() {
var i InvoiceConfig
if err := rows.Scan(
&i.ID,
&i.Name,
&i.Type,
&i.Description,
&i.IsActive,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const updateInvoiceConfig = `-- name: UpdateInvoiceConfig :one
UPDATE invoice_configs
SET name = CASE WHEN $1 = '' THEN name ELSE $1 END,
type = coalesce($2, type),
description = coalesce($3, description),
is_active = coalesce($4, is_active),
metadata = coalesce($5, metadata),
updated_at = $6
WHERE id = $7
RETURNING id, name, type, description, is_active, metadata, created_at, updated_at
`
type UpdateInvoiceConfigParams struct {
Name interface{} `db:"name" json:"name"`
Type InvoiceTypeEnum `db:"type" json:"type"`
Description pgtype.Text `db:"description" json:"description"`
IsActive bool `db:"is_active" json:"isActive"`
Metadata []byte `db:"metadata" json:"metadata"`
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
ID int64 `db:"id" json:"id"`
}
func (q *Queries) UpdateInvoiceConfig(ctx context.Context, arg UpdateInvoiceConfigParams) (InvoiceConfig, error) {
row := q.db.QueryRow(ctx, updateInvoiceConfig,
arg.Name,
arg.Type,
arg.Description,
arg.IsActive,
arg.Metadata,
arg.UpdatedAt,
arg.ID,
)
var i InvoiceConfig
err := row.Scan(
&i.ID,
&i.Name,
&i.Type,
&i.Description,
&i.IsActive,
&i.Metadata,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}

View File

@@ -20,6 +20,7 @@ type Querier interface {
CreateComponentStatusHistory(ctx context.Context, arg CreateComponentStatusHistoryParams) (ComponentStatusHistory, error)
CreateComponentType(ctx context.Context, arg CreateComponentTypeParams) (ComponentType, error)
CreateContainer(ctx context.Context, arg CreateContainerParams) (Container, error)
CreateInvoiceConfig(ctx context.Context, arg CreateInvoiceConfigParams) (InvoiceConfig, error)
CreateRole(ctx context.Context, arg CreateRoleParams) (Role, error)
CreateRoom(ctx context.Context, arg CreateRoomParams) (Room, error)
CreateShelve(ctx context.Context, arg CreateShelveParams) (Shelf, error)
@@ -31,6 +32,7 @@ type Querier interface {
DeleteComponentItem(ctx context.Context, id int64) (int64, error)
DeleteComponentType(ctx context.Context, id int64) (int64, error)
DeleteContainer(ctx context.Context, id int64) (int64, error)
DeleteInvoiceConfig(ctx context.Context, id int64) (int64, error)
DeleteRole(ctx context.Context, id uuid.UUID) (int64, error)
DeleteRoom(ctx context.Context, id int64) (int64, error)
DeleteShelve(ctx context.Context, id int64) (int64, error)
@@ -43,6 +45,7 @@ type Querier interface {
GetComponentItemByID(ctx context.Context, id int64) (ComponentItem, error)
GetComponentTypeByID(ctx context.Context, id int64) (ComponentType, error)
GetContainerByID(ctx context.Context, id int64) (Container, error)
GetInvoiceConfigByID(ctx context.Context, id int64) (InvoiceConfig, error)
GetRoleByID(ctx context.Context, id uuid.UUID) (Role, error)
GetRoomByID(ctx context.Context, id int64) (Room, error)
GetShelveByID(ctx context.Context, id int64) (Shelf, error)
@@ -59,6 +62,7 @@ type Querier interface {
ListComponentTypes(ctx context.Context) ([]ComponentType, error)
ListComponents(ctx context.Context) ([]Component, error)
ListContainers(ctx context.Context) ([]Container, error)
ListInvoiceConfigs(ctx context.Context) ([]InvoiceConfig, error)
ListRoles(ctx context.Context) ([]Role, error)
ListRooms(ctx context.Context) ([]Room, error)
ListShelves(ctx context.Context) ([]Shelf, error)
@@ -73,6 +77,7 @@ type Querier interface {
UpdateComponentItemStatus(ctx context.Context, arg UpdateComponentItemStatusParams) (ComponentItem, error)
UpdateComponentType(ctx context.Context, arg UpdateComponentTypeParams) (ComponentType, error)
UpdateContainer(ctx context.Context, arg UpdateContainerParams) (Container, error)
UpdateInvoiceConfig(ctx context.Context, arg UpdateInvoiceConfigParams) (InvoiceConfig, error)
UpdateRole(ctx context.Context, arg UpdateRoleParams) (Role, error)
UpdateRoom(ctx context.Context, arg UpdateRoomParams) (Room, error)
UpdateShelve(ctx context.Context, arg UpdateShelveParams) (Shelf, error)