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.

68 lines
1.7 KiB

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. }
  16. func (project *Project) Update(update ProjectUpdate) {
  17. if update.Name != nil {
  18. project.Name = *update.Name
  19. }
  20. if update.Description != nil {
  21. project.Description = *update.Description
  22. }
  23. if update.Icon != nil {
  24. project.Icon = *update.Icon
  25. }
  26. if update.Active != nil {
  27. project.Active = *update.Active
  28. }
  29. if update.EndTime != nil {
  30. endTimeCopy := update.EndTime.UTC()
  31. project.EndTime = &endTimeCopy
  32. }
  33. if update.ClearEndTime {
  34. project.EndTime = nil
  35. }
  36. }
  37. type ProjectUpdate struct {
  38. Name *string `json:"name"`
  39. Description *string `json:"description"`
  40. Icon *string `json:"icon"`
  41. Active *bool `json:"active"`
  42. EndTime *time.Time `json:"endTime"`
  43. ClearEndTime bool `json:"clearEndTime"`
  44. }
  45. type ProjectResult struct {
  46. Project
  47. Tasks []*TaskResult `json:"tasks"`
  48. }
  49. type ProjectFilter struct {
  50. UserID string
  51. Active *bool
  52. Expiring bool
  53. IDs []string
  54. }
  55. type ProjectRepository interface {
  56. Find(ctx context.Context, id string) (*Project, error)
  57. List(ctx context.Context, filter ProjectFilter) ([]*Project, error)
  58. Insert(ctx context.Context, project Project) error
  59. Update(ctx context.Context, project Project) error
  60. Delete(ctx context.Context, project Project) error
  61. }