The new logbot, not committed from the wrong terminal window this time.
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.

61 lines
1.1 KiB

  1. package changes
  2. import (
  3. "context"
  4. "encoding/json"
  5. "time"
  6. "git.aiterp.net/rpdata/logbot3/internal/api"
  7. "git.aiterp.net/rpdata/logbot3/internal/models"
  8. )
  9. // The Filter for List.
  10. type Filter struct {
  11. Keys []models.ChangeKey `json:"keys,omitempty"`
  12. EarliestDate *time.Time `json:"earliestDate,omitempty"`
  13. Limit int `json:"limit,omitempty"`
  14. }
  15. // List lists all changes according to the filter.
  16. func List(ctx context.Context, filter *Filter) ([]models.Change, error) {
  17. data, err := api.Global().Query(ctx, listGQL, map[string]interface{}{"filter": filter}, nil)
  18. if err != nil {
  19. return nil, err
  20. }
  21. res := listResult{}
  22. err = json.Unmarshal(data, &res)
  23. return res.Changes, err
  24. }
  25. type listResult struct {
  26. Changes []models.Change `json:"changes"`
  27. }
  28. var listGQL = `
  29. query ListChanges($filter:ChangesFilter) {
  30. changes(filter:$filter) {
  31. id
  32. model
  33. op
  34. author
  35. listed
  36. date
  37. keys {
  38. model
  39. id
  40. }
  41. objects {
  42. __typename
  43. ...on Channel {
  44. name
  45. logged
  46. hub
  47. eventName
  48. locationName
  49. }
  50. }
  51. }
  52. }
  53. `