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.
 
 
 
 
 
 

85 lines
2.3 KiB

package models
import "time"
type Item struct {
ID int `json:"id"`
ScopeID int `json:"scopeId"`
OwnerID string `json:"ownerId"`
ProjectID *int `json:"projectId,omitempty"`
ProjectRequirementID *int `json:"projectRequirementId,omitempty"`
Name string `json:"name"`
Description string `json:"description"`
CreatedTime time.Time `json:"createdTime"`
AcquiredTime *time.Time `json:"acquiredTime"`
ScheduledDate *Date `json:"scheduledDate"`
Stats []StatProgressEntry `json:"stats,omitempty"`
}
func (item *Item) ApplyUpdate(update ItemUpdate) {
if update.ProjectRequirementID != nil {
item.ProjectRequirementID = update.ProjectRequirementID
}
if update.OwnerID != nil {
item.OwnerID = *update.OwnerID
}
if update.Name != nil {
item.Name = *update.Name
}
if update.Description != nil {
item.Description = *update.Description
}
if update.AcquiredTime != nil {
item.AcquiredTime = update.AcquiredTime
}
if update.ScheduledDate != nil {
item.ScheduledDate = update.ScheduledDate
}
if update.ClearScheduledDate {
item.ScheduledDate = nil
}
if update.ClearProjectRequirementID {
item.ProjectRequirementID = nil
}
if update.ClearAcquiredTime {
item.AcquiredTime = nil
}
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 item.Stats {
if item.Stats[j].ID == stat.ID {
item.Stats[j].Required = stat.Required
item.Stats[j].Acquired = stat.Acquired
found = true
break
}
}
if !found {
item.Stats = append(item.Stats, stat)
}
}
}
type ItemUpdate struct {
ProjectRequirementID *int `json:"projectRequirementId"`
OwnerID *string `json:"ownerId"`
Name *string `json:"name"`
Description *string `json:"description"`
AcquiredTime *time.Time `json:"acquiredTime"`
ScheduledDate *Date `json:"scheduledDate"`
Stats []StatProgressEntry `json:"stats"`
ClearProjectRequirementID bool `json:"clearProjectRequirementId"`
ClearAcquiredTime bool `json:"clearAcquiredTime"`
ClearScheduledDate bool `json:"clearScheduledDate"`
}