Base Project
This commit is contained in:
146
sqlc_gen/cabinet.sql.go
Normal file
146
sqlc_gen/cabinet.sql.go
Normal file
@@ -0,0 +1,146 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: cabinet.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createCabinet = `-- name: CreateCabinet :one
|
||||
INSERT INTO cabinets (room_id,name, description, created_at)
|
||||
VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4
|
||||
)
|
||||
RETURNING id, room_id, name, description, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateCabinetParams struct {
|
||||
RoomID int64 `db:"room_id" json:"roomId"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Description pgtype.Text `db:"description" json:"description"`
|
||||
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateCabinet(ctx context.Context, arg CreateCabinetParams) (Cabinet, error) {
|
||||
row := q.db.QueryRow(ctx, createCabinet,
|
||||
arg.RoomID,
|
||||
arg.Name,
|
||||
arg.Description,
|
||||
arg.CreatedAt,
|
||||
)
|
||||
var i Cabinet
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.RoomID,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteCabinet = `-- name: DeleteCabinet :exec
|
||||
DELETE FROM cabinets
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteCabinet(ctx context.Context, id int64) error {
|
||||
_, err := q.db.Exec(ctx, deleteCabinet, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const getCabinetByID = `-- name: GetCabinetByID :one
|
||||
SELECT id, room_id, name, description, created_at, updated_at FROM cabinets
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetCabinetByID(ctx context.Context, id int64) (Cabinet, error) {
|
||||
row := q.db.QueryRow(ctx, getCabinetByID, id)
|
||||
var i Cabinet
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.RoomID,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listCabinets = `-- name: ListCabinets :many
|
||||
SELECT id, room_id, name, description, created_at, updated_at FROM cabinets
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListCabinets(ctx context.Context) ([]Cabinet, error) {
|
||||
rows, err := q.db.Query(ctx, listCabinets)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Cabinet
|
||||
for rows.Next() {
|
||||
var i Cabinet
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.RoomID,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&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 updateCabinet = `-- name: UpdateCabinet :one
|
||||
UPDATE cabinets
|
||||
SET name = coalesce($1, name),
|
||||
description = coalesce($2, description),
|
||||
updated_at = $3
|
||||
WHERE id = $4
|
||||
RETURNING id, room_id, name, description, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateCabinetParams struct {
|
||||
Name string `db:"name" json:"name"`
|
||||
Description pgtype.Text `db:"description" json:"description"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
ID int64 `db:"id" json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateCabinet(ctx context.Context, arg UpdateCabinetParams) (Cabinet, error) {
|
||||
row := q.db.QueryRow(ctx, updateCabinet,
|
||||
arg.Name,
|
||||
arg.Description,
|
||||
arg.UpdatedAt,
|
||||
arg.ID,
|
||||
)
|
||||
var i Cabinet
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.RoomID,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
32
sqlc_gen/db.go
Normal file
32
sqlc_gen/db.go
Normal file
@@ -0,0 +1,32 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
|
||||
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
|
||||
QueryRow(context.Context, string, ...interface{}) pgx.Row
|
||||
}
|
||||
|
||||
func New(db DBTX) *Queries {
|
||||
return &Queries{db: db}
|
||||
}
|
||||
|
||||
type Queries struct {
|
||||
db DBTX
|
||||
}
|
||||
|
||||
func (q *Queries) WithTx(tx pgx.Tx) *Queries {
|
||||
return &Queries{
|
||||
db: tx,
|
||||
}
|
||||
}
|
||||
471
sqlc_gen/models.go
Normal file
471
sqlc_gen/models.go
Normal file
@@ -0,0 +1,471 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type ComponentItemStatusEnum string
|
||||
|
||||
const (
|
||||
ComponentItemStatusEnumNormal ComponentItemStatusEnum = "normal"
|
||||
ComponentItemStatusEnumDamaged ComponentItemStatusEnum = "damaged"
|
||||
ComponentItemStatusEnumLongUnused ComponentItemStatusEnum = "long_unused"
|
||||
ComponentItemStatusEnumExpired ComponentItemStatusEnum = "expired"
|
||||
ComponentItemStatusEnumPendingInspection ComponentItemStatusEnum = "pending_inspection"
|
||||
)
|
||||
|
||||
func (e *ComponentItemStatusEnum) Scan(src interface{}) error {
|
||||
switch s := src.(type) {
|
||||
case []byte:
|
||||
*e = ComponentItemStatusEnum(s)
|
||||
case string:
|
||||
*e = ComponentItemStatusEnum(s)
|
||||
default:
|
||||
return fmt.Errorf("unsupported scan type for ComponentItemStatusEnum: %T", src)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type NullComponentItemStatusEnum struct {
|
||||
ComponentItemStatusEnum ComponentItemStatusEnum `json:"componentItemStatusEnum"`
|
||||
Valid bool `json:"valid"` // Valid is true if ComponentItemStatusEnum is not NULL
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (ns *NullComponentItemStatusEnum) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
ns.ComponentItemStatusEnum, ns.Valid = "", false
|
||||
return nil
|
||||
}
|
||||
ns.Valid = true
|
||||
return ns.ComponentItemStatusEnum.Scan(value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (ns NullComponentItemStatusEnum) Value() (driver.Value, error) {
|
||||
if !ns.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return string(ns.ComponentItemStatusEnum), nil
|
||||
}
|
||||
|
||||
type ContainerTypeEnum string
|
||||
|
||||
const (
|
||||
ContainerTypeEnumEmptyBox ContainerTypeEnum = "empty_box"
|
||||
ContainerTypeEnumTray ContainerTypeEnum = "tray"
|
||||
ContainerTypeEnumPaperBox ContainerTypeEnum = "paper_box"
|
||||
ContainerTypeEnumPlasticBox ContainerTypeEnum = "plastic_box"
|
||||
ContainerTypeEnumBag ContainerTypeEnum = "bag"
|
||||
ContainerTypeEnumOther ContainerTypeEnum = "other"
|
||||
)
|
||||
|
||||
func (e *ContainerTypeEnum) Scan(src interface{}) error {
|
||||
switch s := src.(type) {
|
||||
case []byte:
|
||||
*e = ContainerTypeEnum(s)
|
||||
case string:
|
||||
*e = ContainerTypeEnum(s)
|
||||
default:
|
||||
return fmt.Errorf("unsupported scan type for ContainerTypeEnum: %T", src)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type NullContainerTypeEnum struct {
|
||||
ContainerTypeEnum ContainerTypeEnum `json:"containerTypeEnum"`
|
||||
Valid bool `json:"valid"` // Valid is true if ContainerTypeEnum is not NULL
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (ns *NullContainerTypeEnum) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
ns.ContainerTypeEnum, ns.Valid = "", false
|
||||
return nil
|
||||
}
|
||||
ns.Valid = true
|
||||
return ns.ContainerTypeEnum.Scan(value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (ns NullContainerTypeEnum) Value() (driver.Value, error) {
|
||||
if !ns.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return string(ns.ContainerTypeEnum), nil
|
||||
}
|
||||
|
||||
type InvoiceStatusEnum string
|
||||
|
||||
const (
|
||||
InvoiceStatusEnumDraft InvoiceStatusEnum = "draft"
|
||||
InvoiceStatusEnumPending InvoiceStatusEnum = "pending"
|
||||
InvoiceStatusEnumApproved InvoiceStatusEnum = "approved"
|
||||
InvoiceStatusEnumCompleted InvoiceStatusEnum = "completed"
|
||||
InvoiceStatusEnumCancelled InvoiceStatusEnum = "cancelled"
|
||||
)
|
||||
|
||||
func (e *InvoiceStatusEnum) Scan(src interface{}) error {
|
||||
switch s := src.(type) {
|
||||
case []byte:
|
||||
*e = InvoiceStatusEnum(s)
|
||||
case string:
|
||||
*e = InvoiceStatusEnum(s)
|
||||
default:
|
||||
return fmt.Errorf("unsupported scan type for InvoiceStatusEnum: %T", src)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type NullInvoiceStatusEnum struct {
|
||||
InvoiceStatusEnum InvoiceStatusEnum `json:"invoiceStatusEnum"`
|
||||
Valid bool `json:"valid"` // Valid is true if InvoiceStatusEnum is not NULL
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (ns *NullInvoiceStatusEnum) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
ns.InvoiceStatusEnum, ns.Valid = "", false
|
||||
return nil
|
||||
}
|
||||
ns.Valid = true
|
||||
return ns.InvoiceStatusEnum.Scan(value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (ns NullInvoiceStatusEnum) Value() (driver.Value, error) {
|
||||
if !ns.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return string(ns.InvoiceStatusEnum), nil
|
||||
}
|
||||
|
||||
type InvoiceTypeEnum string
|
||||
|
||||
const (
|
||||
InvoiceTypeEnumImport InvoiceTypeEnum = "import"
|
||||
InvoiceTypeEnumExport InvoiceTypeEnum = "export"
|
||||
)
|
||||
|
||||
func (e *InvoiceTypeEnum) Scan(src interface{}) error {
|
||||
switch s := src.(type) {
|
||||
case []byte:
|
||||
*e = InvoiceTypeEnum(s)
|
||||
case string:
|
||||
*e = InvoiceTypeEnum(s)
|
||||
default:
|
||||
return fmt.Errorf("unsupported scan type for InvoiceTypeEnum: %T", src)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type NullInvoiceTypeEnum struct {
|
||||
InvoiceTypeEnum InvoiceTypeEnum `json:"invoiceTypeEnum"`
|
||||
Valid bool `json:"valid"` // Valid is true if InvoiceTypeEnum is not NULL
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (ns *NullInvoiceTypeEnum) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
ns.InvoiceTypeEnum, ns.Valid = "", false
|
||||
return nil
|
||||
}
|
||||
ns.Valid = true
|
||||
return ns.InvoiceTypeEnum.Scan(value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (ns NullInvoiceTypeEnum) Value() (driver.Value, error) {
|
||||
if !ns.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return string(ns.InvoiceTypeEnum), nil
|
||||
}
|
||||
|
||||
type TransactionTypeEnum string
|
||||
|
||||
const (
|
||||
TransactionTypeEnumImport TransactionTypeEnum = "import"
|
||||
TransactionTypeEnumExport TransactionTypeEnum = "export"
|
||||
TransactionTypeEnumAdjustment TransactionTypeEnum = "adjustment"
|
||||
TransactionTypeEnumTransfer TransactionTypeEnum = "transfer"
|
||||
)
|
||||
|
||||
func (e *TransactionTypeEnum) Scan(src interface{}) error {
|
||||
switch s := src.(type) {
|
||||
case []byte:
|
||||
*e = TransactionTypeEnum(s)
|
||||
case string:
|
||||
*e = TransactionTypeEnum(s)
|
||||
default:
|
||||
return fmt.Errorf("unsupported scan type for TransactionTypeEnum: %T", src)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type NullTransactionTypeEnum struct {
|
||||
TransactionTypeEnum TransactionTypeEnum `json:"transactionTypeEnum"`
|
||||
Valid bool `json:"valid"` // Valid is true if TransactionTypeEnum is not NULL
|
||||
}
|
||||
|
||||
// Scan implements the Scanner interface.
|
||||
func (ns *NullTransactionTypeEnum) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
ns.TransactionTypeEnum, ns.Valid = "", false
|
||||
return nil
|
||||
}
|
||||
ns.Valid = true
|
||||
return ns.TransactionTypeEnum.Scan(value)
|
||||
}
|
||||
|
||||
// Value implements the driver Valuer interface.
|
||||
func (ns NullTransactionTypeEnum) Value() (driver.Value, error) {
|
||||
if !ns.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
return string(ns.TransactionTypeEnum), nil
|
||||
}
|
||||
|
||||
type AlternativeComponent struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
InvoiceConfigItemID int64 `db:"invoice_config_item_id" json:"invoiceConfigItemId"`
|
||||
AlternativeComponentID int64 `db:"alternative_component_id" json:"alternativeComponentId"`
|
||||
ConversionRatio pgtype.Numeric `db:"conversion_ratio" json:"conversionRatio"`
|
||||
Priority int32 `db:"priority" json:"priority"`
|
||||
Note pgtype.Text `db:"note" json:"note"`
|
||||
Metadata []byte `db:"metadata" json:"metadata"`
|
||||
}
|
||||
|
||||
type Cabinet struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
RoomID int64 `db:"room_id" json:"roomId"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Description pgtype.Text `db:"description" json:"description"`
|
||||
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
}
|
||||
|
||||
type Component struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
ComponentTypeID int64 `db:"component_type_id" json:"componentTypeId"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Description pgtype.Text `db:"description" json:"description"`
|
||||
Unit string `db:"unit" json:"unit"`
|
||||
TotalQuantity int32 `db:"total_quantity" json:"totalQuantity"`
|
||||
MinQuantity int32 `db:"min_quantity" json:"minQuantity"`
|
||||
Metadata []byte `db:"metadata" json:"metadata"`
|
||||
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
}
|
||||
|
||||
type ComponentCode struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
ComponentID int64 `db:"component_id" json:"componentId"`
|
||||
Code string `db:"code" json:"code"`
|
||||
CodeType pgtype.Text `db:"code_type" json:"codeType"`
|
||||
IsPrimary bool `db:"is_primary" json:"isPrimary"`
|
||||
Metadata []byte `db:"metadata" json:"metadata"`
|
||||
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
||||
}
|
||||
|
||||
type ComponentItem struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
ComponentID int64 `db:"component_id" json:"componentId"`
|
||||
ContainerID int64 `db:"container_id" json:"containerId"`
|
||||
Quantity int32 `db:"quantity" json:"quantity"`
|
||||
Status ComponentItemStatusEnum `db:"status" json:"status"`
|
||||
Metadata []byte `db:"metadata" json:"metadata"`
|
||||
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
}
|
||||
|
||||
type ComponentStatusHistory struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
ComponentItemID int64 `db:"component_item_id" json:"componentItemId"`
|
||||
OldStatus NullComponentItemStatusEnum `db:"old_status" json:"oldStatus"`
|
||||
NewStatus ComponentItemStatusEnum `db:"new_status" json:"newStatus"`
|
||||
ChangedQuantity pgtype.Int4 `db:"changed_quantity" json:"changedQuantity"`
|
||||
Note pgtype.Text `db:"note" json:"note"`
|
||||
ChangedBy pgtype.Text `db:"changed_by" json:"changedBy"`
|
||||
ChangedAt time.Time `db:"changed_at" json:"changedAt"`
|
||||
}
|
||||
|
||||
type ComponentType struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Description pgtype.Text `db:"description" json:"description"`
|
||||
Metadata []byte `db:"metadata" json:"metadata"`
|
||||
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
}
|
||||
|
||||
type Container struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
ShelfID int64 `db:"shelf_id" json:"shelfId"`
|
||||
Name string `db:"name" json:"name"`
|
||||
ContainerType ContainerTypeEnum `db:"container_type" json:"containerType"`
|
||||
Description pgtype.Text `db:"description" json:"description"`
|
||||
MaxCapacity pgtype.Int4 `db:"max_capacity" json:"maxCapacity"`
|
||||
Metadata []byte `db:"metadata" json:"metadata"`
|
||||
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
}
|
||||
|
||||
type Invoice struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
InvoiceCode string `db:"invoice_code" json:"invoiceCode"`
|
||||
Type InvoiceTypeEnum `db:"type" json:"type"`
|
||||
Status InvoiceStatusEnum `db:"status" json:"status"`
|
||||
InvoiceConfigID pgtype.Int8 `db:"invoice_config_id" json:"invoiceConfigId"`
|
||||
TotalItems int32 `db:"total_items" json:"totalItems"`
|
||||
Note pgtype.Text `db:"note" json:"note"`
|
||||
CreatedBy pgtype.Text `db:"created_by" json:"createdBy"`
|
||||
ApprovedBy pgtype.Text `db:"approved_by" json:"approvedBy"`
|
||||
CompletedAt pgtype.Timestamptz `db:"completed_at" json:"completedAt"`
|
||||
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
Metadata []byte `db:"metadata" json:"metadata"`
|
||||
}
|
||||
|
||||
type InvoiceConfig struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
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"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
}
|
||||
|
||||
type InvoiceConfigItem struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
InvoiceConfigID int64 `db:"invoice_config_id" json:"invoiceConfigId"`
|
||||
ComponentID int64 `db:"component_id" json:"componentId"`
|
||||
RequiredQuantity int32 `db:"required_quantity" json:"requiredQuantity"`
|
||||
AllowAlternative bool `db:"allow_alternative" json:"allowAlternative"`
|
||||
PriorityOrder int32 `db:"priority_order" json:"priorityOrder"`
|
||||
Note pgtype.Text `db:"note" json:"note"`
|
||||
Metadata []byte `db:"metadata" json:"metadata"`
|
||||
}
|
||||
|
||||
type InvoiceItem struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
InvoiceID int64 `db:"invoice_id" json:"invoiceId"`
|
||||
ComponentID int64 `db:"component_id" json:"componentId"`
|
||||
OriginalComponentID pgtype.Int8 `db:"original_component_id" json:"originalComponentId"`
|
||||
RequiredQuantity int32 `db:"required_quantity" json:"requiredQuantity"`
|
||||
ActualQuantity int32 `db:"actual_quantity" json:"actualQuantity"`
|
||||
IsSubstituted bool `db:"is_substituted" json:"isSubstituted"`
|
||||
IsShort bool `db:"is_short" json:"isShort"`
|
||||
ShortageQuantity int32 `db:"shortage_quantity" json:"shortageQuantity"`
|
||||
Note pgtype.Text `db:"note" json:"note"`
|
||||
Metadata []byte `db:"metadata" json:"metadata"`
|
||||
}
|
||||
|
||||
type InvoiceItemLocation struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
InvoiceItemID int64 `db:"invoice_item_id" json:"invoiceItemId"`
|
||||
ContainerID int64 `db:"container_id" json:"containerId"`
|
||||
Quantity int32 `db:"quantity" json:"quantity"`
|
||||
}
|
||||
|
||||
type InvoiceStatusHistory struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
InvoiceID int64 `db:"invoice_id" json:"invoiceId"`
|
||||
OldStatus pgtype.Text `db:"old_status" json:"oldStatus"`
|
||||
NewStatus string `db:"new_status" json:"newStatus"`
|
||||
ChangedBy pgtype.Text `db:"changed_by" json:"changedBy"`
|
||||
Note pgtype.Text `db:"note" json:"note"`
|
||||
ChangedAt time.Time `db:"changed_at" json:"changedAt"`
|
||||
}
|
||||
|
||||
type Permission struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Description pgtype.Text `db:"description" json:"description"`
|
||||
CreatedAt pgtype.Timestamptz `db:"created_at" json:"createdAt"`
|
||||
CreatedBy pgtype.Text `db:"created_by" json:"createdBy"`
|
||||
}
|
||||
|
||||
type Role struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Description pgtype.Text `db:"description" json:"description"`
|
||||
CreatedAt pgtype.Timestamptz `db:"created_at" json:"createdAt"`
|
||||
CreatedBy pgtype.Text `db:"created_by" json:"createdBy"`
|
||||
}
|
||||
|
||||
type RolePermission struct {
|
||||
RoleID uuid.UUID `db:"role_id" json:"roleId"`
|
||||
PermissionID uuid.UUID `db:"permission_id" json:"permissionId"`
|
||||
AssignedAt pgtype.Timestamptz `db:"assigned_at" json:"assignedAt"`
|
||||
}
|
||||
|
||||
type Room struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
WarehouseID int64 `db:"warehouse_id" json:"warehouseId"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Description pgtype.Text `db:"description" json:"description"`
|
||||
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
}
|
||||
|
||||
type Shelf struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
CabinetID int64 `db:"cabinet_id" json:"cabinetId"`
|
||||
Name string `db:"name" json:"name"`
|
||||
LevelIndex int32 `db:"level_index" json:"levelIndex"`
|
||||
Description pgtype.Text `db:"description" json:"description"`
|
||||
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
}
|
||||
|
||||
type StockTransaction struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
InvoiceID int64 `db:"invoice_id" json:"invoiceId"`
|
||||
ComponentID int64 `db:"component_id" json:"componentId"`
|
||||
ContainerID int64 `db:"container_id" json:"containerId"`
|
||||
TransactionType TransactionTypeEnum `db:"transaction_type" json:"transactionType"`
|
||||
Quantity int32 `db:"quantity" json:"quantity"`
|
||||
BalanceAfter pgtype.Int4 `db:"balance_after" json:"balanceAfter"`
|
||||
Note pgtype.Text `db:"note" json:"note"`
|
||||
CreatedBy pgtype.Text `db:"created_by" json:"createdBy"`
|
||||
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
Username string `db:"username" json:"username"`
|
||||
Email string `db:"email" json:"email"`
|
||||
PasswordHash string `db:"password_hash" json:"passwordHash"`
|
||||
FullName pgtype.Text `db:"full_name" json:"fullName"`
|
||||
IsActive pgtype.Bool `db:"is_active" json:"isActive"`
|
||||
CreatedAt pgtype.Timestamptz `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt pgtype.Timestamptz `db:"updated_at" json:"updatedAt"`
|
||||
CreatedBy pgtype.Text `db:"created_by" json:"createdBy"`
|
||||
}
|
||||
|
||||
type UserRole struct {
|
||||
UserID uuid.UUID `db:"user_id" json:"userId"`
|
||||
RoleID uuid.UUID `db:"role_id" json:"roleId"`
|
||||
AssignedAt pgtype.Timestamptz `db:"assigned_at" json:"assignedAt"`
|
||||
}
|
||||
|
||||
type Warehouse struct {
|
||||
ID int64 `db:"id" json:"id"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Description pgtype.Text `db:"description" json:"description"`
|
||||
Address pgtype.Text `db:"address" json:"address"`
|
||||
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
}
|
||||
47
sqlc_gen/querier.go
Normal file
47
sqlc_gen/querier.go
Normal file
@@ -0,0 +1,47 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Querier interface {
|
||||
AssignRoleToUser(ctx context.Context, arg AssignRoleToUserParams) (UserRole, error)
|
||||
CountUsersByRoleID(ctx context.Context, roleID uuid.UUID) (int64, error)
|
||||
CreateCabinet(ctx context.Context, arg CreateCabinetParams) (Cabinet, error)
|
||||
CreateRole(ctx context.Context, arg CreateRoleParams) (Role, error)
|
||||
CreateRoom(ctx context.Context, arg CreateRoomParams) (Room, error)
|
||||
CreateUser(ctx context.Context, arg CreateUserParams) (uuid.UUID, error)
|
||||
CreateWarehouse(ctx context.Context, arg CreateWarehouseParams) (Warehouse, error)
|
||||
DeleteCabinet(ctx context.Context, id int64) error
|
||||
DeleteRole(ctx context.Context, id uuid.UUID) error
|
||||
DeleteRoom(ctx context.Context, id int64) error
|
||||
DeleteWarehouse(ctx context.Context, id int64) error
|
||||
GetCabinetByID(ctx context.Context, id int64) (Cabinet, error)
|
||||
GetRoleByID(ctx context.Context, id uuid.UUID) (Role, error)
|
||||
GetRoomByID(ctx context.Context, id int64) (Room, error)
|
||||
GetUserByEmail(ctx context.Context, email string) (User, error)
|
||||
GetUserByID(ctx context.Context, id uuid.UUID) (User, error)
|
||||
GetUserByUsername(ctx context.Context, username string) (User, error)
|
||||
GetUserRole(ctx context.Context, arg GetUserRoleParams) (UserRole, error)
|
||||
GetUserRolesByRoleID(ctx context.Context, roleID uuid.UUID) ([]GetUserRolesByRoleIDRow, error)
|
||||
GetUserRolesByUserID(ctx context.Context, userID uuid.UUID) ([]GetUserRolesByUserIDRow, error)
|
||||
GetWarehouseByID(ctx context.Context, id int64) (Warehouse, error)
|
||||
ListCabinets(ctx context.Context) ([]Cabinet, error)
|
||||
ListRoles(ctx context.Context) ([]Role, error)
|
||||
ListRooms(ctx context.Context) ([]Room, error)
|
||||
ListWarehouses(ctx context.Context) ([]Warehouse, error)
|
||||
RemoveAllRolesFromUser(ctx context.Context, userID uuid.UUID) error
|
||||
RemoveRoleFromUser(ctx context.Context, arg RemoveRoleFromUserParams) error
|
||||
UpdateCabinet(ctx context.Context, arg UpdateCabinetParams) (Cabinet, error)
|
||||
UpdateRole(ctx context.Context, arg UpdateRoleParams) (Role, error)
|
||||
UpdateRoom(ctx context.Context, arg UpdateRoomParams) (Room, error)
|
||||
UpdateWarehouse(ctx context.Context, arg UpdateWarehouseParams) (Warehouse, error)
|
||||
}
|
||||
|
||||
var _ Querier = (*Queries)(nil)
|
||||
127
sqlc_gen/roles.sql.go
Normal file
127
sqlc_gen/roles.sql.go
Normal file
@@ -0,0 +1,127 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: roles.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createRole = `-- name: CreateRole :one
|
||||
INSERT INTO roles (name, description, created_by)
|
||||
VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3)
|
||||
RETURNING id, name, description, created_at, created_by
|
||||
`
|
||||
|
||||
type CreateRoleParams struct {
|
||||
Name string `db:"name" json:"name"`
|
||||
Description pgtype.Text `db:"description" json:"description"`
|
||||
CreatedBy pgtype.Text `db:"created_by" json:"createdBy"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateRole(ctx context.Context, arg CreateRoleParams) (Role, error) {
|
||||
row := q.db.QueryRow(ctx, createRole, arg.Name, arg.Description, arg.CreatedBy)
|
||||
var i Role
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.CreatedAt,
|
||||
&i.CreatedBy,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteRole = `-- name: DeleteRole :exec
|
||||
DELETE FROM roles
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteRole(ctx context.Context, id uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, deleteRole, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const getRoleByID = `-- name: GetRoleByID :one
|
||||
SELECT id, name, description, created_at, created_by FROM roles
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetRoleByID(ctx context.Context, id uuid.UUID) (Role, error) {
|
||||
row := q.db.QueryRow(ctx, getRoleByID, id)
|
||||
var i Role
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.CreatedAt,
|
||||
&i.CreatedBy,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listRoles = `-- name: ListRoles :many
|
||||
SELECT id, name, description, created_at, created_by FROM roles
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListRoles(ctx context.Context) ([]Role, error) {
|
||||
rows, err := q.db.Query(ctx, listRoles)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Role
|
||||
for rows.Next() {
|
||||
var i Role
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.CreatedAt,
|
||||
&i.CreatedBy,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateRole = `-- name: UpdateRole :one
|
||||
UPDATE roles
|
||||
SET name = $1,
|
||||
description = $2
|
||||
WHERE id = $3
|
||||
RETURNING id, name, description, created_at, created_by
|
||||
`
|
||||
|
||||
type UpdateRoleParams struct {
|
||||
Name string `db:"name" json:"name"`
|
||||
Description pgtype.Text `db:"description" json:"description"`
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateRole(ctx context.Context, arg UpdateRoleParams) (Role, error) {
|
||||
row := q.db.QueryRow(ctx, updateRole, arg.Name, arg.Description, arg.ID)
|
||||
var i Role
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.CreatedAt,
|
||||
&i.CreatedBy,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
146
sqlc_gen/room.sql.go
Normal file
146
sqlc_gen/room.sql.go
Normal file
@@ -0,0 +1,146 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: room.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createRoom = `-- name: CreateRoom :one
|
||||
INSERT INTO rooms (warehouse_id,name, description, created_at)
|
||||
VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4
|
||||
)
|
||||
RETURNING id, warehouse_id, name, description, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateRoomParams struct {
|
||||
WarehouseID int64 `db:"warehouse_id" json:"warehouseId"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Description pgtype.Text `db:"description" json:"description"`
|
||||
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateRoom(ctx context.Context, arg CreateRoomParams) (Room, error) {
|
||||
row := q.db.QueryRow(ctx, createRoom,
|
||||
arg.WarehouseID,
|
||||
arg.Name,
|
||||
arg.Description,
|
||||
arg.CreatedAt,
|
||||
)
|
||||
var i Room
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.WarehouseID,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteRoom = `-- name: DeleteRoom :exec
|
||||
DELETE FROM rooms
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteRoom(ctx context.Context, id int64) error {
|
||||
_, err := q.db.Exec(ctx, deleteRoom, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const getRoomByID = `-- name: GetRoomByID :one
|
||||
SELECT id, warehouse_id, name, description, created_at, updated_at FROM rooms
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetRoomByID(ctx context.Context, id int64) (Room, error) {
|
||||
row := q.db.QueryRow(ctx, getRoomByID, id)
|
||||
var i Room
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.WarehouseID,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listRooms = `-- name: ListRooms :many
|
||||
SELECT id, warehouse_id, name, description, created_at, updated_at FROM rooms
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListRooms(ctx context.Context) ([]Room, error) {
|
||||
rows, err := q.db.Query(ctx, listRooms)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Room
|
||||
for rows.Next() {
|
||||
var i Room
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.WarehouseID,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&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 updateRoom = `-- name: UpdateRoom :one
|
||||
UPDATE rooms
|
||||
SET name = coalesce($1, name),
|
||||
description = coalesce($2, description),
|
||||
updated_at = $3
|
||||
WHERE id = $4
|
||||
RETURNING id, warehouse_id, name, description, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateRoomParams struct {
|
||||
Name string `db:"name" json:"name"`
|
||||
Description pgtype.Text `db:"description" json:"description"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
ID int64 `db:"id" json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateRoom(ctx context.Context, arg UpdateRoomParams) (Room, error) {
|
||||
row := q.db.QueryRow(ctx, updateRoom,
|
||||
arg.Name,
|
||||
arg.Description,
|
||||
arg.UpdatedAt,
|
||||
arg.ID,
|
||||
)
|
||||
var i Room
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.WarehouseID,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
173
sqlc_gen/user_roles.sql.go
Normal file
173
sqlc_gen/user_roles.sql.go
Normal file
@@ -0,0 +1,173 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: user_roles.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const assignRoleToUser = `-- name: AssignRoleToUser :one
|
||||
INSERT INTO user_roles (user_id, role_id)
|
||||
VALUES (
|
||||
$1,
|
||||
$2)
|
||||
RETURNING user_id, role_id, assigned_at
|
||||
`
|
||||
|
||||
type AssignRoleToUserParams struct {
|
||||
UserID uuid.UUID `db:"user_id" json:"userId"`
|
||||
RoleID uuid.UUID `db:"role_id" json:"roleId"`
|
||||
}
|
||||
|
||||
func (q *Queries) AssignRoleToUser(ctx context.Context, arg AssignRoleToUserParams) (UserRole, error) {
|
||||
row := q.db.QueryRow(ctx, assignRoleToUser, arg.UserID, arg.RoleID)
|
||||
var i UserRole
|
||||
err := row.Scan(&i.UserID, &i.RoleID, &i.AssignedAt)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const countUsersByRoleID = `-- name: CountUsersByRoleID :one
|
||||
SELECT COUNT(*) FROM user_roles
|
||||
WHERE role_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) CountUsersByRoleID(ctx context.Context, roleID uuid.UUID) (int64, error) {
|
||||
row := q.db.QueryRow(ctx, countUsersByRoleID, roleID)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
||||
const getUserRole = `-- name: GetUserRole :one
|
||||
SELECT user_id, role_id, assigned_at FROM user_roles
|
||||
WHERE user_id = $1 AND role_id = $2
|
||||
`
|
||||
|
||||
type GetUserRoleParams struct {
|
||||
UserID uuid.UUID `db:"user_id" json:"userId"`
|
||||
RoleID uuid.UUID `db:"role_id" json:"roleId"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetUserRole(ctx context.Context, arg GetUserRoleParams) (UserRole, error) {
|
||||
row := q.db.QueryRow(ctx, getUserRole, arg.UserID, arg.RoleID)
|
||||
var i UserRole
|
||||
err := row.Scan(&i.UserID, &i.RoleID, &i.AssignedAt)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserRolesByRoleID = `-- name: GetUserRolesByRoleID :many
|
||||
SELECT ur.user_id, ur.role_id, ur.assigned_at, u.username, u.email, u.full_name
|
||||
FROM user_roles ur
|
||||
JOIN users u ON u.id = ur.user_id
|
||||
WHERE ur.role_id = $1
|
||||
ORDER BY ur.assigned_at DESC
|
||||
`
|
||||
|
||||
type GetUserRolesByRoleIDRow struct {
|
||||
UserID uuid.UUID `db:"user_id" json:"userId"`
|
||||
RoleID uuid.UUID `db:"role_id" json:"roleId"`
|
||||
AssignedAt pgtype.Timestamptz `db:"assigned_at" json:"assignedAt"`
|
||||
Username string `db:"username" json:"username"`
|
||||
Email string `db:"email" json:"email"`
|
||||
FullName pgtype.Text `db:"full_name" json:"fullName"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetUserRolesByRoleID(ctx context.Context, roleID uuid.UUID) ([]GetUserRolesByRoleIDRow, error) {
|
||||
rows, err := q.db.Query(ctx, getUserRolesByRoleID, roleID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetUserRolesByRoleIDRow
|
||||
for rows.Next() {
|
||||
var i GetUserRolesByRoleIDRow
|
||||
if err := rows.Scan(
|
||||
&i.UserID,
|
||||
&i.RoleID,
|
||||
&i.AssignedAt,
|
||||
&i.Username,
|
||||
&i.Email,
|
||||
&i.FullName,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getUserRolesByUserID = `-- name: GetUserRolesByUserID :many
|
||||
SELECT ur.user_id, ur.role_id, ur.assigned_at, r.name AS role_name, r.description AS role_description
|
||||
FROM user_roles ur
|
||||
JOIN roles r ON r.id = ur.role_id
|
||||
WHERE ur.user_id = $1
|
||||
ORDER BY ur.assigned_at DESC
|
||||
`
|
||||
|
||||
type GetUserRolesByUserIDRow struct {
|
||||
UserID uuid.UUID `db:"user_id" json:"userId"`
|
||||
RoleID uuid.UUID `db:"role_id" json:"roleId"`
|
||||
AssignedAt pgtype.Timestamptz `db:"assigned_at" json:"assignedAt"`
|
||||
RoleName string `db:"role_name" json:"roleName"`
|
||||
RoleDescription pgtype.Text `db:"role_description" json:"roleDescription"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetUserRolesByUserID(ctx context.Context, userID uuid.UUID) ([]GetUserRolesByUserIDRow, error) {
|
||||
rows, err := q.db.Query(ctx, getUserRolesByUserID, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetUserRolesByUserIDRow
|
||||
for rows.Next() {
|
||||
var i GetUserRolesByUserIDRow
|
||||
if err := rows.Scan(
|
||||
&i.UserID,
|
||||
&i.RoleID,
|
||||
&i.AssignedAt,
|
||||
&i.RoleName,
|
||||
&i.RoleDescription,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const removeAllRolesFromUser = `-- name: RemoveAllRolesFromUser :exec
|
||||
DELETE FROM user_roles
|
||||
WHERE user_id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) RemoveAllRolesFromUser(ctx context.Context, userID uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, removeAllRolesFromUser, userID)
|
||||
return err
|
||||
}
|
||||
|
||||
const removeRoleFromUser = `-- name: RemoveRoleFromUser :exec
|
||||
DELETE FROM user_roles
|
||||
WHERE user_id = $1 AND role_id = $2
|
||||
`
|
||||
|
||||
type RemoveRoleFromUserParams struct {
|
||||
UserID uuid.UUID `db:"user_id" json:"userId"`
|
||||
RoleID uuid.UUID `db:"role_id" json:"roleId"`
|
||||
}
|
||||
|
||||
func (q *Queries) RemoveRoleFromUser(ctx context.Context, arg RemoveRoleFromUserParams) error {
|
||||
_, err := q.db.Exec(ctx, removeRoleFromUser, arg.UserID, arg.RoleID)
|
||||
return err
|
||||
}
|
||||
113
sqlc_gen/users.sql.go
Normal file
113
sqlc_gen/users.sql.go
Normal file
@@ -0,0 +1,113 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: users.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createUser = `-- name: CreateUser :one
|
||||
INSERT INTO users (username, email, password_hash, full_name, created_by)
|
||||
VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5)
|
||||
RETURNING id
|
||||
`
|
||||
|
||||
type CreateUserParams struct {
|
||||
Username string `db:"username" json:"username"`
|
||||
Email string `db:"email" json:"email"`
|
||||
PasswordHash string `db:"password_hash" json:"passwordHash"`
|
||||
FullName pgtype.Text `db:"full_name" json:"fullName"`
|
||||
CreatedBy pgtype.Text `db:"created_by" json:"createdBy"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (uuid.UUID, error) {
|
||||
row := q.db.QueryRow(ctx, createUser,
|
||||
arg.Username,
|
||||
arg.Email,
|
||||
arg.PasswordHash,
|
||||
arg.FullName,
|
||||
arg.CreatedBy,
|
||||
)
|
||||
var id uuid.UUID
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const getUserByEmail = `-- name: GetUserByEmail :one
|
||||
SELECT id, username, email, password_hash, full_name, is_active, created_at, updated_at, created_by FROM users
|
||||
WHERE email = $1
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error) {
|
||||
row := q.db.QueryRow(ctx, getUserByEmail, email)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Username,
|
||||
&i.Email,
|
||||
&i.PasswordHash,
|
||||
&i.FullName,
|
||||
&i.IsActive,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.CreatedBy,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserByID = `-- name: GetUserByID :one
|
||||
SELECT id, username, email, password_hash, full_name, is_active, created_at, updated_at, created_by FROM users
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetUserByID(ctx context.Context, id uuid.UUID) (User, error) {
|
||||
row := q.db.QueryRow(ctx, getUserByID, id)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Username,
|
||||
&i.Email,
|
||||
&i.PasswordHash,
|
||||
&i.FullName,
|
||||
&i.IsActive,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.CreatedBy,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserByUsername = `-- name: GetUserByUsername :one
|
||||
SELECT id, username, email, password_hash, full_name, is_active, created_at, updated_at, created_by FROM users
|
||||
WHERE username = $1
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
func (q *Queries) GetUserByUsername(ctx context.Context, username string) (User, error) {
|
||||
row := q.db.QueryRow(ctx, getUserByUsername, username)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Username,
|
||||
&i.Email,
|
||||
&i.PasswordHash,
|
||||
&i.FullName,
|
||||
&i.IsActive,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.CreatedBy,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
149
sqlc_gen/warehouse.sql.go
Normal file
149
sqlc_gen/warehouse.sql.go
Normal file
@@ -0,0 +1,149 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: warehouse.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createWarehouse = `-- name: CreateWarehouse :one
|
||||
INSERT INTO warehouses (name, description, address, created_at)
|
||||
VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4
|
||||
)
|
||||
RETURNING id, name, description, address, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateWarehouseParams struct {
|
||||
Name string `db:"name" json:"name"`
|
||||
Description pgtype.Text `db:"description" json:"description"`
|
||||
Address pgtype.Text `db:"address" json:"address"`
|
||||
CreatedAt time.Time `db:"created_at" json:"createdAt"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateWarehouse(ctx context.Context, arg CreateWarehouseParams) (Warehouse, error) {
|
||||
row := q.db.QueryRow(ctx, createWarehouse,
|
||||
arg.Name,
|
||||
arg.Description,
|
||||
arg.Address,
|
||||
arg.CreatedAt,
|
||||
)
|
||||
var i Warehouse
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.Address,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteWarehouse = `-- name: DeleteWarehouse :exec
|
||||
DELETE FROM warehouses
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteWarehouse(ctx context.Context, id int64) error {
|
||||
_, err := q.db.Exec(ctx, deleteWarehouse, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const getWarehouseByID = `-- name: GetWarehouseByID :one
|
||||
SELECT id, name, description, address, created_at, updated_at FROM warehouses
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetWarehouseByID(ctx context.Context, id int64) (Warehouse, error) {
|
||||
row := q.db.QueryRow(ctx, getWarehouseByID, id)
|
||||
var i Warehouse
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.Address,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listWarehouses = `-- name: ListWarehouses :many
|
||||
SELECT id, name, description, address, created_at, updated_at FROM warehouses
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListWarehouses(ctx context.Context) ([]Warehouse, error) {
|
||||
rows, err := q.db.Query(ctx, listWarehouses)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Warehouse
|
||||
for rows.Next() {
|
||||
var i Warehouse
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.Address,
|
||||
&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 updateWarehouse = `-- name: UpdateWarehouse :one
|
||||
UPDATE warehouses
|
||||
SET name = CASE WHEN $1 = '' THEN name ELSE $1 END,
|
||||
description = coalesce($2, description),
|
||||
address = coalesce($3, address),
|
||||
updated_at = $4
|
||||
WHERE id = $5
|
||||
RETURNING id, name, description, address, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateWarehouseParams struct {
|
||||
Name interface{} `db:"name" json:"name"`
|
||||
Description pgtype.Text `db:"description" json:"description"`
|
||||
Address pgtype.Text `db:"address" json:"address"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
ID int64 `db:"id" json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateWarehouse(ctx context.Context, arg UpdateWarehouseParams) (Warehouse, error) {
|
||||
row := q.db.QueryRow(ctx, updateWarehouse,
|
||||
arg.Name,
|
||||
arg.Description,
|
||||
arg.Address,
|
||||
arg.UpdatedAt,
|
||||
arg.ID,
|
||||
)
|
||||
var i Warehouse
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.Name,
|
||||
&i.Description,
|
||||
&i.Address,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
Reference in New Issue
Block a user