diff options
author | Mo Tarbin <mhed.t91@gmail.com> | 2024-07-07 03:02:21 -0400 |
---|---|---|
committer | Mo Tarbin <mhed.t91@gmail.com> | 2024-07-07 03:02:21 -0400 |
commit | a3fa964c585f62ccf4c4113da1dc324839122c88 (patch) | |
tree | f189f84015d8327d5d6bc7fb1b97f4362d0be2ec /internal/thing | |
parent | 17326a16a018ae84d274be53b52be9273ef69932 (diff) | |
download | donetick-a3fa964c585f62ccf4c4113da1dc324839122c88.tar.gz donetick-a3fa964c585f62ccf4c4113da1dc324839122c88.tar.bz2 donetick-a3fa964c585f62ccf4c4113da1dc324839122c88.zip |
Fix Adaptive Scheduler, Update email handlers, telegram notifications
Diffstat (limited to '')
-rw-r--r-- | internal/thing/handler.go | 10 | ||||
-rw-r--r-- | internal/thing/repo/repository.go | 4 |
2 files changed, 14 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 diff --git a/internal/thing/repo/repository.go b/internal/thing/repo/repository.go index a7b1fc9..ad5a92f 100644 --- a/internal/thing/repo/repository.go +++ b/internal/thing/repo/repository.go @@ -70,6 +70,10 @@ func (r *ThingRepository) DissociateThingWithChore(c context.Context, thingID in return r.db.WithContext(c).Where("thing_id = ? AND chore_id = ?", thingID, choreID).Delete(&tModel.ThingChore{}).Error } +func (r *ThingRepository) DissociateChoreWithThing(c context.Context, choreID int) error { + return r.db.WithContext(c).Where("chore_id = ?", choreID).Delete(&tModel.ThingChore{}).Error +} + func (r *ThingRepository) GetThingHistoryWithOffset(c context.Context, thingID int, offset int) ([]*tModel.ThingHistory, error) { var thingHistory []*tModel.ThingHistory if err := r.db.WithContext(c).Model(&tModel.ThingHistory{}).Where("thing_id = ?", thingID).Order("created_at desc").Offset(offset).Limit(10).Find(&thingHistory).Error; err != nil { |