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.

93 lines
2.5 KiB

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 TaskResult struct {
  66. Task
  67. Item *Item `json:"item"`
  68. Logs []*Log `json:"logs"`
  69. CompletedAmount int `json:"completedAmount"`
  70. Project *Project `json:"project,omitempty"`
  71. }
  72. type TaskFilter struct {
  73. UserID string
  74. Active *bool
  75. Expiring *bool
  76. IDs []string
  77. ItemIDs []string
  78. ProjectIDs []string
  79. }
  80. type TaskRepository interface {
  81. Find(ctx context.Context, id string) (*Task, error)
  82. List(ctx context.Context, filter TaskFilter) ([]*Task, error)
  83. Insert(ctx context.Context, task Task) error
  84. Update(ctx context.Context, task Task) error
  85. Delete(ctx context.Context, task Task) error
  86. }