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.

73 lines
1.8 KiB

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. StartTime time.Time `json:"startTime" db:"start_time"`
  11. EndTime time.Time `json:"endTime" db:"end_time"`
  12. Amount int `json:"amount" db:"amount"`
  13. Name string `json:"name" db:"name"`
  14. Description string `json:"description" db:"description"`
  15. }
  16. func (goal *Goal) Update(update GoalUpdate) {
  17. if update.Amount != nil {
  18. goal.Amount = *update.Amount
  19. }
  20. if update.StartTime != nil {
  21. goal.StartTime = *update.StartTime
  22. }
  23. if update.EndTime != nil {
  24. goal.EndTime = *update.EndTime
  25. }
  26. if update.Name != nil {
  27. goal.Name = *update.Name
  28. }
  29. if update.Description != nil {
  30. goal.Description = *update.Description
  31. }
  32. }
  33. type GoalUpdate struct {
  34. StartTime *time.Time `json:"startTime"`
  35. EndTime *time.Time `json:"endTime"`
  36. Amount *int `json:"amount"`
  37. Name *string `json:"name"`
  38. Description *string `json:"description"`
  39. }
  40. type GoalResult struct {
  41. Goal
  42. Group *Group `json:"group"`
  43. Items []*GoalResultItem `json:"items"`
  44. Logs []*LogResult `json:"logs"`
  45. CompletedAmount int `json:"completedAmount"`
  46. }
  47. type GoalResultItem struct {
  48. Item
  49. CompletedAmount int `json:"completedAmount"`
  50. }
  51. type GoalFilter struct {
  52. UserID string
  53. GroupIDs []string
  54. IncludesTime *time.Time
  55. MinTime *time.Time
  56. MaxTime *time.Time
  57. IDs []string
  58. }
  59. type GoalRepository interface {
  60. Find(ctx context.Context, id string) (*Goal, error)
  61. List(ctx context.Context, filter GoalFilter) ([]*Goal, error)
  62. Insert(ctx context.Context, goal Goal) error
  63. Update(ctx context.Context, goal Goal) error
  64. Delete(ctx context.Context, goal Goal) error
  65. }