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.

50 lines
1.1 KiB

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. }
  30. type LogFilter struct {
  31. UserID string
  32. IDs []string
  33. ItemIDs []string
  34. MinTime *time.Time
  35. MaxTime *time.Time
  36. }
  37. type LogRepository interface {
  38. Find(ctx context.Context, id string) (*Log, error)
  39. List(ctx context.Context, filter LogFilter) ([]*Log, error)
  40. Insert(ctx context.Context, log Log) error
  41. Update(ctx context.Context, log Log) error
  42. Delete(ctx context.Context, log Log) error
  43. }