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.

122 lines
3.4 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 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. }
  98. type ProjectFilter struct {
  99. UserID string
  100. ProjectGroupIDs []string
  101. Active *bool
  102. Favorite *bool
  103. Expiring bool
  104. IncludeSemiActive bool
  105. IDs []string
  106. Ungrouped bool
  107. }
  108. type ProjectRepository interface {
  109. Find(ctx context.Context, id string) (*Project, error)
  110. List(ctx context.Context, filter ProjectFilter) ([]*Project, error)
  111. Insert(ctx context.Context, project Project) error
  112. Update(ctx context.Context, project Project) error
  113. Delete(ctx context.Context, project Project) error
  114. }