package models import ( "context" "strings" "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"` TaskFilter *string `json:"taskFilter" db:"task_filter"` ItemFilter *string `json:"itemFilter" db:"item_filter"` } func (goal *Goal) Accepts(item *Item, task *Task) bool { if item.GroupID != goal.GroupID { return false } if goal.ItemID != nil && item.ID != *goal.ItemID { return false } if goal.TaskFilter != nil && !strings.Contains(strings.ToLower(task.Name), *goal.TaskFilter) { return false } if goal.ItemFilter != nil && !strings.Contains(strings.ToLower(item.Name), *goal.ItemFilter) { return false } return true } 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 } if update.TaskFilter != nil { goal.TaskFilter = update.TaskFilter } if update.ClearTaskFilter { goal.TaskFilter = nil } if update.ItemFilter != nil { goal.ItemFilter = update.ItemFilter } if update.ClearItemFilter { goal.ItemFilter = 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"` ClearItemID bool `json:"clearItemID"` Unweighted *bool `json:"unweighted"` CompositionMode *string `json:"compositionMode"` TaskFilter *string `json:"taskFilter"` ClearTaskFilter bool `json:"clearTaskFilter"` ItemFilter *string `json:"itemFilter"` ClearItemFilter bool `json:"clearItemFilter"` } type GoalResult struct { Goal Group *Group `json:"group"` Items []*GoalResultItem `json:"items"` Logs []*GoalResultLog `json:"logs"` CompletedAmount int `json:"completedAmount"` } type GoalResultLog struct { LogResult ItemCounted bool `json:"itemCounted"` SecondaryItemCounted bool `json:"secondaryItemCounted"` } 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 }