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.

73 lines
1.9 KiB

  1. package services
  2. import (
  3. "git.aiterp.net/rpdata/api/database"
  4. "git.aiterp.net/rpdata/api/services/loaders"
  5. "git.aiterp.net/rpdata/api/space"
  6. )
  7. // A Bundle contains all services.
  8. type Bundle struct {
  9. Tags *TagService
  10. Characters *CharacterService
  11. Changes *ChangeService
  12. Logs *LogService
  13. Channels *ChannelService
  14. Stories *StoryService
  15. Auth *AuthService
  16. Files *FileService
  17. }
  18. // NewBundle creates a new bundle.
  19. func NewBundle(db database.Database, spaceClient *space.Client) *Bundle {
  20. bundle := &Bundle{}
  21. bundle.Auth = &AuthService{
  22. keys: db.Keys(),
  23. users: db.Users(),
  24. }
  25. bundle.Changes = &ChangeService{
  26. changes: db.Changes(),
  27. authService: bundle.Auth,
  28. }
  29. bundle.Files = &FileService{
  30. files: db.Files(),
  31. authService: bundle.Auth,
  32. changeService: bundle.Changes,
  33. space: spaceClient,
  34. }
  35. bundle.Tags = &TagService{tags: db.Tags()}
  36. bundle.Characters = &CharacterService{
  37. characters: db.Characters(),
  38. loader: loaders.CharacterLoaderFromRepository(db.Characters()),
  39. changeService: bundle.Changes,
  40. authService: bundle.Auth,
  41. }
  42. bundle.Channels = &ChannelService{
  43. channels: db.Channels(),
  44. loader: loaders.ChannelLoaderFromRepository(db.Channels()),
  45. changeService: bundle.Changes,
  46. authService: bundle.Auth,
  47. }
  48. bundle.Logs = &LogService{
  49. logs: db.Logs(),
  50. posts: db.Posts(),
  51. changeService: bundle.Changes,
  52. channelService: bundle.Channels,
  53. characterService: bundle.Characters,
  54. authService: bundle.Auth,
  55. unknownNicks: make(map[string]int, 512),
  56. }
  57. bundle.Stories = &StoryService{
  58. stories: db.Stories(),
  59. chapters: db.Chapters(),
  60. comments: db.Comments(),
  61. changeService: bundle.Changes,
  62. characterService: bundle.Characters,
  63. authService: bundle.Auth,
  64. }
  65. bundle.Characters.logService = bundle.Logs
  66. return bundle
  67. }