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.

83 lines
2.2 KiB

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. 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. }
  48. type ProjectUpdate struct {
  49. Name *string `json:"name"`
  50. Description *string `json:"description"`
  51. Icon *string `json:"icon"`
  52. Active *bool `json:"active"`
  53. EndTime *time.Time `json:"endTime"`
  54. ClearEndTime bool `json:"clearEndTime"`
  55. StatusTag *string `json:"statusTag"`
  56. ClearStatusTag bool `json:"clearStatusTag"`
  57. Favorite *bool `json:"favorite"`
  58. }
  59. type ProjectResult struct {
  60. Project
  61. Tasks []*TaskResult `json:"tasks"`
  62. }
  63. type ProjectFilter struct {
  64. UserID string
  65. Active *bool
  66. Favorite *bool
  67. Expiring bool
  68. IDs []string
  69. }
  70. type ProjectRepository interface {
  71. Find(ctx context.Context, id string) (*Project, error)
  72. List(ctx context.Context, filter ProjectFilter) ([]*Project, error)
  73. Insert(ctx context.Context, project Project) error
  74. Update(ctx context.Context, project Project) error
  75. Delete(ctx context.Context, project Project) error
  76. }