Dissociate chore with thing in deleteChore function

This commit is contained in:
Mo Tarbin 2024-07-02 01:39:46 -04:00
parent 17326a16a0
commit e40c2a84cd
2 changed files with 6 additions and 0 deletions

View File

@ -562,6 +562,8 @@ func (h *Handler) deleteChore(c *gin.Context) {
return return
} }
h.nRepo.DeleteAllChoreNotifications(id) h.nRepo.DeleteAllChoreNotifications(id)
h.tRepo.DissociateChoreWithThing(c, id)
c.JSON(200, gin.H{ c.JSON(200, gin.H{
"message": "Chore deleted successfully", "message": "Chore deleted successfully",
}) })

View File

@ -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 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) { func (r *ThingRepository) GetThingHistoryWithOffset(c context.Context, thingID int, offset int) ([]*tModel.ThingHistory, error) {
var thingHistory []*tModel.ThingHistory 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 { 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 {