From e40c2a84cd93683aa7e4d98d4ada7923e32a3e33 Mon Sep 17 00:00:00 2001 From: Mo Tarbin Date: Tue, 2 Jul 2024 01:39:46 -0400 Subject: Dissociate chore with thing in deleteChore function --- internal/chore/handler.go | 2 ++ internal/thing/repo/repository.go | 4 ++++ 2 files changed, 6 insertions(+) (limited to 'internal') diff --git a/internal/chore/handler.go b/internal/chore/handler.go index 3d9f9e7..919e838 100644 --- a/internal/chore/handler.go +++ b/internal/chore/handler.go @@ -562,6 +562,8 @@ func (h *Handler) deleteChore(c *gin.Context) { return } h.nRepo.DeleteAllChoreNotifications(id) + h.tRepo.DissociateChoreWithThing(c, id) + c.JSON(200, gin.H{ "message": "Chore deleted successfully", }) 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 { -- cgit