Add description field to ChoreDetail model and repository methods
This commit is contained in:
parent
12cdfe8bf9
commit
9296d6e1b8
2 changed files with 18 additions and 3 deletions
|
@ -120,6 +120,7 @@ type Tag struct {
|
||||||
type ChoreDetail struct {
|
type ChoreDetail struct {
|
||||||
ID int `json:"id" gorm:"column:id"`
|
ID int `json:"id" gorm:"column:id"`
|
||||||
Name string `json:"name" gorm:"column:name"`
|
Name string `json:"name" gorm:"column:name"`
|
||||||
|
Description *string `json:"description" gorm:"column:description"`
|
||||||
FrequencyType string `json:"frequencyType" gorm:"column:frequency_type"`
|
FrequencyType string `json:"frequencyType" gorm:"column:frequency_type"`
|
||||||
NextDueDate *time.Time `json:"nextDueDate" gorm:"column:next_due_date"`
|
NextDueDate *time.Time `json:"nextDueDate" gorm:"column:next_due_date"`
|
||||||
AssignedTo int `json:"assignedTo" gorm:"column:assigned_to"`
|
AssignedTo int `json:"assignedTo" gorm:"column:assigned_to"`
|
||||||
|
|
|
@ -70,8 +70,18 @@ func (r *ChoreRepository) GetArchivedChores(c context.Context, circleID int, use
|
||||||
return chores, nil
|
return chores, nil
|
||||||
}
|
}
|
||||||
func (r *ChoreRepository) DeleteChore(c context.Context, id int) error {
|
func (r *ChoreRepository) DeleteChore(c context.Context, id int) error {
|
||||||
r.db.WithContext(c).Where("chore_id = ?", id).Delete(&chModel.ChoreAssignees{})
|
return r.db.WithContext(c).Transaction(func(tx *gorm.DB) error {
|
||||||
return r.db.WithContext(c).Delete(&chModel.Chore{}, id).Error
|
if err := tx.Where("chore_id = ?", id).Delete(&chModel.ChoreAssignees{}).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := tx.Delete(&chModel.ChoreHistory{}, "chore_id = ?", id).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := tx.Delete(&chModel.Chore{}, id).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ChoreRepository) SoftDelete(c context.Context, id int, userID int) error {
|
func (r *ChoreRepository) SoftDelete(c context.Context, id int, userID int) error {
|
||||||
|
@ -154,6 +164,9 @@ func (r *ChoreRepository) UpdateChoreHistory(c context.Context, history *chModel
|
||||||
func (r *ChoreRepository) DeleteChoreHistory(c context.Context, historyID int) error {
|
func (r *ChoreRepository) DeleteChoreHistory(c context.Context, historyID int) error {
|
||||||
return r.db.WithContext(c).Delete(&chModel.ChoreHistory{}, historyID).Error
|
return r.db.WithContext(c).Delete(&chModel.ChoreHistory{}, historyID).Error
|
||||||
}
|
}
|
||||||
|
func (r *ChoreRepository) DeleteChoreHistoryByChoreID(c context.Context, tx, choreID int) error {
|
||||||
|
return r.db.WithContext(c).Delete(&chModel.ChoreHistory{}, "chore_id = ?", choreID).Error
|
||||||
|
}
|
||||||
|
|
||||||
func (r *ChoreRepository) UpdateChoreAssignees(c context.Context, assignees []*chModel.ChoreAssignees) error {
|
func (r *ChoreRepository) UpdateChoreAssignees(c context.Context, assignees []*chModel.ChoreAssignees) error {
|
||||||
return r.db.WithContext(c).Save(&assignees).Error
|
return r.db.WithContext(c).Save(&assignees).Error
|
||||||
|
@ -265,6 +278,7 @@ func (r *ChoreRepository) GetChoreDetailByID(c context.Context, choreID int, cir
|
||||||
Select(`
|
Select(`
|
||||||
chores.id,
|
chores.id,
|
||||||
chores.name,
|
chores.name,
|
||||||
|
chores.description,
|
||||||
chores.frequency_type,
|
chores.frequency_type,
|
||||||
chores.next_due_date,
|
chores.next_due_date,
|
||||||
chores.assigned_to,
|
chores.assigned_to,
|
||||||
|
|
Loading…
Add table
Reference in a new issue