add project groups to backend.
This commit is contained in:
@@ -373,6 +373,89 @@ func (l *Loader) ListProjects(ctx context.Context, filter models.ProjectFilter)
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (l *Loader) FindProjectGroup(ctx context.Context, id string) (*models.ProjectGroupResult, error) {
|
||||
group, err := l.DB.ProjectGroups().Find(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
projects, err := l.ListProjects(ctx, models.ProjectFilter{
|
||||
UserID: auth.UserID(ctx),
|
||||
ProjectGroupIDs: []string{group.ID},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := &models.ProjectGroupResult{
|
||||
ProjectGroup: *group,
|
||||
Projects: projects,
|
||||
}
|
||||
result.RecountTasks()
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (l *Loader) ListProjectGroups(ctx context.Context) ([]*models.ProjectGroupResult, error) {
|
||||
groups, err := l.DB.ProjectGroups().List(ctx, models.ProjectGroupFilter{UserID: auth.UserID(ctx)})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ids := make([]string, 0, len(groups))
|
||||
for _, group := range groups {
|
||||
ids = append(ids, group.ID)
|
||||
}
|
||||
|
||||
projects, err := l.ListProjects(ctx, models.ProjectFilter{
|
||||
UserID: auth.UserID(ctx),
|
||||
ProjectGroupIDs: ids,
|
||||
})
|
||||
|
||||
results := make([]*models.ProjectGroupResult, 0, len(groups)+1)
|
||||
|
||||
for _, group := range groups {
|
||||
matchingProjects := make([]*models.ProjectResult, 0, len(projects)/len(groups))
|
||||
for _, project := range projects {
|
||||
if *project.GroupID == group.ID {
|
||||
matchingProjects = append(matchingProjects, project)
|
||||
}
|
||||
}
|
||||
|
||||
result := &models.ProjectGroupResult{
|
||||
ProjectGroup: *group,
|
||||
Projects: matchingProjects,
|
||||
}
|
||||
result.RecountTasks()
|
||||
|
||||
results = append(results, result)
|
||||
}
|
||||
|
||||
ungroupedProjects, err := l.ListProjects(ctx, models.ProjectFilter{
|
||||
UserID: auth.UserID(ctx),
|
||||
Ungrouped: true,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(ungroupedProjects) > 0 {
|
||||
result := &models.ProjectGroupResult{
|
||||
ProjectGroup: models.ProjectGroup{
|
||||
ID: "META_UNGROUPED",
|
||||
Name: "Ungrouped",
|
||||
Abbreviation: "OTHER",
|
||||
CategoryNames: map[string]string{},
|
||||
},
|
||||
Projects: ungroupedProjects,
|
||||
}
|
||||
result.RecountTasks()
|
||||
|
||||
results = append(results, result)
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (l *Loader) FindTask(ctx context.Context, id string) (*models.TaskResult, error) {
|
||||
task, err := l.DB.Tasks().Find(ctx, id)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user