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.

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