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.

89 lines
2.4 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. }
  50. type TaskUpdate struct {
  51. ItemID *string `json:"itemId"`
  52. ItemAmount *int `json:"itemAmount"`
  53. Name *string `json:"name"`
  54. Description *string `json:"description"`
  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. }
  61. type TaskResult struct {
  62. Task
  63. Item *Item `json:"item"`
  64. Logs []*Log `json:"logs"`
  65. CompletedAmount int `json:"completedAmount"`
  66. Project *Project `json:"project,omitempty"`
  67. }
  68. type TaskFilter struct {
  69. UserID string
  70. Active *bool
  71. Expiring *bool
  72. IDs []string
  73. ItemIDs []string
  74. ProjectIDs []string
  75. }
  76. type TaskRepository interface {
  77. Find(ctx context.Context, id string) (*Task, error)
  78. List(ctx context.Context, filter TaskFilter) ([]*Task, error)
  79. Insert(ctx context.Context, task Task) error
  80. Update(ctx context.Context, task Task) error
  81. Delete(ctx context.Context, task Task) error
  82. }