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.

128 lines
3.5 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. package models
  2. import (
  3. "context"
  4. "time"
  5. )
  6. type Project struct {
  7. ID string `json:"id" db:"project_id"`
  8. UserID string `json:"-" db:"user_id"`
  9. GroupID *string `json:"groupId" db:"project_group_id"`
  10. Name string `json:"name" db:"name"`
  11. Description string `json:"description" db:"description"`
  12. Icon string `json:"icon" db:"icon"`
  13. Active bool `json:"active" db:"active"`
  14. CreatedTime time.Time `json:"createdTime" db:"created_time"`
  15. StartTime *time.Time `json:"startTime" db:"start_time"`
  16. EndTime *time.Time `json:"endTime" db:"end_time"`
  17. SubtractAmount int `json:"subtractAmount" db:"subtract_amount"`
  18. StatusTag *string `json:"statusTag" db:"status_tag"`
  19. Favorite bool `json:"favorite" db:"favorite"`
  20. Tags []string `json:"tags" db:"tags"`
  21. }
  22. func (project *Project) Update(update ProjectUpdate) {
  23. if update.GroupID != nil {
  24. if *update.GroupID == "" {
  25. project.GroupID = nil
  26. } else {
  27. project.GroupID = update.GroupID
  28. }
  29. }
  30. if update.Name != nil {
  31. project.Name = *update.Name
  32. }
  33. if update.Description != nil {
  34. project.Description = *update.Description
  35. }
  36. if update.Icon != nil {
  37. project.Icon = *update.Icon
  38. }
  39. if update.Active != nil {
  40. project.Active = *update.Active
  41. }
  42. if update.StartTime != nil {
  43. startTimeCopy := update.StartTime.UTC()
  44. project.StartTime = &startTimeCopy
  45. }
  46. if update.ClearStartTime {
  47. project.StartTime = nil
  48. }
  49. if update.EndTime != nil {
  50. endTimeCopy := update.EndTime.UTC()
  51. project.EndTime = &endTimeCopy
  52. }
  53. if update.ClearEndTime {
  54. project.EndTime = nil
  55. }
  56. if update.SubtractAmount != nil {
  57. project.SubtractAmount = *update.SubtractAmount
  58. if project.SubtractAmount < 0 {
  59. project.SubtractAmount = 0
  60. }
  61. }
  62. if update.StatusTag != nil {
  63. project.StatusTag = update.StatusTag
  64. }
  65. if update.ClearStatusTag {
  66. project.StatusTag = nil
  67. }
  68. if update.Favorite != nil {
  69. project.Favorite = *update.Favorite
  70. }
  71. if update.SetTags != nil {
  72. project.Tags = update.SetTags
  73. }
  74. if project.StatusTag != nil && project.Active {
  75. project.StatusTag = nil
  76. }
  77. }
  78. type ProjectUpdate struct {
  79. GroupID *string `json:"groupId"`
  80. Name *string `json:"name"`
  81. Description *string `json:"description"`
  82. Icon *string `json:"icon"`
  83. Active *bool `json:"active"`
  84. StartTime *time.Time `json:"startTime"`
  85. ClearStartTime bool `json:"clearStartTime"`
  86. EndTime *time.Time `json:"endTime"`
  87. ClearEndTime bool `json:"clearEndTime"`
  88. SubtractAmount *int `json:"subtractAmount"`
  89. StatusTag *string `json:"statusTag"`
  90. ClearStatusTag bool `json:"clearStatusTag"`
  91. SetTags []string `json:"setTags"`
  92. Favorite *bool `json:"favorite"`
  93. }
  94. type ProjectResult struct {
  95. Project
  96. Tasks []*TaskResult `json:"tasks"`
  97. Subtractions []ProjectSubtraction `json:"subtractions"`
  98. }
  99. type ProjectSubtraction struct {
  100. Item Item `json:"item"`
  101. Amount int `json:"amount"`
  102. }
  103. type ProjectFilter struct {
  104. UserID string
  105. ProjectGroupIDs []string
  106. Active *bool
  107. Favorite *bool
  108. Expiring bool
  109. IncludeSemiActive bool
  110. IDs []string
  111. Ungrouped bool
  112. }
  113. type ProjectRepository interface {
  114. Find(ctx context.Context, id string) (*Project, error)
  115. List(ctx context.Context, filter ProjectFilter) ([]*Project, error)
  116. Insert(ctx context.Context, project Project) error
  117. Update(ctx context.Context, project Project) error
  118. Delete(ctx context.Context, project Project) error
  119. }