sp.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package sp
  2. import (
  3. "git.dmitriygnatenko.ru/dima/homethings/internal/repositories"
  4. authService "git.dmitriygnatenko.ru/dima/homethings/internal/services/auth"
  5. dbService "git.dmitriygnatenko.ru/dima/homethings/internal/services/db"
  6. envService "git.dmitriygnatenko.ru/dima/homethings/internal/services/env"
  7. mailerService "git.dmitriygnatenko.ru/dima/homethings/internal/services/mailer"
  8. )
  9. type ServiceProvider struct {
  10. env *envService.Service
  11. auth *authService.Service
  12. mailer *mailerService.Service
  13. placeRepository *repositories.PlaceRepository
  14. thingRepository *repositories.ThingRepository
  15. tagRepository *repositories.TagRepository
  16. placeThingRepository *repositories.PlaceThingRepository
  17. placeImageRepository *repositories.PlaceImageRepository
  18. thingImageRepository *repositories.ThingImageRepository
  19. thingTagRepository *repositories.ThingTagRepository
  20. userRepository *repositories.UserRepository
  21. thingNotificationRepository *repositories.ThingNotificationRepository
  22. fileRepository *repositories.FileRepository
  23. }
  24. func Init() (*ServiceProvider, error) {
  25. sp := &ServiceProvider{}
  26. env, err := envService.Init()
  27. if err != nil {
  28. return nil, err
  29. }
  30. sp.env = env
  31. auth, err := authService.Init(env)
  32. if err != nil {
  33. return nil, err
  34. }
  35. sp.auth = auth
  36. mailer, err := mailerService.Init(env)
  37. if err != nil {
  38. return nil, err
  39. }
  40. sp.mailer = mailer
  41. db, err := dbService.Init(env)
  42. if err != nil {
  43. return nil, err
  44. }
  45. // Init repositories
  46. sp.placeRepository = repositories.InitPlaceRepository(db)
  47. sp.thingRepository = repositories.InitThingRepository(db)
  48. sp.placeThingRepository = repositories.InitPlaceThingRepository(db)
  49. sp.placeImageRepository = repositories.InitPlaceImageRepository(db)
  50. sp.thingImageRepository = repositories.InitThingImageRepository(db)
  51. sp.tagRepository = repositories.InitTagRepository(db)
  52. sp.thingTagRepository = repositories.InitThingTagRepository(db)
  53. sp.userRepository = repositories.InitUserRepository(db)
  54. sp.thingNotificationRepository = repositories.InitThingNotificationRepository(db)
  55. sp.fileRepository = repositories.InitFileRepository()
  56. return sp, nil
  57. }
  58. func (sp *ServiceProvider) GetEnvService() *envService.Service {
  59. return sp.env
  60. }
  61. func (sp *ServiceProvider) GetAuthService() *authService.Service {
  62. return sp.auth
  63. }
  64. func (sp *ServiceProvider) GetMailerService() *mailerService.Service {
  65. return sp.mailer
  66. }
  67. func (sp *ServiceProvider) GetPlaceRepository() *repositories.PlaceRepository {
  68. return sp.placeRepository
  69. }
  70. func (sp *ServiceProvider) GetThingRepository() *repositories.ThingRepository {
  71. return sp.thingRepository
  72. }
  73. func (sp *ServiceProvider) GetTagRepository() *repositories.TagRepository {
  74. return sp.tagRepository
  75. }
  76. func (sp *ServiceProvider) GetPlaceThingRepository() *repositories.PlaceThingRepository {
  77. return sp.placeThingRepository
  78. }
  79. func (sp *ServiceProvider) GetPlaceImageRepository() *repositories.PlaceImageRepository {
  80. return sp.placeImageRepository
  81. }
  82. func (sp *ServiceProvider) GetThingImageRepository() *repositories.ThingImageRepository {
  83. return sp.thingImageRepository
  84. }
  85. func (sp *ServiceProvider) GetThingTagRepository() *repositories.ThingTagRepository {
  86. return sp.thingTagRepository
  87. }
  88. func (sp *ServiceProvider) GetThingNotificationRepository() *repositories.ThingNotificationRepository {
  89. return sp.thingNotificationRepository
  90. }
  91. func (sp *ServiceProvider) GetUserRepository() *repositories.UserRepository {
  92. return sp.userRepository
  93. }
  94. func (sp *ServiceProvider) GetFileRepository() *repositories.FileRepository {
  95. return sp.fileRepository
  96. }