aboutsummaryrefslogtreecommitdiffstats
path: root/internal/thing
diff options
context:
space:
mode:
authorLibravatar Mo Tarbin <mhed.t91@gmail.com>2024-07-02 01:40:09 -0400
committerLibravatar Mo Tarbin <mhed.t91@gmail.com>2024-07-02 01:40:09 -0400
commit6845fd54f10f9f7c2b500255af578cf5078ff3f5 (patch)
treed32f9d01dacf453740ea42707565dcdf8f3a856f /internal/thing
parente40c2a84cd93683aa7e4d98d4ada7923e32a3e33 (diff)
downloaddonetick-6845fd54f10f9f7c2b500255af578cf5078ff3f5.tar.gz
donetick-6845fd54f10f9f7c2b500255af578cf5078ff3f5.tar.bz2
donetick-6845fd54f10f9f7c2b500255af578cf5078ff3f5.zip
Add validation to deleteThing endpoint to prevent deletion of things with associated tasks
Diffstat (limited to '')
-rw-r--r--internal/thing/handler.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/internal/thing/handler.go b/internal/thing/handler.go
index 65bc871..7121c82 100644
--- a/internal/thing/handler.go
+++ b/internal/thing/handler.go
@@ -261,6 +261,16 @@ func (h *Handler) DeleteThing(c *gin.Context) {
c.JSON(403, gin.H{"error": "Forbidden"})
return
}
+ // confirm there are no chores associated with the thing:
+ thingChores, err := h.tRepo.GetThingChoresByThingId(c, thing.ID)
+ if err != nil {
+ c.JSON(500, gin.H{"error": "Unable to find tasks linked to this thing"})
+ return
+ }
+ if len(thingChores) > 0 {
+ c.JSON(405, gin.H{"error": "Unable to delete thing with associated tasks"})
+ return
+ }
if err := h.tRepo.DeleteThing(c, thingID); err != nil {
c.JSON(500, gin.H{"error": err.Error()})
return