commit 6b319947d4ffa38e70529fd9f909c722aca88293
parent c6b2d45de31f0cb1a4a56b7b085a072f149bdb4c
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Sat, 21 Sep 2024 11:21:29 -0700
Add door swing information to pointmaps
The door swing parameter is a string with the first character being
either 'a' or 'b' saying what point the hinge is on followed by a
plus ('+') or minus ('-') saying whether to swing positively or
negatively (such as +90 degrees or -90 degrees).
Diffstat:
2 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/cmd/api/migration/2024-09-19T19:22:03.sql b/cmd/api/migration/2024-09-19T19:22:03.sql
@@ -0,0 +1,7 @@
+BEGIN;
+
+ALTER TABLE spaceplanner.floorplan_pointmaps ADD COLUMN door_swing varchar;
+ALTER TABLE spaceplanner.floorplan_pointmaps ADD CONSTRAINT check_door_swing
+ CHECK (door_swing = 'a+' OR door_swing = 'a-' OR door_swing = 'b+' OR door_swing = 'b-');
+
+END;
diff --git a/internal/backend/floorplan_data.go b/internal/backend/floorplan_data.go
@@ -39,6 +39,7 @@ type PointMap struct {
Type string `json:"type" binding:"required"`
A ObjectID `json:"a" binding:"required"`
B ObjectID `json:"b" binding:"required"`
+ DoorSwing *string `json:"door_swing,omitempty"`
}
// NOTE: I'd like to allow every value to be omitted so
@@ -227,7 +228,7 @@ func (e *Env) getFloorplanPoints(tx *sql.Tx, user string, floorplan string) (map
func (e *Env) getFloorplanPointMaps(tx *sql.Tx, user string, floorplan string) (map[ObjectID]PointMap, error) {
stmt, err := e.CacheTxStmt(tx, "get_pointmaps",
- `SELECT id, type, a, b FROM spaceplanner.floorplan_pointmaps WHERE
+ `SELECT id, type, a, b, door_swing FROM spaceplanner.floorplan_pointmaps WHERE
floorplan = spaceplanner.floorplan_id($1, $2)`)
if err != nil {
return nil, err
@@ -563,26 +564,26 @@ func (e *Env) DeletePoint(tx *sql.Tx, user string, floorplan string, id ObjectID
func (pm PointMap) Create(e *Env, tx *sql.Tx, user string, floorplan string) (DBObject, error) {
stmt, err := e.CacheTxStmt(tx, "add_pointmap",
- `INSERT INTO spaceplanner.floorplan_pointmaps (floorplan, type, a, b) VALUES (
- floorplan_id($1, $2), $3, $4, $5
- ) RETURNING id, type, a, b`)
+ `INSERT INTO spaceplanner.floorplan_pointmaps (floorplan, type, a, b, door_swing) VALUES (
+ floorplan_id($1, $2), $3, $4, $5, $6
+ ) RETURNING id, type, a, b, door_swing`)
if err != nil {
return PointMap{}, err
}
- return scanPointMap(stmt.QueryRow(user, floorplan, pm.Type, pm.A.Seq, pm.B.Seq))
+ return scanPointMap(stmt.QueryRow(user, floorplan, pm.Type, pm.A.Seq, pm.B.Seq, pm.DoorSwing))
}
func (pm PointMap) Update(e *Env, tx *sql.Tx, user string, floorplan string) (DBObject, error) {
stmt, err := e.CacheTxStmt(tx, "repl_pointmap",
- `UPDATE spaceplanner.floorplan_pointmaps SET (type, a, b) =
- ($4, $5, $6) WHERE floorplan = floorplan_id($1, $2) AND id = $3
- RETURNING id, type, a, b`)
+ `UPDATE spaceplanner.floorplan_pointmaps SET (type, a, b, door_swing) =
+ ($4, $5, $6, $7) WHERE floorplan = floorplan_id($1, $2) AND id = $3
+ RETURNING id, type, a, b, door_swing`)
if err != nil {
return PointMap{}, err
}
- return scanPointMap(stmt.QueryRow(user, floorplan, pm.id.Seq, pm.Type, pm.A.Seq, pm.B.Seq))
+ return scanPointMap(stmt.QueryRow(user, floorplan, pm.id.Seq, pm.Type, pm.A.Seq, pm.B.Seq, pm.DoorSwing))
}
func (pm PointMap) Delete(e *Env, tx *sql.Tx, user, floorplan string) (DBObject, error) {
@@ -593,7 +594,7 @@ func (e *Env) DeletePointMap(tx *sql.Tx, user string, floorplan string, id Objec
stmt, err := e.CacheTxStmt(tx, "dele_pointmap",
`DELETE FROM spaceplanner.floorplan_pointmaps
WHERE floorplan = floorplan_id($1, $2) AND id = $3
- RETURNING id, type, a, b`)
+ RETURNING id, type, a, b, door_swing`)
if err != nil {
return PointMap{}, err
}
@@ -840,7 +841,7 @@ func scanPointMap(s Scanner) (PointMap, error) {
var pm PointMap
var id, a, b int64
- err := s.Scan(&id, &pm.Type, &a, &b)
+ err := s.Scan(&id, &pm.Type, &a, &b, &pm.DoorSwing)
if err != nil {
return pm, err
}