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.
 
 
 
 
 
 

75 lines
2.0 KiB

package models
import (
"context"
"time"
)
type Task struct {
ID string `json:"id" db:"task_id"`
UserID string `json:"-" db:"user_id"`
ItemID string `json:"itemId" db:"item_id"`
ProjectID string `json:"projectId" db:"project_id"`
ItemAmount int `json:"itemAmount" db:"item_amount"`
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"`
EndTime *time.Time `json:"endTime" db:"end_time"`
}
func (task *Task) Update(update TaskUpdate) {
if update.ItemAmount != nil {
task.ItemAmount = *update.ItemAmount
}
if update.Name != nil {
task.Name = *update.Name
}
if update.Description != nil {
task.Description = *update.Description
}
if update.Active != nil {
task.Active = *update.Active
}
if update.EndTime != nil {
endTimeCopy := update.EndTime.UTC()
task.EndTime = &endTimeCopy
}
if update.ClearEndTime {
task.EndTime = nil
}
}
type TaskUpdate struct {
ItemAmount *int `json:"itemAmount"`
Name *string `json:"name"`
Description *string `json:"description"`
Active *bool `json:"active"`
EndTime *time.Time `json:"endTime"`
ClearEndTime bool `json:"clearEndTime"`
}
type TaskResult struct {
Task
Item *Item `json:"item"`
Logs []*Log `json:"logs"`
CompletedAmount int `json:"completedAmount"`
}
type TaskFilter struct {
UserID string
Active *bool
Expiring *bool
IDs []string
ItemIDs []string
ProjectIDs []string
}
type TaskRepository interface {
Find(ctx context.Context, id string) (*Task, error)
List(ctx context.Context, filter TaskFilter) ([]*Task, error)
Insert(ctx context.Context, task Task) error
Update(ctx context.Context, task Task) error
Delete(ctx context.Context, task Task) error
}