feat: implement component-item management with CRUD operations and status updates
This commit is contained in:
320
sqlc_gen/component_item.sql.go
Normal file
320
sqlc_gen/component_item.sql.go
Normal file
@@ -0,0 +1,320 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: component_item.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
const createComponentItem = `-- name: CreateComponentItem :one
|
||||
INSERT INTO component_items (component_id,container_id,quantity, status, metadata, created_at)
|
||||
VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5,
|
||||
$6
|
||||
)
|
||||
RETURNING id, component_id, container_id, quantity, status, metadata, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateComponentItemParams struct {
|
||||
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"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateComponentItem(ctx context.Context, arg CreateComponentItemParams) (ComponentItem, error) {
|
||||
row := q.db.QueryRow(ctx, createComponentItem,
|
||||
arg.ComponentID,
|
||||
arg.ContainerID,
|
||||
arg.Quantity,
|
||||
arg.Status,
|
||||
arg.Metadata,
|
||||
arg.CreatedAt,
|
||||
)
|
||||
var i ComponentItem
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ComponentID,
|
||||
&i.ContainerID,
|
||||
&i.Quantity,
|
||||
&i.Status,
|
||||
&i.Metadata,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteComponentItem = `-- name: DeleteComponentItem :execrows
|
||||
DELETE FROM component_items
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteComponentItem(ctx context.Context, id int64) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, deleteComponentItem, id)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const findComponentItem = `-- name: FindComponentItem :many
|
||||
SELECT
|
||||
c.name AS component_name,
|
||||
ct.name AS type_name,
|
||||
ci.quantity,
|
||||
ci.status,
|
||||
cn.name AS container_name,
|
||||
cn.container_type,
|
||||
s.name AS shelf_name,
|
||||
cb.name AS cabinet_name,
|
||||
r.name AS room_name,
|
||||
w.name AS warehouse_name
|
||||
FROM component_items ci
|
||||
JOIN components c ON ci.component_id = c.id
|
||||
JOIN component_types ct ON c.component_type_id = ct.id
|
||||
JOIN containers cn ON ci.container_id = cn.id
|
||||
JOIN shelves s ON cn.shelf_id = s.id
|
||||
JOIN cabinets cb ON s.cabinet_id = cb.id
|
||||
JOIN rooms r ON cb.room_id = r.id
|
||||
JOIN warehouses w ON r.warehouse_id = w.id
|
||||
WHERE ci.component_id = $1 AND ci.quantity > 0
|
||||
`
|
||||
|
||||
type FindComponentItemRow struct {
|
||||
ComponentName string `db:"component_name" json:"componentName"`
|
||||
TypeName string `db:"type_name" json:"typeName"`
|
||||
Quantity int32 `db:"quantity" json:"quantity"`
|
||||
Status ComponentItemStatusEnum `db:"status" json:"status"`
|
||||
ContainerName string `db:"container_name" json:"containerName"`
|
||||
ContainerType ContainerTypeEnum `db:"container_type" json:"containerType"`
|
||||
ShelfName string `db:"shelf_name" json:"shelfName"`
|
||||
CabinetName string `db:"cabinet_name" json:"cabinetName"`
|
||||
RoomName string `db:"room_name" json:"roomName"`
|
||||
WarehouseName string `db:"warehouse_name" json:"warehouseName"`
|
||||
}
|
||||
|
||||
func (q *Queries) FindComponentItem(ctx context.Context, componentid int64) ([]FindComponentItemRow, error) {
|
||||
rows, err := q.db.Query(ctx, findComponentItem, componentid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []FindComponentItemRow
|
||||
for rows.Next() {
|
||||
var i FindComponentItemRow
|
||||
if err := rows.Scan(
|
||||
&i.ComponentName,
|
||||
&i.TypeName,
|
||||
&i.Quantity,
|
||||
&i.Status,
|
||||
&i.ContainerName,
|
||||
&i.ContainerType,
|
||||
&i.ShelfName,
|
||||
&i.CabinetName,
|
||||
&i.RoomName,
|
||||
&i.WarehouseName,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const getComponentItemByComponentContainerStatus = `-- name: GetComponentItemByComponentContainerStatus :one
|
||||
SELECT id, component_id, container_id, quantity, status, metadata, created_at, updated_at FROM component_items
|
||||
WHERE component_id = $1
|
||||
AND container_id = $2
|
||||
AND status = $3
|
||||
`
|
||||
|
||||
type GetComponentItemByComponentContainerStatusParams struct {
|
||||
ComponentID int64 `db:"component_id" json:"componentId"`
|
||||
ContainerID int64 `db:"container_id" json:"containerId"`
|
||||
Status ComponentItemStatusEnum `db:"status" json:"status"`
|
||||
}
|
||||
|
||||
func (q *Queries) GetComponentItemByComponentContainerStatus(ctx context.Context, arg GetComponentItemByComponentContainerStatusParams) (ComponentItem, error) {
|
||||
row := q.db.QueryRow(ctx, getComponentItemByComponentContainerStatus, arg.ComponentID, arg.ContainerID, arg.Status)
|
||||
var i ComponentItem
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ComponentID,
|
||||
&i.ContainerID,
|
||||
&i.Quantity,
|
||||
&i.Status,
|
||||
&i.Metadata,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getComponentItemByID = `-- name: GetComponentItemByID :one
|
||||
SELECT id, component_id, container_id, quantity, status, metadata, created_at, updated_at FROM component_items
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetComponentItemByID(ctx context.Context, id int64) (ComponentItem, error) {
|
||||
row := q.db.QueryRow(ctx, getComponentItemByID, id)
|
||||
var i ComponentItem
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ComponentID,
|
||||
&i.ContainerID,
|
||||
&i.Quantity,
|
||||
&i.Status,
|
||||
&i.Metadata,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listComponentItems = `-- name: ListComponentItems :many
|
||||
SELECT id, component_id, container_id, quantity, status, metadata, created_at, updated_at FROM component_items
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListComponentItems(ctx context.Context) ([]ComponentItem, error) {
|
||||
rows, err := q.db.Query(ctx, listComponentItems)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ComponentItem
|
||||
for rows.Next() {
|
||||
var i ComponentItem
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ComponentID,
|
||||
&i.ContainerID,
|
||||
&i.Quantity,
|
||||
&i.Status,
|
||||
&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 updateComponentItem = `-- name: UpdateComponentItem :one
|
||||
UPDATE component_items
|
||||
SET component_id = CASE WHEN $1 = '' THEN component_id ELSE $1 END,
|
||||
container_id = CASE WHEN $2 = '' THEN container_id ELSE $2 END,
|
||||
metadata = coalesce($3, metadata),
|
||||
updated_at = $4
|
||||
WHERE id = $5
|
||||
RETURNING id, component_id, container_id, quantity, status, metadata, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateComponentItemParams struct {
|
||||
ComponentID interface{} `db:"component_id" json:"componentId"`
|
||||
ContainerID interface{} `db:"container_id" json:"containerId"`
|
||||
Metadata []byte `db:"metadata" json:"metadata"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
ID int64 `db:"id" json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateComponentItem(ctx context.Context, arg UpdateComponentItemParams) (ComponentItem, error) {
|
||||
row := q.db.QueryRow(ctx, updateComponentItem,
|
||||
arg.ComponentID,
|
||||
arg.ContainerID,
|
||||
arg.Metadata,
|
||||
arg.UpdatedAt,
|
||||
arg.ID,
|
||||
)
|
||||
var i ComponentItem
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ComponentID,
|
||||
&i.ContainerID,
|
||||
&i.Quantity,
|
||||
&i.Status,
|
||||
&i.Metadata,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateComponentItemQuantity = `-- name: UpdateComponentItemQuantity :one
|
||||
UPDATE component_items
|
||||
SET quantity = $1,
|
||||
updated_at = $2
|
||||
WHERE id = $3
|
||||
RETURNING id, component_id, container_id, quantity, status, metadata, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateComponentItemQuantityParams struct {
|
||||
Quantity int32 `db:"quantity" json:"quantity"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
ID int64 `db:"id" json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateComponentItemQuantity(ctx context.Context, arg UpdateComponentItemQuantityParams) (ComponentItem, error) {
|
||||
row := q.db.QueryRow(ctx, updateComponentItemQuantity, arg.Quantity, arg.UpdatedAt, arg.ID)
|
||||
var i ComponentItem
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ComponentID,
|
||||
&i.ContainerID,
|
||||
&i.Quantity,
|
||||
&i.Status,
|
||||
&i.Metadata,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const updateComponentItemStatus = `-- name: UpdateComponentItemStatus :one
|
||||
UPDATE component_items
|
||||
SET status = $1,
|
||||
updated_at = $2
|
||||
WHERE id = $3
|
||||
RETURNING id, component_id, container_id, quantity, status, metadata, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateComponentItemStatusParams struct {
|
||||
Status ComponentItemStatusEnum `db:"status" json:"status"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
ID int64 `db:"id" json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateComponentItemStatus(ctx context.Context, arg UpdateComponentItemStatusParams) (ComponentItem, error) {
|
||||
row := q.db.QueryRow(ctx, updateComponentItemStatus, arg.Status, arg.UpdatedAt, arg.ID)
|
||||
var i ComponentItem
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ComponentID,
|
||||
&i.ContainerID,
|
||||
&i.Quantity,
|
||||
&i.Status,
|
||||
&i.Metadata,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
64
sqlc_gen/component_status_history.sql.go
Normal file
64
sqlc_gen/component_status_history.sql.go
Normal file
@@ -0,0 +1,64 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: component_status_history.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createComponentStatusHistory = `-- name: CreateComponentStatusHistory :one
|
||||
INSERT INTO component_status_history (
|
||||
component_item_id, old_status, new_status,
|
||||
changed_quantity, note, changed_by, changed_at
|
||||
)
|
||||
VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5,
|
||||
$6,
|
||||
$7
|
||||
)
|
||||
RETURNING id, component_item_id, old_status, new_status, changed_quantity, note, changed_by, changed_at
|
||||
`
|
||||
|
||||
type CreateComponentStatusHistoryParams struct {
|
||||
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"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateComponentStatusHistory(ctx context.Context, arg CreateComponentStatusHistoryParams) (ComponentStatusHistory, error) {
|
||||
row := q.db.QueryRow(ctx, createComponentStatusHistory,
|
||||
arg.ComponentItemID,
|
||||
arg.OldStatus,
|
||||
arg.NewStatus,
|
||||
arg.ChangedQuantity,
|
||||
arg.Note,
|
||||
arg.ChangedBy,
|
||||
arg.ChangedAt,
|
||||
)
|
||||
var i ComponentStatusHistory
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.ComponentItemID,
|
||||
&i.OldStatus,
|
||||
&i.NewStatus,
|
||||
&i.ChangedQuantity,
|
||||
&i.Note,
|
||||
&i.ChangedBy,
|
||||
&i.ChangedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -16,6 +16,8 @@ type Querier interface {
|
||||
CreateCabinet(ctx context.Context, arg CreateCabinetParams) (Cabinet, error)
|
||||
CreateComponent(ctx context.Context, arg CreateComponentParams) (Component, error)
|
||||
CreateComponentCode(ctx context.Context, arg CreateComponentCodeParams) (ComponentCode, error)
|
||||
CreateComponentItem(ctx context.Context, arg CreateComponentItemParams) (ComponentItem, error)
|
||||
CreateComponentStatusHistory(ctx context.Context, arg CreateComponentStatusHistoryParams) (ComponentStatusHistory, error)
|
||||
CreateComponentType(ctx context.Context, arg CreateComponentTypeParams) (ComponentType, error)
|
||||
CreateContainer(ctx context.Context, arg CreateContainerParams) (Container, error)
|
||||
CreateRole(ctx context.Context, arg CreateRoleParams) (Role, error)
|
||||
@@ -26,15 +28,19 @@ type Querier interface {
|
||||
DeleteCabinet(ctx context.Context, id int64) (int64, error)
|
||||
DeleteComponent(ctx context.Context, id int64) (int64, error)
|
||||
DeleteComponentCode(ctx context.Context, id int64) (int64, error)
|
||||
DeleteComponentItem(ctx context.Context, id int64) (int64, error)
|
||||
DeleteComponentType(ctx context.Context, id int64) (int64, error)
|
||||
DeleteContainer(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)
|
||||
DeleteWarehouse(ctx context.Context, id int64) (int64, error)
|
||||
FindComponentItem(ctx context.Context, componentid int64) ([]FindComponentItemRow, error)
|
||||
GetCabinetByID(ctx context.Context, id int64) (Cabinet, error)
|
||||
GetComponentByID(ctx context.Context, id int64) (Component, error)
|
||||
GetComponentCodeByID(ctx context.Context, id int64) (ComponentCode, error)
|
||||
GetComponentItemByComponentContainerStatus(ctx context.Context, arg GetComponentItemByComponentContainerStatusParams) (ComponentItem, error)
|
||||
GetComponentItemByID(ctx context.Context, id int64) (ComponentItem, error)
|
||||
GetComponentTypeByID(ctx context.Context, id int64) (ComponentType, error)
|
||||
GetContainerByID(ctx context.Context, id int64) (Container, error)
|
||||
GetRoleByID(ctx context.Context, id uuid.UUID) (Role, error)
|
||||
@@ -49,6 +55,7 @@ type Querier interface {
|
||||
GetWarehouseByID(ctx context.Context, id int64) (Warehouse, error)
|
||||
ListCabinets(ctx context.Context) ([]Cabinet, error)
|
||||
ListComponentCodes(ctx context.Context) ([]ComponentCode, error)
|
||||
ListComponentItems(ctx context.Context) ([]ComponentItem, error)
|
||||
ListComponentTypes(ctx context.Context) ([]ComponentType, error)
|
||||
ListComponents(ctx context.Context) ([]Component, error)
|
||||
ListContainers(ctx context.Context) ([]Container, error)
|
||||
@@ -61,6 +68,9 @@ type Querier interface {
|
||||
UpdateCabinet(ctx context.Context, arg UpdateCabinetParams) (Cabinet, error)
|
||||
UpdateComponent(ctx context.Context, arg UpdateComponentParams) (Component, error)
|
||||
UpdateComponentCode(ctx context.Context, arg UpdateComponentCodeParams) (ComponentCode, error)
|
||||
UpdateComponentItem(ctx context.Context, arg UpdateComponentItemParams) (ComponentItem, error)
|
||||
UpdateComponentItemQuantity(ctx context.Context, arg UpdateComponentItemQuantityParams) (ComponentItem, error)
|
||||
UpdateComponentItemStatus(ctx context.Context, arg UpdateComponentItemStatusParams) (ComponentItem, error)
|
||||
UpdateComponentType(ctx context.Context, arg UpdateComponentTypeParams) (ComponentType, error)
|
||||
UpdateContainer(ctx context.Context, arg UpdateContainerParams) (Container, error)
|
||||
UpdateRole(ctx context.Context, arg UpdateRoleParams) (Role, error)
|
||||
|
||||
Reference in New Issue
Block a user