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.2 KiB

3 years ago
  1. package models
  2. import "context"
  3. type Item struct {
  4. ID string `json:"id" db:"item_id"`
  5. UserID string `json:"-" db:"user_id"`
  6. GroupID string `json:"groupId" db:"group_id"`
  7. GroupWeight int `json:"groupWeight" db:"group_weight"`
  8. Icon string `json:"icon" db:"icon"`
  9. Name string `json:"name" db:"name"`
  10. Description string `json:"description" db:"description"`
  11. }
  12. func (item *Item) Update(update ItemUpdate) {
  13. if update.GroupWeight != nil {
  14. item.GroupWeight = *update.GroupWeight
  15. }
  16. if update.Name != nil {
  17. item.Name = *update.Name
  18. }
  19. if update.Description != nil {
  20. item.Description = *update.Description
  21. }
  22. }
  23. type ItemUpdate struct {
  24. GroupWeight *int `json:"groupWeight"`
  25. Name *string `json:"name"`
  26. Description *string `json:"description"`
  27. }
  28. type ItemResult struct {
  29. Item
  30. Group *Group `json:"group"`
  31. }
  32. type ItemFilter struct {
  33. UserID string
  34. IDs []string
  35. GroupIDs []string
  36. }
  37. type ItemRepository interface {
  38. Find(ctx context.Context, id string) (*Item, error)
  39. List(ctx context.Context, filter ItemFilter) ([]*Item, error)
  40. Insert(ctx context.Context, item Item) error
  41. Update(ctx context.Context, item Item) error
  42. Delete(ctx context.Context, item Item) error
  43. }