Loggest thy stuff
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.
 
 
 
 
 
 

98 lines
2.5 KiB

package models
import "time"
type ProjectEntry struct {
ID int `json:"id"`
OwnerID string `json:"ownerId,omitempty"`
CreatedTime time.Time `json:"createdTime"`
Name string `json:"name"`
Status Status `json:"status"`
}
type ProjectRequirement struct {
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Status Status `json:"status"`
Stats []StatProgressEntry `json:"stats,omitempty"`
Items []Item `json:"items,omitempty"`
}
func (requirement *ProjectRequirement) Update(update ProjectRequirementUpdate) {
if update.Name != nil {
requirement.Name = *update.Name
}
if update.Description != nil {
requirement.Description = *update.Description
}
if update.Status != nil {
requirement.Status = *update.Status
}
deleteList := make([]int, 0, len(update.Stats))
for i, stat := range update.Stats {
if stat.Acquired == 0 && stat.Required == 0 {
deleteList = append(deleteList, i-len(deleteList))
}
found := false
for j := range requirement.Stats {
if requirement.Stats[j].ID == stat.ID {
requirement.Stats[j].Required = stat.Required
requirement.Stats[j].Acquired = stat.Acquired
found = true
break
}
}
if !found {
requirement.Stats = append(requirement.Stats, stat)
}
}
}
type ProjectRequirementUpdate struct {
Name *string `json:"name"`
Description *string `json:"description"`
Status *Status `json:"status"`
Stats []StatProgressEntry `json:"stats"`
}
type Project struct {
ProjectEntry
Description string `json:"description"`
Requirements []ProjectRequirement `json:"requirements"`
}
func (project *Project) Update(update ProjectUpdate) {
if update.OwnerID != nil {
project.OwnerID = *update.OwnerID
}
if update.Name != nil {
project.Name = *update.Name
}
if update.Description != nil {
project.Description = *update.Description
}
if update.Status != nil {
project.Status = *update.Status
}
}
func (project *Project) Requirement(id int) *ProjectRequirement {
for i, requirement := range project.Requirements {
if requirement.ID == id {
return &project.Requirements[i]
}
}
return nil
}
type ProjectUpdate struct {
Name *string `json:"name,omitempty"`
OwnerID *string `json:"ownerId,omitempty"`
Status *Status `json:"status,omitempty"`
Description *string `json:"description,omitempty"`
}