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.

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