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.

111 lines
3.1 KiB

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