feat(accounts): add consent settings and organization management
This commit is contained in:
1 parent
24638d46d2
commit
391af7a1ef
83 files changed
+10198
-613
No files matched your search
@@ -0,0 +1,48 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"lincodex/backend/config"
|
||||
v1 "lincodex/backend/internal/adapter/primary/http/v1"
|
||||
"lincodex/backend/internal/adapter/secondary/postgres"
|
||||
"lincodex/backend/internal/usecase/identity"
|
||||
"lincodex/backend/internal/usecase/organization"
|
||||
)
|
||||
|
||||
const organizationPoolMaxConns = 8
|
||||
|
||||
// newOrganizationHandler builds company reads and writes from the PostgreSQL
|
||||
// transaction boundary. Without DATABASE_URL the composite handler keeps the
|
||||
// operations on its 501 fallback.
|
||||
func newOrganizationHandler(
|
||||
ctx context.Context,
|
||||
settings config.Config,
|
||||
logger *slog.Logger,
|
||||
keyring *identity.Keyring,
|
||||
) (*v1.OrganizationHandler, func(), error) {
|
||||
if settings.DatabaseURL == "" {
|
||||
logger.Warn("organization operations are not served because DATABASE_URL is not set")
|
||||
return nil, func() {}, nil
|
||||
}
|
||||
if keyring == nil {
|
||||
return nil, nil, fmt.Errorf("bootstrap.newOrganizationHandler - identity keyring must be set")
|
||||
}
|
||||
pool, err := postgres.NewSizedPool(ctx, settings.DatabaseURL, organizationPoolMaxConns)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("bootstrap.newOrganizationHandler - create pool: %w", err)
|
||||
}
|
||||
service, err := organization.NewService(organization.Dependencies{
|
||||
Transactor: postgres.NewTransactor(pool),
|
||||
Keyring: keyring,
|
||||
Clock: time.Now,
|
||||
})
|
||||
if err != nil {
|
||||
pool.Close()
|
||||
return nil, nil, fmt.Errorf("bootstrap.newOrganizationHandler - create service: %w", err)
|
||||
}
|
||||
return v1.NewOrganizationHandler(service, settings.AppPublicURL), pool.Close, nil
|
||||
}
|
||||
Reference in new issue
Block a user