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.
 
 
 
 
 
 

87 lines
2.3 KiB

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"`
EndTime *time.Time `json:"endTime" db:"end_time"`
StatusTag *string `json:"statusTag" db:"status_tag"`
Favorite bool `json:"favorite" db:"favorite"`
}
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.EndTime != nil {
endTimeCopy := update.EndTime.UTC()
project.EndTime = &endTimeCopy
}
if update.ClearEndTime {
project.EndTime = nil
}
if update.StatusTag != nil {
project.StatusTag = update.StatusTag
}
if update.ClearStatusTag {
project.StatusTag = nil
}
if update.Favorite != nil {
project.Favorite = *update.Favorite
}
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"`
EndTime *time.Time `json:"endTime"`
ClearEndTime bool `json:"clearEndTime"`
StatusTag *string `json:"statusTag"`
ClearStatusTag bool `json:"clearStatusTag"`
Favorite *bool `json:"favorite"`
}
type ProjectResult struct {
Project
Tasks []*TaskResult `json:"tasks"`
}
type ProjectFilter struct {
UserID string
Active *bool
Favorite *bool
Expiring 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
}