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.

121 lines
3.4 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
  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. project.GroupID = update.GroupID
  25. if *project.GroupID == "" {
  26. project.GroupID = nil
  27. }
  28. }
  29. if update.Name != nil {
  30. project.Name = *update.Name
  31. }
  32. if update.Description != nil {
  33. project.Description = *update.Description
  34. }
  35. if update.Icon != nil {
  36. project.Icon = *update.Icon
  37. }
  38. if update.Active != nil {
  39. project.Active = *update.Active
  40. }
  41. if update.StartTime != nil {
  42. startTimeCopy := update.StartTime.UTC()
  43. project.StartTime = &startTimeCopy
  44. }
  45. if update.ClearStartTime {
  46. project.StartTime = nil
  47. }
  48. if update.EndTime != nil {
  49. endTimeCopy := update.EndTime.UTC()
  50. project.EndTime = &endTimeCopy
  51. }
  52. if update.ClearEndTime {
  53. project.EndTime = nil
  54. }
  55. if update.SubtractAmount != nil {
  56. project.SubtractAmount = *update.SubtractAmount
  57. if project.SubtractAmount < 0 {
  58. project.SubtractAmount = 0
  59. }
  60. }
  61. if update.StatusTag != nil {
  62. project.StatusTag = update.StatusTag
  63. }
  64. if update.ClearStatusTag {
  65. project.StatusTag = nil
  66. }
  67. if update.Favorite != nil {
  68. project.Favorite = *update.Favorite
  69. }
  70. if update.SetTags != nil {
  71. project.Tags = update.SetTags
  72. }
  73. if project.StatusTag != nil && project.Active {
  74. project.StatusTag = nil
  75. }
  76. }
  77. type ProjectUpdate struct {
  78. GroupID *string `json:"groupId"`
  79. Name *string `json:"name"`
  80. Description *string `json:"description"`
  81. Icon *string `json:"icon"`
  82. Active *bool `json:"active"`
  83. StartTime *time.Time `json:"startTime"`
  84. ClearStartTime bool `json:"clearStartTime"`
  85. EndTime *time.Time `json:"endTime"`
  86. ClearEndTime bool `json:"clearEndTime"`
  87. SubtractAmount *int `json:"subtractAmount"`
  88. StatusTag *string `json:"statusTag"`
  89. ClearStatusTag bool `json:"clearStatusTag"`
  90. SetTags []string `json:"setTags"`
  91. Favorite *bool `json:"favorite"`
  92. }
  93. type ProjectResult struct {
  94. Project
  95. Tasks []*TaskResult `json:"tasks"`
  96. }
  97. type ProjectFilter struct {
  98. UserID string
  99. ProjectGroupIDs []string
  100. Active *bool
  101. Favorite *bool
  102. Expiring bool
  103. IncludeSemiActive bool
  104. IDs []string
  105. Ungrouped bool
  106. }
  107. type ProjectRepository interface {
  108. Find(ctx context.Context, id string) (*Project, error)
  109. List(ctx context.Context, filter ProjectFilter) ([]*Project, error)
  110. Insert(ctx context.Context, project Project) error
  111. Update(ctx context.Context, project Project) error
  112. Delete(ctx context.Context, project Project) error
  113. }