aboutsummaryrefslogtreecommitdiffstats
path: root/internal/chore
diff options
context:
space:
mode:
authorLibravatar Mo Tarbin <mhed.t91@gmail.com>2024-07-06 03:26:11 -0400
committerLibravatar Mo Tarbin <mhed.t91@gmail.com>2024-07-06 03:26:11 -0400
commitc92cdb427d050456769f520cdcc4ee10db895ad9 (patch)
tree927a0cb18af9f4e27387609881ffd6cf5c1bbd1b /internal/chore
parent36f4717454f9da8dff013d0387882c6633662faa (diff)
downloaddonetick-c92cdb427d050456769f520cdcc4ee10db895ad9.tar.gz
donetick-c92cdb427d050456769f520cdcc4ee10db895ad9.tar.bz2
donetick-c92cdb427d050456769f520cdcc4ee10db895ad9.zip
Add GetChoreHistoryWithLimit method to ChoreRepository
Diffstat (limited to '')
-rw-r--r--internal/chore/repo/repository.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/internal/chore/repo/repository.go b/internal/chore/repo/repository.go
index 51ebb2c..4eac59c 100644
--- a/internal/chore/repo/repository.go
+++ b/internal/chore/repo/repository.go
@@ -111,6 +111,13 @@ func (r *ChoreRepository) GetChoreHistory(c context.Context, choreID int) ([]*ch
}
return histories, nil
}
+func (r *ChoreRepository) GetChoreHistoryWithLimit(c context.Context, choreID int, limit int) ([]*chModel.ChoreHistory, error) {
+ var histories []*chModel.ChoreHistory
+ if err := r.db.WithContext(c).Where("chore_id = ?", choreID).Order("completed_at desc").Limit(limit).Find(&histories).Error; err != nil {
+ return nil, err
+ }
+ return histories, nil
+}
func (r *ChoreRepository) UpdateChoreAssignees(c context.Context, assignees []*chModel.ChoreAssignees) error {
return r.db.WithContext(c).Save(&assignees).Error
@@ -243,7 +250,7 @@ func (r *ChoreRepository) GetChoreDetailByID(c context.Context, choreID int, cir
)
) AS recent_history ON chores.id = recent_history.chore_id`).
Where("chores.id = ? and chores.circle_id = ?", choreID, circleID).
- Group("chores.id, recent_history.last_completed_date").
+ Group("chores.id, recent_history.last_completed_date, recent_history.last_assigned_to").
First(&choreDetail).Error; err != nil {
return nil, err