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.
 
 
 
 
 
 

93 lines
2.5 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"`
StatusTag *string `json:"statusTag" db:"status_tag"`
}
func (task *Task) Update(update TaskUpdate) {
if update.ItemID != nil {
task.ItemID = *update.ItemID
}
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
}
if update.StatusTag != nil {
task.StatusTag = update.StatusTag
}
if update.ClearStatusTag {
task.StatusTag = nil
}
if update.ProjectID != nil {
task.ProjectID = *update.ProjectID
}
}
type TaskUpdate struct {
ItemID *string `json:"itemId"`
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"`
StatusTag *string `json:"statusTag"`
ClearStatusTag bool `json:"clearStatusTag"`
ProjectID *string `json:"projectId"`
}
type TaskResult struct {
Task
Item *Item `json:"item"`
Logs []*Log `json:"logs"`
CompletedAmount int `json:"completedAmount"`
Project *Project `json:"project,omitempty"`
}
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
}