commit e57a7d8e5f29aeb05dfb075ebe02b9a83dc41d67
parent 9a907d021c37d7706c43455a870ace0a239be998
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Wed, 16 Oct 2024 20:29:35 -0700
Fix test for invalid patch type
This caused deleted objects to be returned in the floorplan data
for patch responses, which was not the desired behavior.
While perhaps not as good as using a custom type like
type PatchOp string
there are now constants for the patch operations used in the program.
In the future I may go through the trouble of adding the PatchOp
type and making the necessary tweaks and serialization methods for
it to function, but for now this will do.
Diffstat:
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/internal/backend/floorplan_data.go b/internal/backend/floorplan_data.go
@@ -506,7 +506,7 @@ func (e *Env) PatchFloorplanData(tx *sql.Tx, user string, floorplan ObjectID, pa
if err != nil {
return data, id.Error("", err)
}
- if patch.Op != "delete" {
+ if patch.Op != PatchRemove {
data.Points[point.id] = point
}
} else if (id.Type == IDTypePointMap) {
@@ -514,7 +514,7 @@ func (e *Env) PatchFloorplanData(tx *sql.Tx, user string, floorplan ObjectID, pa
if err != nil {
return data, id.Error("", err)
}
- if patch.Op != "delete" {
+ if patch.Op != PatchRemove {
data.Pointmaps[pointmap.id] = pointmap
}
} else if (id.Type == IDTypeFurniture) {
@@ -522,7 +522,7 @@ func (e *Env) PatchFloorplanData(tx *sql.Tx, user string, floorplan ObjectID, pa
if err != nil {
return data, id.Error("", err)
}
- if patch.Op != "delete" {
+ if patch.Op != PatchRemove {
data.Furniture[def.id] = def
}
} else if (id.Type == IDTypeFurnitureMap) {
@@ -530,7 +530,7 @@ func (e *Env) PatchFloorplanData(tx *sql.Tx, user string, floorplan ObjectID, pa
if err != nil {
return data, id.Error("", err)
}
- if patch.Op != "delete" {
+ if patch.Op != PatchRemove {
data.FurnitureMaps[fm.id] = fm
}
} else {
diff --git a/internal/backend/patch.go b/internal/backend/patch.go
@@ -1,5 +1,11 @@
package backend
+var (
+ PatchNew = "new"
+ PatchReplace = "replace"
+ PatchRemove = "remove"
+)
+
type Patch struct {
Op string `json:"op" binding:"required"`
Path string `json:"path" binding:"required"`