aboutsummaryrefslogtreecommitdiffstats
path: root/internal/chore/repo
diff options
context:
space:
mode:
authorLibravatar Mo Tarbin <mhed.t91@gmail.com>2024-07-20 03:42:38 -0400
committerLibravatar Mo Tarbin <mhed.t91@gmail.com>2024-07-20 03:42:38 -0400
commitee7a8e24da1dfc959d78236a63ee65acc4be45e4 (patch)
tree5feccf155c39b67606b2de831e5d903d9389e1af /internal/chore/repo
parent861a1666e48a91d43db6d1fd272dac832013f5b7 (diff)
downloaddonetick-ee7a8e24da1dfc959d78236a63ee65acc4be45e4.tar.gz
donetick-ee7a8e24da1dfc959d78236a63ee65acc4be45e4.tar.bz2
donetick-ee7a8e24da1dfc959d78236a63ee65acc4be45e4.zip
Update ChoreHistory model to include updatedAt field, Support history modification
Diffstat (limited to 'internal/chore/repo')
-rw-r--r--internal/chore/repo/repository.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/internal/chore/repo/repository.go b/internal/chore/repo/repository.go
index 7284202..e7035d5 100644
--- a/internal/chore/repo/repository.go
+++ b/internal/chore/repo/repository.go
@@ -73,7 +73,7 @@ func (r *ChoreRepository) IsChoreOwner(c context.Context, choreID int, userID in
// return chores, nil
// }
-func (r *ChoreRepository) CompleteChore(c context.Context, chore *chModel.Chore, note *string, userID int, dueDate *time.Time, completedDate time.Time, nextAssignedTo int) error {
+func (r *ChoreRepository) CompleteChore(c context.Context, chore *chModel.Chore, note *string, userID int, dueDate *time.Time, completedDate *time.Time, nextAssignedTo int) error {
err := r.db.WithContext(c).Transaction(func(tx *gorm.DB) error {
ch := &chModel.ChoreHistory{
ChoreID: chore.ID,
@@ -119,6 +119,22 @@ func (r *ChoreRepository) GetChoreHistoryWithLimit(c context.Context, choreID in
return histories, nil
}
+func (r *ChoreRepository) GetChoreHistoryByID(c context.Context, choreID int, historyID int) (*chModel.ChoreHistory, error) {
+ var history chModel.ChoreHistory
+ if err := r.db.WithContext(c).Where("id = ? and chore_id = ? ", historyID, choreID).First(&history).Error; err != nil {
+ return nil, err
+ }
+ return &history, nil
+}
+
+func (r *ChoreRepository) UpdateChoreHistory(c context.Context, history *chModel.ChoreHistory) error {
+ return r.db.WithContext(c).Save(history).Error
+}
+
+func (r *ChoreRepository) DeleteChoreHistory(c context.Context, historyID int) error {
+ return r.db.WithContext(c).Delete(&chModel.ChoreHistory{}, historyID).Error
+}
+
func (r *ChoreRepository) UpdateChoreAssignees(c context.Context, assignees []*chModel.ChoreAssignees) error {
return r.db.WithContext(c).Save(&assignees).Error
}