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.

80 lines
2.1 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 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. }
  19. func (task *Task) Update(update TaskUpdate) {
  20. if update.ItemID != nil {
  21. task.ItemID = *update.ItemID
  22. }
  23. if update.ItemAmount != nil {
  24. task.ItemAmount = *update.ItemAmount
  25. }
  26. if update.Name != nil {
  27. task.Name = *update.Name
  28. }
  29. if update.Description != nil {
  30. task.Description = *update.Description
  31. }
  32. if update.Active != nil {
  33. task.Active = *update.Active
  34. }
  35. if update.EndTime != nil {
  36. endTimeCopy := update.EndTime.UTC()
  37. task.EndTime = &endTimeCopy
  38. }
  39. if update.ClearEndTime {
  40. task.EndTime = nil
  41. }
  42. }
  43. type TaskUpdate struct {
  44. ItemID *string `json:"itemId"`
  45. ItemAmount *int `json:"itemAmount"`
  46. Name *string `json:"name"`
  47. Description *string `json:"description"`
  48. Active *bool `json:"active"`
  49. EndTime *time.Time `json:"endTime"`
  50. ClearEndTime bool `json:"clearEndTime"`
  51. }
  52. type TaskResult struct {
  53. Task
  54. Item *Item `json:"item"`
  55. Logs []*Log `json:"logs"`
  56. CompletedAmount int `json:"completedAmount"`
  57. Project *Project `json:"project,omitempty"`
  58. }
  59. type TaskFilter struct {
  60. UserID string
  61. Active *bool
  62. Expiring *bool
  63. IDs []string
  64. ItemIDs []string
  65. ProjectIDs []string
  66. }
  67. type TaskRepository interface {
  68. Find(ctx context.Context, id string) (*Task, error)
  69. List(ctx context.Context, filter TaskFilter) ([]*Task, error)
  70. Insert(ctx context.Context, task Task) error
  71. Update(ctx context.Context, task Task) error
  72. Delete(ctx context.Context, task Task) error
  73. }