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.

92 lines
2.5 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  1. package models
  2. import (
  3. "context"
  4. "time"
  5. )
  6. type Goal struct {
  7. ID string `json:"id" db:"goal_id"`
  8. UserID string `json:"-" db:"user_id"`
  9. GroupID string `json:"groupId" db:"group_id"`
  10. ItemID *string `json:"itemId" db:"item_id"`
  11. StartTime time.Time `json:"startTime" db:"start_time"`
  12. EndTime time.Time `json:"endTime" db:"end_time"`
  13. Amount int `json:"amount" db:"amount"`
  14. Unweighted bool `json:"unweighted" db:"unweighted"`
  15. Name string `json:"name" db:"name"`
  16. Description string `json:"description" db:"description"`
  17. CompositionMode string `json:"compositionMode" db:"composition_mode"`
  18. }
  19. func (goal *Goal) Update(update GoalUpdate) {
  20. if update.Amount != nil {
  21. goal.Amount = *update.Amount
  22. }
  23. if update.StartTime != nil {
  24. goal.StartTime = *update.StartTime
  25. }
  26. if update.EndTime != nil {
  27. goal.EndTime = *update.EndTime
  28. }
  29. if update.Name != nil {
  30. goal.Name = *update.Name
  31. }
  32. if update.Description != nil {
  33. goal.Description = *update.Description
  34. }
  35. if update.Unweighted != nil {
  36. goal.Unweighted = *update.Unweighted
  37. }
  38. if update.CompositionMode != nil {
  39. goal.CompositionMode = *update.CompositionMode
  40. }
  41. if update.ItemID != nil {
  42. goal.ItemID = update.ItemID
  43. }
  44. if update.ClearItemID {
  45. goal.ItemID = nil
  46. }
  47. }
  48. type GoalUpdate struct {
  49. StartTime *time.Time `json:"startTime"`
  50. EndTime *time.Time `json:"endTime"`
  51. Amount *int `json:"amount"`
  52. Name *string `json:"name"`
  53. Description *string `json:"description"`
  54. ItemID *string `json:"itemId"`
  55. Unweighted *bool `json:"unweighted"`
  56. CompositionMode *string `json:"compositionMode"`
  57. ClearItemID bool `json:"clearItemID"`
  58. }
  59. type GoalResult struct {
  60. Goal
  61. Group *Group `json:"group"`
  62. Items []*GoalResultItem `json:"items"`
  63. Logs []*LogResult `json:"logs"`
  64. CompletedAmount int `json:"completedAmount"`
  65. }
  66. type GoalResultItem struct {
  67. Item
  68. CompletedAmount int `json:"completedAmount"`
  69. }
  70. type GoalFilter struct {
  71. UserID string
  72. GroupIDs []string
  73. IncludesTime *time.Time
  74. MinTime *time.Time
  75. MaxTime *time.Time
  76. IDs []string
  77. }
  78. type GoalRepository interface {
  79. Find(ctx context.Context, id string) (*Goal, error)
  80. List(ctx context.Context, filter GoalFilter) ([]*Goal, error)
  81. Insert(ctx context.Context, goal Goal) error
  82. Update(ctx context.Context, goal Goal) error
  83. Delete(ctx context.Context, goal Goal) error
  84. }