dev_service.go 643 B

1234567891011121314151617181920212223242526272829303132
  1. package service
  2. import (
  3. "context"
  4. "net/http"
  5. "cmr-backend/internal/apperr"
  6. "cmr-backend/internal/store/postgres"
  7. )
  8. type DevService struct {
  9. appEnv string
  10. store *postgres.Store
  11. }
  12. func NewDevService(appEnv string, store *postgres.Store) *DevService {
  13. return &DevService{
  14. appEnv: appEnv,
  15. store: store,
  16. }
  17. }
  18. func (s *DevService) Enabled() bool {
  19. return s.appEnv != "production"
  20. }
  21. func (s *DevService) BootstrapDemo(ctx context.Context) (*postgres.DemoBootstrapSummary, error) {
  22. if !s.Enabled() {
  23. return nil, apperr.New(http.StatusNotFound, "not_found", "dev bootstrap is disabled")
  24. }
  25. return s.store.EnsureDemoData(ctx)
  26. }