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.

77 lines
2.0 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  1. package models
  2. import (
  3. "context"
  4. "time"
  5. )
  6. type Project struct {
  7. ID string `json:"id" db:"project_id"`
  8. UserID string `json:"-" db:"user_id"`
  9. Name string `json:"name" db:"name"`
  10. Description string `json:"description" db:"description"`
  11. Icon string `json:"icon" db:"icon"`
  12. Active bool `json:"active" db:"active"`
  13. CreatedTime time.Time `json:"createdTime" db:"created_time"`
  14. EndTime *time.Time `json:"endTime" db:"end_time"`
  15. StatusTag *string `json:"statusTag" db:"status_tag"`
  16. }
  17. func (project *Project) Update(update ProjectUpdate) {
  18. if update.Name != nil {
  19. project.Name = *update.Name
  20. }
  21. if update.Description != nil {
  22. project.Description = *update.Description
  23. }
  24. if update.Icon != nil {
  25. project.Icon = *update.Icon
  26. }
  27. if update.Active != nil {
  28. project.Active = *update.Active
  29. }
  30. if update.EndTime != nil {
  31. endTimeCopy := update.EndTime.UTC()
  32. project.EndTime = &endTimeCopy
  33. }
  34. if update.ClearEndTime {
  35. project.EndTime = nil
  36. }
  37. if update.StatusTag != nil {
  38. project.StatusTag = update.StatusTag
  39. }
  40. if update.ClearStatusTag {
  41. project.StatusTag = nil
  42. }
  43. }
  44. type ProjectUpdate struct {
  45. Name *string `json:"name"`
  46. Description *string `json:"description"`
  47. Icon *string `json:"icon"`
  48. Active *bool `json:"active"`
  49. EndTime *time.Time `json:"endTime"`
  50. ClearEndTime bool `json:"clearEndTime"`
  51. StatusTag *string `json:"statusTag"`
  52. ClearStatusTag bool `json:"clearStatusTag"`
  53. }
  54. type ProjectResult struct {
  55. Project
  56. Tasks []*TaskResult `json:"tasks"`
  57. }
  58. type ProjectFilter struct {
  59. UserID string
  60. Active *bool
  61. Expiring bool
  62. IDs []string
  63. }
  64. type ProjectRepository interface {
  65. Find(ctx context.Context, id string) (*Project, error)
  66. List(ctx context.Context, filter ProjectFilter) ([]*Project, error)
  67. Insert(ctx context.Context, project Project) error
  68. Update(ctx context.Context, project Project) error
  69. Delete(ctx context.Context, project Project) error
  70. }