From c92cdb427d050456769f520cdcc4ee10db895ad9 Mon Sep 17 00:00:00 2001 From: Mo Tarbin Date: Sat, 6 Jul 2024 03:26:11 -0400 Subject: Add GetChoreHistoryWithLimit method to ChoreRepository --- internal/chore/repo/repository.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 -- cgit