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
|
||||
}
|
||||
Reference in New Issue
Block a user