Browse Source

fix tasks endpoint returning wrong values for task.logs.

main
Gisle Aune 4 years ago
parent
commit
68ad952577
  1. 4
      database/postgres/logs.go
  2. 2
      models/log.go
  3. 18
      services/loader.go

4
database/postgres/logs.go

@ -30,8 +30,8 @@ func (r *logRepository) Find(ctx context.Context, id string) (*models.Log, error
func (r *logRepository) List(ctx context.Context, filter models.LogFilter) ([]*models.Log, error) { func (r *logRepository) List(ctx context.Context, filter models.LogFilter) ([]*models.Log, error) {
sq := squirrel.Select("log.*").From("log").PlaceholderFormat(squirrel.Dollar) sq := squirrel.Select("log.*").From("log").PlaceholderFormat(squirrel.Dollar)
sq = sq.Where(squirrel.Eq{"user_id": filter.UserID}) sq = sq.Where(squirrel.Eq{"user_id": filter.UserID})
if len(filter.IDs) > 0 {
sq = sq.Where(squirrel.Eq{"task_id": filter.IDs})
if len(filter.TaskIDs) > 0 {
sq = sq.Where(squirrel.Eq{"task_id": filter.TaskIDs})
} }
if len(filter.ItemIDs) > 0 { if len(filter.ItemIDs) > 0 {
sq = sq.Where(squirrel.Eq{"item_id": filter.ItemIDs}) sq = sq.Where(squirrel.Eq{"item_id": filter.ItemIDs})

2
models/log.go

@ -36,7 +36,7 @@ type LogResult struct {
type LogFilter struct { type LogFilter struct {
UserID string UserID string
IDs []string
TaskIDs []string
ItemIDs []string ItemIDs []string
MinTime *time.Time MinTime *time.Time
MaxTime *time.Time MaxTime *time.Time

18
services/loader.go

@ -207,8 +207,8 @@ func (l *Loader) FindProject(ctx context.Context, id string) (*models.ProjectRes
} }
logs, err := l.DB.Logs().List(ctx, models.LogFilter{ logs, err := l.DB.Logs().List(ctx, models.LogFilter{
UserID: auth.UserID(ctx),
IDs: taskIDs,
UserID: auth.UserID(ctx),
TaskIDs: taskIDs,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
@ -270,8 +270,8 @@ func (l *Loader) ListProjects(ctx context.Context, filter models.ProjectFilter)
} }
logs, err := l.DB.Logs().List(ctx, models.LogFilter{ logs, err := l.DB.Logs().List(ctx, models.LogFilter{
UserID: auth.UserID(ctx),
IDs: taskIDs,
UserID: auth.UserID(ctx),
TaskIDs: taskIDs,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
@ -331,8 +331,8 @@ func (l *Loader) FindTask(ctx context.Context, id string) (*models.TaskResult, e
result.Item, _ = l.DB.Items().Find(ctx, task.ItemID) result.Item, _ = l.DB.Items().Find(ctx, task.ItemID)
result.Project, _ = l.DB.Projects().Find(ctx, task.ProjectID) result.Project, _ = l.DB.Projects().Find(ctx, task.ProjectID)
result.Logs, err = l.DB.Logs().List(ctx, models.LogFilter{ result.Logs, err = l.DB.Logs().List(ctx, models.LogFilter{
UserID: task.UserID,
IDs: []string{task.ID},
UserID: task.UserID,
TaskIDs: []string{task.ID},
}) })
if err != nil { if err != nil {
return nil, err return nil, err
@ -363,8 +363,8 @@ func (l *Loader) ListTasks(ctx context.Context, filter models.TaskFilter) ([]*mo
} }
logs, err := l.DB.Logs().List(ctx, models.LogFilter{ logs, err := l.DB.Logs().List(ctx, models.LogFilter{
UserID: auth.UserID(ctx),
IDs: taskIDs,
UserID: auth.UserID(ctx),
TaskIDs: taskIDs,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
@ -394,7 +394,7 @@ func (l *Loader) ListTasks(ctx context.Context, filter models.TaskFilter) ([]*mo
} }
for _, log := range logs { for _, log := range logs {
if log.TaskID != task.ID {
if log.TaskID == task.ID {
result.Logs = append(result.Logs, log) result.Logs = append(result.Logs, log)
} }
} }

Loading…
Cancel
Save