Plan stuff. Log stuff.
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.

45 lines
982 B

  1. package models
  2. import "github.com/gisle/stufflog/internal/generate"
  3. type Item struct {
  4. ID string `json:"id" msgpack:"id"`
  5. UserID string `json:"userId" msgpack:"userId"`
  6. Active bool `json:"active" msgpack:"active"`
  7. Name string `json:"name" msgpack:"name"`
  8. Multiplier float64 `json:"multiplier" msgpack:"multiplier"`
  9. }
  10. func (item *Item) GenerateID() {
  11. item.ID = generate.ID("I", 16)
  12. }
  13. func (item *Item) ApplyUpdate(update ItemUpdate) error {
  14. if update.SetActive != nil {
  15. item.Active = *update.SetActive
  16. }
  17. if update.SetName != nil {
  18. item.Name = *update.SetName
  19. }
  20. return nil
  21. }
  22. type ItemUpdate struct {
  23. SetName *string `json:"setName"`
  24. SetActive *bool `json:"setActive"`
  25. }
  26. type ItemsByName []*Item
  27. func (items ItemsByName) Len() int {
  28. return len(items)
  29. }
  30. func (items ItemsByName) Less(i, j int) bool {
  31. return items[i].Name < items[j].Name
  32. }
  33. func (items ItemsByName) Swap(i, j int) {
  34. items[i], items[j] = items[j], items[i]
  35. }