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.

108 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
4 years ago
4 years ago
4 years ago
  1. package models
  2. import (
  3. "context"
  4. "time"
  5. )
  6. type Task struct {
  7. ID string `json:"id" db:"task_id"`
  8. UserID string `json:"-" db:"user_id"`
  9. ItemID string `json:"itemId" db:"item_id"`
  10. ProjectID string `json:"projectId" db:"project_id"`
  11. ItemAmount int `json:"itemAmount" db:"item_amount"`
  12. Name string `json:"name" db:"name"`
  13. Description string `json:"description" db:"description"`
  14. Icon string `json:"icon" db:"icon"`
  15. Active bool `json:"active" db:"active"`
  16. CreatedTime time.Time `json:"createdTime" db:"created_time"`
  17. EndTime *time.Time `json:"endTime" db:"end_time"`
  18. StatusTag *string `json:"statusTag" db:"status_tag"`
  19. }
  20. func (task *Task) Update(update TaskUpdate) {
  21. if update.ItemID != nil {
  22. task.ItemID = *update.ItemID
  23. }
  24. if update.ItemAmount != nil {
  25. task.ItemAmount = *update.ItemAmount
  26. }
  27. if update.Name != nil {
  28. task.Name = *update.Name
  29. }
  30. if update.Description != nil {
  31. task.Description = *update.Description
  32. }
  33. if update.Active != nil {
  34. task.Active = *update.Active
  35. }
  36. if update.EndTime != nil {
  37. endTimeCopy := update.EndTime.UTC()
  38. task.EndTime = &endTimeCopy
  39. }
  40. if update.ClearEndTime {
  41. task.EndTime = nil
  42. }
  43. if update.StatusTag != nil {
  44. task.StatusTag = update.StatusTag
  45. }
  46. if update.ClearStatusTag {
  47. task.StatusTag = nil
  48. }
  49. if update.ProjectID != nil {
  50. task.ProjectID = *update.ProjectID
  51. }
  52. }
  53. type TaskUpdate struct {
  54. ItemID *string `json:"itemId"`
  55. ItemAmount *int `json:"itemAmount"`
  56. Name *string `json:"name"`
  57. Description *string `json:"description"`
  58. Active *bool `json:"active"`
  59. EndTime *time.Time `json:"endTime"`
  60. ClearEndTime bool `json:"clearEndTime"`
  61. StatusTag *string `json:"statusTag"`
  62. ClearStatusTag bool `json:"clearStatusTag"`
  63. ProjectID *string `json:"projectId"`
  64. }
  65. type TaskLink struct {
  66. TaskID string `json:"taskId" db:"task_id"`
  67. ProjectID string `json:"projectId" db:"project_id"`
  68. }
  69. type TaskWithProject struct {
  70. Task
  71. Project *Project `json:"project,omitempty"`
  72. }
  73. type TaskResult struct {
  74. Task
  75. Item *Item `json:"item"`
  76. Logs []*LogWithSecondaryItem `json:"logs"`
  77. CompletedAmount int `json:"completedAmount"`
  78. Project *Project `json:"project,omitempty"`
  79. }
  80. type TaskFilter struct {
  81. UserID string
  82. Active *bool
  83. Expiring *bool
  84. IDs []string
  85. ItemIDs []string
  86. ProjectIDs []string
  87. }
  88. type TaskRepository interface {
  89. Find(ctx context.Context, id string) (*Task, error)
  90. List(ctx context.Context, filter TaskFilter) ([]*Task, error)
  91. ListWithLinks(ctx context.Context, filter TaskFilter) ([]*Task, []*TaskLink, error)
  92. Insert(ctx context.Context, task Task) error
  93. Update(ctx context.Context, task Task) error
  94. CreateLink(ctx context.Context, link TaskLink) error
  95. DeleteLink(ctx context.Context, link TaskLink) error
  96. UnlinkTask(ctx context.Context, task Task) error
  97. UnlinkProject(ctx context.Context, project Project) error
  98. Delete(ctx context.Context, task Task) error
  99. }