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

3 years ago
  1. package models
  2. import "time"
  3. type ProjectEntry struct {
  4. ID int `json:"id"`
  5. OwnerID string `json:"ownerId,omitempty"`
  6. CreatedTime time.Time `json:"createdTime"`
  7. Name string `json:"name"`
  8. Status Status `json:"status"`
  9. }
  10. type ProjectRequirement struct {
  11. ID int `json:"id"`
  12. Name string `json:"name"`
  13. Description string `json:"description"`
  14. Status Status `json:"status"`
  15. Stats []StatProgressEntry `json:"stats,omitempty"`
  16. Items []Item `json:"items,omitempty"`
  17. }
  18. func (requirement *ProjectRequirement) Update(update ProjectRequirementUpdate) {
  19. if update.Name != nil {
  20. requirement.Name = *update.Name
  21. }
  22. if update.Description != nil {
  23. requirement.Description = *update.Description
  24. }
  25. if update.Status != nil {
  26. requirement.Status = *update.Status
  27. }
  28. deleteList := make([]int, 0, len(update.Stats))
  29. for i, stat := range update.Stats {
  30. if stat.Acquired == 0 && stat.Required == 0 {
  31. deleteList = append(deleteList, i-len(deleteList))
  32. }
  33. found := false
  34. for j := range requirement.Stats {
  35. if requirement.Stats[j].ID == stat.ID {
  36. requirement.Stats[j].Required = stat.Required
  37. requirement.Stats[j].Acquired = stat.Acquired
  38. found = true
  39. break
  40. }
  41. }
  42. if !found {
  43. requirement.Stats = append(requirement.Stats, stat)
  44. }
  45. }
  46. }
  47. type ProjectRequirementUpdate struct {
  48. Name *string `json:"name"`
  49. Description *string `json:"description"`
  50. Status *Status `json:"status"`
  51. Stats []StatProgressEntry `json:"stats"`
  52. }
  53. type Project struct {
  54. ProjectEntry
  55. Description string `json:"description"`
  56. Requirements []ProjectRequirement `json:"requirements"`
  57. }
  58. func (project *Project) Update(update ProjectUpdate) {
  59. if update.OwnerID != nil {
  60. project.OwnerID = *update.OwnerID
  61. }
  62. if update.Name != nil {
  63. project.Name = *update.Name
  64. }
  65. if update.Description != nil {
  66. project.Description = *update.Description
  67. }
  68. if update.Status != nil {
  69. project.Status = *update.Status
  70. }
  71. }
  72. func (project *Project) Requirement(id int) *ProjectRequirement {
  73. for i, requirement := range project.Requirements {
  74. if requirement.ID == id {
  75. return &project.Requirements[i]
  76. }
  77. }
  78. return nil
  79. }
  80. type ProjectUpdate struct {
  81. Name *string `json:"name,omitempty"`
  82. OwnerID *string `json:"ownerId,omitempty"`
  83. Status *Status `json:"status,omitempty"`
  84. Description *string `json:"description,omitempty"`
  85. }