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

  1. package models
  2. import "time"
  3. type Item struct {
  4. ID int `json:"id"`
  5. ScopeID int `json:"scopeId"`
  6. OwnerID string `json:"-"`
  7. ProjectID *int `json:"projectId,omitempty"`
  8. ProjectRequirementID *int `json:"projectRequirementId,omitempty"`
  9. Name string `json:"name"`
  10. Description string `json:"description"`
  11. CreatedTime time.Time `json:"createdTime"`
  12. AcquiredTime *time.Time `json:"acquiredTime"`
  13. ScheduledDate *Date `json:"scheduledDate"`
  14. Stats []StatProgressEntry `json:"stats,omitempty"`
  15. }
  16. func (item *Item) ApplyUpdate(update ItemUpdate) {
  17. if update.ProjectRequirementID != nil {
  18. item.ProjectRequirementID = update.ProjectRequirementID
  19. }
  20. if update.OwnerID != nil {
  21. item.OwnerID = *update.OwnerID
  22. }
  23. if update.Name != nil {
  24. item.Name = *update.Name
  25. }
  26. if update.Description != nil {
  27. item.Description = *update.Description
  28. }
  29. if update.AcquiredTime != nil {
  30. item.AcquiredTime = update.AcquiredTime
  31. }
  32. if update.ScheduledDate != nil {
  33. item.ScheduledDate = update.ScheduledDate
  34. }
  35. if update.ClearScheduledDate {
  36. item.ScheduledDate = nil
  37. }
  38. if update.ClearProjectRequirementID {
  39. item.ProjectRequirementID = nil
  40. }
  41. if update.ClearAcquiredTime {
  42. item.AcquiredTime = nil
  43. }
  44. deleteList := make([]int, 0, len(update.Stats))
  45. for i, stat := range update.Stats {
  46. if stat.Acquired == 0 && stat.Required == 0 {
  47. deleteList = append(deleteList, i-len(deleteList))
  48. }
  49. found := false
  50. for j := range item.Stats {
  51. if item.Stats[j].ID == stat.ID {
  52. item.Stats[j].Required = stat.Required
  53. item.Stats[j].Acquired = stat.Acquired
  54. found = true
  55. break
  56. }
  57. }
  58. if !found {
  59. item.Stats = append(item.Stats, stat)
  60. }
  61. }
  62. }
  63. type ItemUpdate struct {
  64. ProjectRequirementID *int `json:"projectRequirementId"`
  65. OwnerID *string `json:"ownerId"`
  66. Name *string `json:"name"`
  67. Description *string `json:"description"`
  68. AcquiredTime *time.Time `json:"acquiredTime"`
  69. ScheduledDate *Date `json:"scheduledDate"`
  70. Stats []StatProgressEntry `json:"stats"`
  71. ClearProjectRequirementID bool `json:"clearProjectRequirementId"`
  72. ClearAcquiredTime bool `json:"clearAcquiredTime"`
  73. ClearScheduledDate bool `json:"clearScheduledDate"`
  74. }