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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package models
  2. import "time"
  3. type Log struct {
  4. ID string `db:"log_id"`
  5. UserID string `db:"user_id"`
  6. Date time.Time `db:"date"`
  7. Description string `db:"description"`
  8. Items []LogItem
  9. Tasks []LogTask
  10. }
  11. func (log *Log) Copy() *Log {
  12. newLog := *log
  13. newLog.Items = append(newLog.Items[:0:0], log.Items...)
  14. newLog.Tasks = append(newLog.Tasks[:0:0], log.Tasks...)
  15. return &newLog
  16. }
  17. func (log *Log) Empty() bool {
  18. return len(log.Items) == 0 && len(log.Tasks) == 0
  19. }
  20. func (log *Log) MatchesIssue(issueID string) bool {
  21. for _, item := range log.Items {
  22. if item.IssueID == issueID {
  23. return true
  24. }
  25. }
  26. for _, task := range log.Tasks {
  27. if task.IssueID == issueID {
  28. return true
  29. }
  30. }
  31. return false
  32. }
  33. func (log *Log) MatchesIssueTask(issueTaskID string) bool {
  34. for _, task := range log.Tasks {
  35. if task.IssueTaskID == issueTaskID {
  36. return true
  37. }
  38. }
  39. return false
  40. }
  41. func (log *Log) MatchesIssueItem(issueItemID string) bool {
  42. for _, item := range log.Items {
  43. if item.IssueItemID == issueItemID {
  44. return true
  45. }
  46. }
  47. return false
  48. }
  49. func (log *Log) Task(issueTaskID string) *LogTask {
  50. for i := range log.Tasks {
  51. task := &log.Tasks[i]
  52. if task.IssueTaskID == issueTaskID {
  53. return task
  54. }
  55. }
  56. return nil
  57. }
  58. func (log *Log) Item(issueItemID string) *LogItem {
  59. for i := range log.Items {
  60. item := &log.Items[i]
  61. if item.IssueItemID == issueItemID {
  62. return item
  63. }
  64. }
  65. return nil
  66. }
  67. type LogTask struct {
  68. LogID string `db:"log_id"`
  69. IssueID string `db:"issue_id"`
  70. IssueTaskID string `db:"issue_task_id"`
  71. Units *int `db:"units"`
  72. Duration time.Duration `db:"duration"`
  73. }
  74. type LogItem struct {
  75. LogID string `db:"log_id"`
  76. IssueID string `db:"issue_id"`
  77. IssueItemID string `db:"issue_item_id"`
  78. Amount int `db:"amount"`
  79. }
  80. type LogFilter struct {
  81. LogIDs []string
  82. UserIDs []string
  83. IssueIDs []string
  84. IssueTaskIDs []string
  85. IssueItemIDs []string
  86. FromDate *time.Time
  87. ToDate *time.Time
  88. }