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.
106 lines
2.9 KiB
106 lines
2.9 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"`
|
|
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"`
|
|
}
|
|
|
|
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 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"`
|
|
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
|
|
}
|