feat: add shelve management functionality
This commit is contained in:
@@ -16,15 +16,18 @@ type Querier interface {
|
||||
CreateCabinet(ctx context.Context, arg CreateCabinetParams) (Cabinet, 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)
|
||||
CreateUser(ctx context.Context, arg CreateUserParams) (uuid.UUID, error)
|
||||
CreateWarehouse(ctx context.Context, arg CreateWarehouseParams) (Warehouse, error)
|
||||
DeleteCabinet(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)
|
||||
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)
|
||||
GetShelveByID(ctx context.Context, id int64) (Shelf, 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)
|
||||
@@ -35,12 +38,14 @@ type Querier interface {
|
||||
ListCabinets(ctx context.Context) ([]Cabinet, error)
|
||||
ListRoles(ctx context.Context) ([]Role, error)
|
||||
ListRooms(ctx context.Context) ([]Room, error)
|
||||
ListShelves(ctx context.Context) ([]Shelf, 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)
|
||||
UpdateShelve(ctx context.Context, arg UpdateShelveParams) (Shelf, error)
|
||||
UpdateWarehouse(ctx context.Context, arg UpdateWarehouseParams) (Warehouse, error)
|
||||
}
|
||||
|
||||
|
||||
159
sqlc_gen/shelve.sql.go
Normal file
159
sqlc_gen/shelve.sql.go
Normal file
@@ -0,0 +1,159 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.30.0
|
||||
// source: shelve.sql
|
||||
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const createShelve = `-- name: CreateShelve :one
|
||||
INSERT INTO shelves (cabinet_id,name,level_index, description, created_at)
|
||||
VALUES (
|
||||
$1,
|
||||
$2,
|
||||
$3,
|
||||
$4,
|
||||
$5
|
||||
)
|
||||
RETURNING id, cabinet_id, name, level_index, description, created_at, updated_at
|
||||
`
|
||||
|
||||
type CreateShelveParams struct {
|
||||
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"`
|
||||
}
|
||||
|
||||
func (q *Queries) CreateShelve(ctx context.Context, arg CreateShelveParams) (Shelf, error) {
|
||||
row := q.db.QueryRow(ctx, createShelve,
|
||||
arg.CabinetID,
|
||||
arg.Name,
|
||||
arg.LevelIndex,
|
||||
arg.Description,
|
||||
arg.CreatedAt,
|
||||
)
|
||||
var i Shelf
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CabinetID,
|
||||
&i.Name,
|
||||
&i.LevelIndex,
|
||||
&i.Description,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteShelve = `-- name: DeleteShelve :execrows
|
||||
DELETE FROM shelves
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteShelve(ctx context.Context, id int64) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, deleteShelve, id)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const getShelveByID = `-- name: GetShelveByID :one
|
||||
SELECT id, cabinet_id, name, level_index, description, created_at, updated_at FROM shelves
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetShelveByID(ctx context.Context, id int64) (Shelf, error) {
|
||||
row := q.db.QueryRow(ctx, getShelveByID, id)
|
||||
var i Shelf
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CabinetID,
|
||||
&i.Name,
|
||||
&i.LevelIndex,
|
||||
&i.Description,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const listShelves = `-- name: ListShelves :many
|
||||
SELECT id, cabinet_id, name, level_index, description, created_at, updated_at FROM shelves
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
func (q *Queries) ListShelves(ctx context.Context) ([]Shelf, error) {
|
||||
rows, err := q.db.Query(ctx, listShelves)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Shelf
|
||||
for rows.Next() {
|
||||
var i Shelf
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.CabinetID,
|
||||
&i.Name,
|
||||
&i.LevelIndex,
|
||||
&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 updateShelve = `-- name: UpdateShelve :one
|
||||
UPDATE shelves
|
||||
SET name = CASE WHEN $1 = '' THEN name ELSE $1 END,
|
||||
level_index = CASE WHEN $2 = 0 THEN level_index ELSE $2 END,
|
||||
description = coalesce($3, description),
|
||||
updated_at = $4
|
||||
WHERE id = $5
|
||||
RETURNING id, cabinet_id, name, level_index, description, created_at, updated_at
|
||||
`
|
||||
|
||||
type UpdateShelveParams struct {
|
||||
Name interface{} `db:"name" json:"name"`
|
||||
LevelIndex interface{} `db:"level_index" json:"levelIndex"`
|
||||
Description pgtype.Text `db:"description" json:"description"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updatedAt"`
|
||||
ID int64 `db:"id" json:"id"`
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateShelve(ctx context.Context, arg UpdateShelveParams) (Shelf, error) {
|
||||
row := q.db.QueryRow(ctx, updateShelve,
|
||||
arg.Name,
|
||||
arg.LevelIndex,
|
||||
arg.Description,
|
||||
arg.UpdatedAt,
|
||||
arg.ID,
|
||||
)
|
||||
var i Shelf
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CabinetID,
|
||||
&i.Name,
|
||||
&i.LevelIndex,
|
||||
&i.Description,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
Reference in New Issue
Block a user