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. 10
      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

10
services/loader.go

@ -208,7 +208,7 @@ 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), UserID: auth.UserID(ctx),
IDs: taskIDs,
TaskIDs: taskIDs,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
@ -271,7 +271,7 @@ 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), UserID: auth.UserID(ctx),
IDs: taskIDs,
TaskIDs: taskIDs,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
@ -332,7 +332,7 @@ func (l *Loader) FindTask(ctx context.Context, id string) (*models.TaskResult, e
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, UserID: task.UserID,
IDs: []string{task.ID},
TaskIDs: []string{task.ID},
}) })
if err != nil { if err != nil {
return nil, err return nil, err
@ -364,7 +364,7 @@ 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), UserID: auth.UserID(ctx),
IDs: taskIDs,
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