28 lines
795 B
Go
28 lines
795 B
Go
package bootstrap
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"lincodex/backend/config"
|
|
v1 "lincodex/backend/internal/adapter/primary/http/v1"
|
|
"lincodex/backend/internal/adapter/secondary/postgres"
|
|
"lincodex/backend/internal/usecase/consent"
|
|
)
|
|
|
|
const consentPoolMaxConns = 4
|
|
|
|
func newConsentHandler(ctx context.Context, settings config.Config) (*v1.ConsentHandler, func(), error) {
|
|
if settings.DatabaseURL == "" {
|
|
return nil, func() {}, nil
|
|
}
|
|
pool, err := postgres.NewSizedPool(ctx, settings.DatabaseURL, consentPoolMaxConns)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
store := postgres.NewConsentStore(pool)
|
|
reader := consent.NewQueryService(store, time.Now)
|
|
commands := consent.NewService(postgres.NewTransactor(pool), time.Now)
|
|
return v1.NewConsentHandler(reader, commands), pool.Close, nil
|
|
}
|