This commit is contained in:
+43
-15
@@ -128,6 +128,9 @@ func (l *Loader) FindLog(ctx context.Context, id string) (*models.LogResult, err
|
||||
|
||||
result.Task, _ = l.DB.Tasks().Find(ctx, id)
|
||||
result.Item, _ = l.DB.Items().Find(ctx, log.ItemID)
|
||||
if log.SecondaryItemID != nil {
|
||||
result.SecondaryItem, _ = l.DB.Items().Find(ctx, *log.SecondaryItemID)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
@@ -144,6 +147,9 @@ func (l *Loader) ListLogs(ctx context.Context, filter models.LogFilter) ([]*mode
|
||||
for _, log := range logs {
|
||||
taskIDs.Add(log.TaskID)
|
||||
itemIDs.Add(log.ItemID)
|
||||
if log.SecondaryItemID != nil {
|
||||
itemIDs.Add(*log.SecondaryItemID)
|
||||
}
|
||||
}
|
||||
tasks, err := l.DB.Tasks().List(ctx, models.TaskFilter{
|
||||
UserID: auth.UserID(ctx),
|
||||
@@ -177,7 +183,9 @@ func (l *Loader) ListLogs(ctx context.Context, filter models.LogFilter) ([]*mode
|
||||
for _, item := range items {
|
||||
if item.ID == log.ItemID {
|
||||
results[i].Item = item
|
||||
break
|
||||
}
|
||||
if log.SecondaryItemID != nil && item.ID == *log.SecondaryItemID {
|
||||
results[i].SecondaryItem = item
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -502,16 +510,22 @@ func (l *Loader) populateGoals(ctx context.Context, goal *models.Goal) (*models.
|
||||
MinTime: &goal.StartTime,
|
||||
MaxTime: &goal.EndTime,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Get tasks
|
||||
taskIDs := make([]string, 0, len(result.Logs))
|
||||
taskIDs := stringset.New()
|
||||
for _, log := range logs {
|
||||
taskIDs = append(taskIDs, log.TaskID)
|
||||
taskIDs.Add(log.TaskID)
|
||||
}
|
||||
tasks, err := l.DB.Tasks().List(ctx, models.TaskFilter{
|
||||
UserID: userID,
|
||||
IDs: taskIDs,
|
||||
IDs: taskIDs.Strings(),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Apply logs
|
||||
result.Logs = make([]*models.LogResult, 0, len(logs))
|
||||
@@ -523,20 +537,34 @@ func (l *Loader) populateGoals(ctx context.Context, goal *models.Goal) (*models.
|
||||
for _, task := range tasks {
|
||||
if task.ID == log.TaskID {
|
||||
resultLog.Task = task
|
||||
|
||||
for _, item := range result.Items {
|
||||
if task.ItemID == item.ID {
|
||||
item.CompletedAmount += 1
|
||||
result.CompletedAmount += item.GroupWeight
|
||||
break
|
||||
}
|
||||
|
||||
resultLog.Item = &item.Item
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for _, item := range result.Items {
|
||||
amount := log.Amount(item.ID)
|
||||
if amount > 0 && (goal.ItemID == nil || *goal.ItemID == item.ID) {
|
||||
item.CompletedAmount += amount
|
||||
|
||||
if goal.Unweighted {
|
||||
result.CompletedAmount += amount
|
||||
} else {
|
||||
result.CompletedAmount += amount * item.GroupWeight
|
||||
}
|
||||
}
|
||||
|
||||
if item.ID == log.ItemID {
|
||||
resultLog.Item = &item.Item
|
||||
if log.SecondaryItemID == nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if log.SecondaryItemID != nil && item.ID == *log.SecondaryItemID {
|
||||
resultLog.SecondaryItem = &item.Item
|
||||
}
|
||||
}
|
||||
|
||||
result.Logs = append(result.Logs, resultLog)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user