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.

75 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. if spaceClient != nil {
  30. bundle.Files = &FileService{
  31. files: db.Files(),
  32. authService: bundle.Auth,
  33. changeService: bundle.Changes,
  34. space: spaceClient,
  35. }
  36. }
  37. bundle.Tags = &TagService{tags: db.Tags()}
  38. bundle.Characters = &CharacterService{
  39. characters: db.Characters(),
  40. loader: loaders.CharacterLoaderFromRepository(db.Characters()),
  41. changeService: bundle.Changes,
  42. authService: bundle.Auth,
  43. }
  44. bundle.Channels = &ChannelService{
  45. channels: db.Channels(),
  46. loader: loaders.ChannelLoaderFromRepository(db.Channels()),
  47. changeService: bundle.Changes,
  48. authService: bundle.Auth,
  49. }
  50. bundle.Logs = &LogService{
  51. logs: db.Logs(),
  52. posts: db.Posts(),
  53. changeService: bundle.Changes,
  54. channelService: bundle.Channels,
  55. characterService: bundle.Characters,
  56. authService: bundle.Auth,
  57. unknownNicks: make(map[string]int, 512),
  58. }
  59. bundle.Stories = &StoryService{
  60. stories: db.Stories(),
  61. chapters: db.Chapters(),
  62. comments: db.Comments(),
  63. changeService: bundle.Changes,
  64. characterService: bundle.Characters,
  65. authService: bundle.Auth,
  66. }
  67. bundle.Characters.logService = bundle.Logs
  68. return bundle
  69. }