Add backend foundation and config-driven workbench
This commit is contained in:
32
backend/internal/service/dev_service.go
Normal file
32
backend/internal/service/dev_service.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"cmr-backend/internal/apperr"
|
||||
"cmr-backend/internal/store/postgres"
|
||||
)
|
||||
|
||||
type DevService struct {
|
||||
appEnv string
|
||||
store *postgres.Store
|
||||
}
|
||||
|
||||
func NewDevService(appEnv string, store *postgres.Store) *DevService {
|
||||
return &DevService{
|
||||
appEnv: appEnv,
|
||||
store: store,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DevService) Enabled() bool {
|
||||
return s.appEnv != "production"
|
||||
}
|
||||
|
||||
func (s *DevService) BootstrapDemo(ctx context.Context) (*postgres.DemoBootstrapSummary, error) {
|
||||
if !s.Enabled() {
|
||||
return nil, apperr.New(http.StatusNotFound, "not_found", "dev bootstrap is disabled")
|
||||
}
|
||||
return s.store.EnsureDemoData(ctx)
|
||||
}
|
||||
Reference in New Issue
Block a user