mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
chore: apply filters in database query (see #335)
This commit is contained in:
@ -22,7 +22,15 @@ func NewDurationService(heartbeatService IHeartbeatService) *DurationService {
|
||||
}
|
||||
|
||||
func (srv *DurationService) Get(from, to time.Time, user *models.User, filters *models.Filters) (models.Durations, error) {
|
||||
heartbeats, err := srv.heartbeatService.GetAllWithin(from, to, user)
|
||||
get := srv.heartbeatService.GetAllWithin
|
||||
|
||||
if filters != nil && !filters.IsEmpty() {
|
||||
get = func(t1 time.Time, t2 time.Time, user *models.User) ([]*models.Heartbeat, error) {
|
||||
return srv.heartbeatService.GetAllWithinByFilters(t1, t2, user, filters)
|
||||
}
|
||||
}
|
||||
|
||||
heartbeats, err := get(from, to, user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user