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.

87 lines
2.3 KiB

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