api.spaceplanner.app

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

commit c6b2d45de31f0cb1a4a56b7b085a072f149bdb4c
parent 45a6cafb9356db7c62a31ed5c26431c88058a81e
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Wed, 18 Sep 2024 12:37:51 -0700

Fix backend's DeleteFloorplanData

Before only points (and pointmaps by cascade) were deleted, now
furniture and furniture maps are deleted aswell.

Also remove some old debug logging

Diffstat:
Minternal/backend/floorplan_data.go | 39+++++++++++++++++++++++++++++++++------
1 file changed, 33 insertions(+), 6 deletions(-)

diff --git a/internal/backend/floorplan_data.go b/internal/backend/floorplan_data.go @@ -9,8 +9,6 @@ import ( "strings" ) -import "log" - type FloorplanData struct { Points map[ObjectID]Point `json:"points"` Pointmaps map[ObjectID]PointMap `json:"pointmaps"` @@ -347,15 +345,45 @@ func (e *Env) ReplaceFloorplanData(tx *sql.Tx, user string, floorplan string, da } func (e *Env) DeleteFloorplanData(tx *sql.Tx, user string, floorplan string) error { - stmt, err := e.CacheTxStmt(tx, "del_floorplan_data", + var mytx bool + + if tx == nil { + mytx = true + var err error + tx, err = e.DB.Begin() + if err != nil { + return err + } + defer tx.Rollback() + } + + delPnt, err := e.CacheTxStmt(tx, "del_floorplan_pnt", `DELETE FROM spaceplanner.floorplan_points WHERE floorplan = spaceplanner.floorplan_id($1, $2)`) if err != nil { return err } - _, err = stmt.Exec(user, floorplan) - return err + delFur, err := e.CacheTxStmt(tx, "del_floorplan_fur", + `DELETE FROM spaceplanner.furniture + WHERE floorplan = spaceplanner.floorplan_id($1, $2)`) + if err != nil { + return err + } + + _, err = delPnt.Exec(user, floorplan) + if err != nil { + return err + } + _, err = delFur.Exec(user, floorplan) + if err != nil { + return err + } + + if (mytx) { + return tx.Commit() + } + return nil } func (e *Env) PatchFloorplanData(tx *sql.Tx, user string, floorplan string, patches []Patch) (FloorplanData, error) { @@ -457,7 +485,6 @@ func applyPatch[T DBObject](e *Env, tx *sql.Tx, user, floorplan string, patch *P // can't figure it out right now. I'll come back to it later // but for now a few type assertions thing = thing.updateIDs(id, newIDs).(T) - log.Print(patch, thing) var err error var dbo DBObject