stufflog graphql server
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.
 
 
 

108 lines
2.0 KiB

package models
import "time"
type Log struct {
ID string `db:"log_id"`
UserID string `db:"user_id"`
Date time.Time `db:"date"`
Description string `db:"description"`
Items []LogItem
Tasks []LogTask
}
func (log *Log) Copy() *Log {
newLog := *log
newLog.Items = append(newLog.Items[:0:0], log.Items...)
newLog.Tasks = append(newLog.Tasks[:0:0], log.Tasks...)
return &newLog
}
func (log *Log) Empty() bool {
return len(log.Items) == 0 && len(log.Tasks) == 0
}
func (log *Log) MatchesIssue(issueID string) bool {
for _, item := range log.Items {
if item.IssueID == issueID {
return true
}
}
for _, task := range log.Tasks {
if task.IssueID == issueID {
return true
}
}
return false
}
func (log *Log) MatchesIssueTask(issueTaskID string) bool {
for _, task := range log.Tasks {
if task.IssueTaskID == issueTaskID {
return true
}
}
return false
}
func (log *Log) MatchesIssueItem(issueItemID string) bool {
for _, item := range log.Items {
if item.IssueItemID == issueItemID {
return true
}
}
return false
}
func (log *Log) Task(issueTaskID string) *LogTask {
for i := range log.Tasks {
task := &log.Tasks[i]
if task.IssueTaskID == issueTaskID {
return task
}
}
return nil
}
func (log *Log) Item(issueItemID string) *LogItem {
for i := range log.Items {
item := &log.Items[i]
if item.IssueItemID == issueItemID {
return item
}
}
return nil
}
type LogTask struct {
LogID string `db:"log_id"`
IssueID string `db:"issue_id"`
IssueTaskID string `db:"issue_task_id"`
Units *int `db:"units"`
Duration time.Duration `db:"duration"`
}
type LogItem struct {
LogID string `db:"log_id"`
IssueID string `db:"issue_id"`
IssueItemID string `db:"issue_item_id"`
Amount int `db:"amount"`
}
type LogFilter struct {
LogIDs []string
UserIDs []string
IssueIDs []string
IssueTaskIDs []string
IssueItemIDs []string
FromDate *time.Time
ToDate *time.Time
}