GraphQL API and utilities for the rpdata project
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.3 KiB

  1. package services
  2. import (
  3. "git.aiterp.net/rpdata/api/database"
  4. "git.aiterp.net/rpdata/api/services/loaders"
  5. )
  6. // A Bundle contains all services.
  7. type Bundle struct {
  8. Tags *TagService
  9. Characters *CharacterService
  10. Changes *ChangeService
  11. Logs *LogService
  12. Channels *ChannelService
  13. Stories *StoryService
  14. }
  15. // NewBundle creates a new bundle.
  16. func NewBundle(db database.Database) *Bundle {
  17. bundle := &Bundle{}
  18. bundle.Changes = &ChangeService{
  19. changes: db.Changes(),
  20. }
  21. bundle.Tags = &TagService{tags: db.Tags()}
  22. bundle.Characters = &CharacterService{
  23. characters: db.Characters(),
  24. loader: loaders.CharacterLoaderFromRepository(db.Characters()),
  25. changeService: bundle.Changes,
  26. }
  27. bundle.Channels = &ChannelService{
  28. channels: db.Channels(),
  29. loader: loaders.ChannelLoaderFromRepository(db.Channels()),
  30. changeService: bundle.Changes,
  31. }
  32. bundle.Logs = &LogService{
  33. logs: db.Logs(),
  34. posts: db.Posts(),
  35. changeService: bundle.Changes,
  36. channelService: bundle.Channels,
  37. characterService: bundle.Characters,
  38. }
  39. bundle.Stories = &StoryService{
  40. stories: db.Stories(),
  41. chapters: db.Chapters(),
  42. comments: db.Comments(),
  43. changeService: bundle.Changes,
  44. characterService: bundle.Characters,
  45. }
  46. return bundle
  47. }