package models import ( "context" "time" ) type Project struct { ID string `json:"id" db:"project_id"` UserID string `json:"-" db:"user_id"` Name string `json:"name" db:"name"` Description string `json:"description" db:"description"` Icon string `json:"icon" db:"icon"` Active bool `json:"active" db:"active"` CreatedTime time.Time `json:"createdTime" db:"created_time"` StartTime *time.Time `json:"startTime" db:"start_time"` EndTime *time.Time `json:"endTime" db:"end_time"` SubtractAmount int `json:"subtractAmount" db:"subtract_amount"` StatusTag *string `json:"statusTag" db:"status_tag"` Favorite bool `json:"favorite" db:"favorite"` Tags []string `json:"tags" db:"tags"` } func (project *Project) Update(update ProjectUpdate) { if update.Name != nil { project.Name = *update.Name } if update.Description != nil { project.Description = *update.Description } if update.Icon != nil { project.Icon = *update.Icon } if update.Active != nil { project.Active = *update.Active } if update.StartTime != nil { startTimeCopy := update.StartTime.UTC() project.StartTime = &startTimeCopy } if update.ClearStartTime { project.StartTime = nil } if update.EndTime != nil { endTimeCopy := update.EndTime.UTC() project.EndTime = &endTimeCopy } if update.ClearEndTime { project.EndTime = nil } if update.SubtractAmount != nil { project.SubtractAmount = *update.SubtractAmount if project.SubtractAmount < 0 { project.SubtractAmount = 0 } } if update.StatusTag != nil { project.StatusTag = update.StatusTag } if update.ClearStatusTag { project.StatusTag = nil } if update.Favorite != nil { project.Favorite = *update.Favorite } if update.SetTags != nil { project.Tags = update.SetTags } if project.StatusTag != nil && project.Active { project.StatusTag = nil } } type ProjectUpdate struct { Name *string `json:"name"` Description *string `json:"description"` Icon *string `json:"icon"` Active *bool `json:"active"` StartTime *time.Time `json:"startTime"` ClearStartTime bool `json:"clearStartTime"` EndTime *time.Time `json:"endTime"` ClearEndTime bool `json:"clearEndTime"` SubtractAmount *int `json:"subtractAmount"` StatusTag *string `json:"statusTag"` ClearStatusTag bool `json:"clearStatusTag"` SetTags []string `json:"setTags"` Favorite *bool `json:"favorite"` } type ProjectResult struct { Project Tasks []*TaskResult `json:"tasks"` } type ProjectFilter struct { UserID string Active *bool Favorite *bool Expiring bool IncludeSemiActive bool IDs []string } type ProjectRepository interface { Find(ctx context.Context, id string) (*Project, error) List(ctx context.Context, filter ProjectFilter) ([]*Project, error) Insert(ctx context.Context, project Project) error Update(ctx context.Context, project Project) error Delete(ctx context.Context, project Project) error }