api.spaceplanner.app

Spaceplanner API
git clone git://jacobedwards.org/api.spaceplanner.app
Log | Files | Refs

commit 212fd61942353bc63f6f1274e080eb3b2db33e7a
parent 97f348a807f72351b26d09b30c378eb7e8f75426
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Mon, 21 Oct 2024 08:23:57 -0700

Add UserType field to furniture definitions

There aren't going to be that many furniture types, so this allows
the true type to be documented separate from the name field

Diffstat:
Acmd/api/migration/2024-10-21T15:11:30.sql | 2++
Minternal/backend/floorplan_data.go | 23++++++++++++-----------
2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/cmd/api/migration/2024-10-21T15:11:30.sql b/cmd/api/migration/2024-10-21T15:11:30.sql @@ -0,0 +1,2 @@ +ALTER TABLE spaceplanner.furniture + ADD COLUMN user_type varchar ; diff --git a/internal/backend/floorplan_data.go b/internal/backend/floorplan_data.go @@ -48,6 +48,7 @@ type Furniture struct { id ObjectID OldID *ObjectID `json:"old_id,omitempty"` Type string `json:"type" binding:"required"` + UserType *string `json:"user_type,omitempty"` Style *string `json:"style,omitempty"` Name *string `json:"name"` Width int `json:"width" binding:"required"` @@ -302,7 +303,7 @@ func (e *Env) getFloorplanPointMaps(tx *sql.Tx, floorplan ObjectID) (map[ObjectI func (e *Env) getFloorplanFurnitureDefs(tx *sql.Tx, floorplan ObjectID) (map[ObjectID]Furniture, error) { defsStmt, err := e.CacheTxStmt(tx, "furniture_defs", - `SELECT id, type, style, name, width, depth + `SELECT id, type, user_type, style, name, width, depth FROM spaceplanner.furniture WHERE floorplan = $1`) if err != nil { @@ -703,33 +704,33 @@ func (e *Env) DeletePointMap(tx *sql.Tx, floorplan, id ObjectID) (PointMap, erro func (f Furniture) Create(e *Env, tx *sql.Tx, floorplan ObjectID) (DBObject, error) { ins, err := e.CacheTxStmt(tx, "add_furn", - `INSERT INTO spaceplanner.furniture (floorplan, type, style, name, width, depth) - VALUES ($1, $2, $3, $4, $5, $6) - RETURNING id, type, style, name, width, depth`) + `INSERT INTO spaceplanner.furniture (floorplan, type, user_type, style, name, width, depth) + VALUES ($1, $2, $3, $4, $5, $6, $7) + RETURNING id, type, user_type, style, name, width, depth`) if err != nil { return f, err } - return scanFurniture(ins.QueryRow(floorplan.Seq, f.Type, f.Style, f.Name, f.Width, f.Depth)) + return scanFurniture(ins.QueryRow(floorplan.Seq, f.Type, f.UserType, f.Style, f.Name, f.Width, f.Depth)) } func (f Furniture) Update(e *Env, tx *sql.Tx, floorplan ObjectID) (DBObject, error) { update, err := e.CacheTxStmt(tx, "update_furn", - `UPDATE spaceplanner.furniture SET (type, style, name, width, depth) = - ($3, $4, $5, $6, $7) WHERE floorplan = $1 AND id = $2 - RETURNING id, type, style, name, width, depth`) + `UPDATE spaceplanner.furniture SET (type, user_type, style, name, width, depth) = + ($3, $4, $5, $6, $7, $8) WHERE floorplan = $1 AND id = $2 + RETURNING id, type, user_type, style, name, width, depth`) if err != nil { return f, err } - return scanFurniture(update.QueryRow(floorplan.Seq, f.id.Seq, f.Type, f.Style, f.Name, f.Width, f.Depth)) + return scanFurniture(update.QueryRow(floorplan.Seq, f.id.Seq, f.Type, f.UserType, f.Style, f.Name, f.Width, f.Depth)) } func (f Furniture) Delete(e *Env, tx *sql.Tx, floorplan ObjectID) (DBObject, error) { del, err := e.CacheTxStmt(tx, "dele_furn", `DELETE FROM spaceplanner.furniture WHERE floorplan = $1 AND id = $2 - RETURNING id, type, style, name, width, depth`) + RETURNING id, type, user_type, style, name, width, depth`) if err != nil { return f, err } @@ -936,7 +937,7 @@ func scanFurniture(row Scanner) (Furniture, error) { var f Furniture var id int64 - err := row.Scan(&id, &f.Type, &f.Style, &f.Name, &f.Width, &f.Depth) + err := row.Scan(&id, &f.Type, &f.UserType, &f.Style, &f.Name, &f.Width, &f.Depth) if err != nil { return f, err }