You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

85 lines
2.4 KiB

package models
import "context"
type ProjectGroup struct {
ID string `json:"id" db:"project_group_id"`
UserID string `json:"-" db:"user_id"`
Name string `json:"name" db:"name"`
Description string `json:"description" db:"description"`
Abbreviation string `json:"abbreviation" db:"abbreviation"`
CategoryNames map[string]string `json:"categoryNames" db:"category_names"`
}
func (group *ProjectGroup) Update(update ProjectGroupUpdate) {
for key, value := range update.SetCategoryNames {
if value == "" {
delete(group.CategoryNames, key)
} else {
group.CategoryNames[key] = value
}
}
if update.Name != nil && *update.Name != "" {
group.Name = *update.Name
}
if update.Abbreviation != nil && *update.Abbreviation != "" {
group.Abbreviation = *update.Abbreviation
}
if update.Description != nil {
group.Description = *update.Description
}
}
type ProjectGroupUpdate struct {
Name *string `json:"name"`
Abbreviation *string `json:"abbreviation"`
Description *string `json:"description"`
SetCategoryNames map[string]string `json:"setCategoryNames"`
}
type ProjectGroupFilter struct {
UserID string `json:"userId"`
}
type ProjectGroupResult struct {
ProjectGroup
Projects []*ProjectResult `json:"projects"`
ProjectCounts map[string]int `json:"projectCounts"`
TaskCounts map[string]int `json:"taskCounts"`
}
func (r *ProjectGroupResult) RecountTasks() {
r.ProjectCounts = make(map[string]int)
r.TaskCounts = make(map[string]int)
r.ProjectCounts["total"] = 0
r.TaskCounts["total"] = 0
for _, project := range r.Projects {
r.ProjectCounts["total"] += 1
if project.StatusTag == nil {
r.ProjectCounts["active"] += 1
} else {
r.ProjectCounts[*project.StatusTag] += 1
}
for _, task := range project.Tasks {
r.TaskCounts["total"] += 1
if task.StatusTag == nil {
r.TaskCounts["active"] += 1
} else {
r.TaskCounts[*task.StatusTag] += 1
}
}
}
}
type ProjectGroupRepository interface {
Find(ctx context.Context, id string) (*ProjectGroup, error)
List(ctx context.Context, filter ProjectGroupFilter) ([]*ProjectGroup, error)
Insert(ctx context.Context, group ProjectGroup) error
Update(ctx context.Context, group ProjectGroup) error
Delete(ctx context.Context, group ProjectGroup) error
}