package models import ( "context" "time" ) type Goal struct { ID string `json:"id" db:"goal_id"` UserID string `json:"-" db:"user_id"` GroupID string `json:"groupId" db:"group_id"` ItemID *string `json:"itemId" db:"item_id"` StartTime time.Time `json:"startTime" db:"start_time"` EndTime time.Time `json:"endTime" db:"end_time"` Amount int `json:"amount" db:"amount"` Unweighted bool `json:"unweighted" db:"unweighted"` Name string `json:"name" db:"name"` Description string `json:"description" db:"description"` CompositionMode string `json:"compositionMode" db:"composition_mode"` } func (goal *Goal) Update(update GoalUpdate) { if update.Amount != nil { goal.Amount = *update.Amount } if update.StartTime != nil { goal.StartTime = *update.StartTime } if update.EndTime != nil { goal.EndTime = *update.EndTime } if update.Name != nil { goal.Name = *update.Name } if update.Description != nil { goal.Description = *update.Description } if update.Unweighted != nil { goal.Unweighted = *update.Unweighted } if update.CompositionMode != nil { goal.CompositionMode = *update.CompositionMode } if update.ItemID != nil { goal.ItemID = update.ItemID } if update.ClearItemID { goal.ItemID = nil } } type GoalUpdate struct { StartTime *time.Time `json:"startTime"` EndTime *time.Time `json:"endTime"` Amount *int `json:"amount"` Name *string `json:"name"` Description *string `json:"description"` ItemID *string `json:"itemId"` Unweighted *bool `json:"unweighted"` CompositionMode *string `json:"compositionMode"` ClearItemID bool `json:"clearItemID"` } type GoalResult struct { Goal Group *Group `json:"group"` Items []*GoalResultItem `json:"items"` Logs []*LogResult `json:"logs"` CompletedAmount int `json:"completedAmount"` } type GoalResultItem struct { Item CompletedAmount int `json:"completedAmount"` } type GoalFilter struct { UserID string GroupIDs []string IncludesTime *time.Time MinTime *time.Time MaxTime *time.Time IDs []string } type GoalRepository interface { Find(ctx context.Context, id string) (*Goal, error) List(ctx context.Context, filter GoalFilter) ([]*Goal, error) Insert(ctx context.Context, goal Goal) error Update(ctx context.Context, goal Goal) error Delete(ctx context.Context, goal Goal) error }