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.

103 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
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 TaskResult struct {
  70. Task
  71. Item *Item `json:"item"`
  72. Logs []*Log `json:"logs"`
  73. CompletedAmount int `json:"completedAmount"`
  74. Project *Project `json:"project,omitempty"`
  75. }
  76. type TaskFilter struct {
  77. UserID string
  78. Active *bool
  79. Expiring *bool
  80. IDs []string
  81. ItemIDs []string
  82. ProjectIDs []string
  83. }
  84. type TaskRepository interface {
  85. Find(ctx context.Context, id string) (*Task, error)
  86. List(ctx context.Context, filter TaskFilter) ([]*Task, error)
  87. ListWithLinks(ctx context.Context, filter TaskFilter) ([]*Task, []*TaskLink, error)
  88. Insert(ctx context.Context, task Task) error
  89. Update(ctx context.Context, task Task) error
  90. CreateLink(ctx context.Context, link TaskLink) error
  91. DeleteLink(ctx context.Context, link TaskLink) error
  92. UnlinkTask(ctx context.Context, task Task) error
  93. UnlinkProject(ctx context.Context, project Project) error
  94. Delete(ctx context.Context, task Task) error
  95. }