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.

51 lines
1.2 KiB

4 years ago
4 years ago
4 years ago
  1. package models
  2. import (
  3. "context"
  4. "time"
  5. )
  6. type Log struct {
  7. ID string `json:"id" db:"log_id"`
  8. UserID string `json:"-" db:"user_id"`
  9. TaskID string `json:"taskId" db:"task_id"`
  10. ItemID string `json:"itemId" db:"item_id"`
  11. LoggedTime time.Time `json:"loggedTime" db:"logged_time"`
  12. Description string `json:"description" db:"description"`
  13. }
  14. func (log *Log) Update(update LogUpdate) {
  15. if update.LoggedTime != nil {
  16. log.LoggedTime = update.LoggedTime.UTC()
  17. }
  18. if update.Description != nil {
  19. log.Description = *update.Description
  20. }
  21. }
  22. type LogUpdate struct {
  23. LoggedTime *time.Time `json:"loggedTime"`
  24. Description *string `json:"description"`
  25. }
  26. type LogResult struct {
  27. Log
  28. Task *Task `json:"task"`
  29. Item *Item `json:"item"`
  30. }
  31. type LogFilter struct {
  32. UserID string
  33. TaskIDs []string
  34. ItemIDs []string
  35. MinTime *time.Time
  36. MaxTime *time.Time
  37. }
  38. type LogRepository interface {
  39. Find(ctx context.Context, id string) (*Log, error)
  40. List(ctx context.Context, filter LogFilter) ([]*Log, error)
  41. Insert(ctx context.Context, log Log) error
  42. Update(ctx context.Context, log Log) error
  43. Delete(ctx context.Context, log Log) error
  44. }