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.

68 lines
1.7 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. Auth *AuthService
  15. Files *FileService
  16. }
  17. // NewBundle creates a new bundle.
  18. func NewBundle(db database.Database) *Bundle {
  19. bundle := &Bundle{}
  20. bundle.Auth = &AuthService{
  21. keys: db.Keys(),
  22. users: db.Users(),
  23. }
  24. bundle.Files = &FileService{
  25. files: nil,
  26. authService: bundle.Auth,
  27. }
  28. bundle.Changes = &ChangeService{
  29. changes: db.Changes(),
  30. authService: bundle.Auth,
  31. }
  32. bundle.Tags = &TagService{tags: db.Tags()}
  33. bundle.Characters = &CharacterService{
  34. characters: db.Characters(),
  35. loader: loaders.CharacterLoaderFromRepository(db.Characters()),
  36. changeService: bundle.Changes,
  37. authService: bundle.Auth,
  38. }
  39. bundle.Channels = &ChannelService{
  40. channels: db.Channels(),
  41. loader: loaders.ChannelLoaderFromRepository(db.Channels()),
  42. changeService: bundle.Changes,
  43. authService: bundle.Auth,
  44. }
  45. bundle.Logs = &LogService{
  46. logs: db.Logs(),
  47. posts: db.Posts(),
  48. changeService: bundle.Changes,
  49. channelService: bundle.Channels,
  50. characterService: bundle.Characters,
  51. authService: bundle.Auth,
  52. unknownNicks: make(map[string]int, 512),
  53. }
  54. bundle.Stories = &StoryService{
  55. stories: db.Stories(),
  56. chapters: db.Chapters(),
  57. comments: db.Comments(),
  58. changeService: bundle.Changes,
  59. characterService: bundle.Characters,
  60. authService: bundle.Auth,
  61. }
  62. return bundle
  63. }