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.

74 lines
1.9 KiB

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