Files
lincodex/backend/internal/bootstrap/profile.go
T

28 lines
840 B
Go

package bootstrap
import (
"context"
"log/slog"
"time"
"lincodex/backend/config"
v1 "lincodex/backend/internal/adapter/primary/http/v1"
"lincodex/backend/internal/adapter/secondary/postgres"
profileusecase "lincodex/backend/internal/usecase/profile"
)
const profilePoolMaxConns = 8
func newProfileHandler(ctx context.Context, settings config.Config, logger *slog.Logger) (*v1.ProfileHandler, func(), error) {
if settings.DatabaseURL == "" {
logger.Warn("candidate profile operations are not served because DATABASE_URL is not set")
return nil, func() {}, nil
}
pool, err := postgres.NewSizedPool(ctx, settings.DatabaseURL, profilePoolMaxConns)
if err != nil {
return nil, nil, err
}
service := profileusecase.NewService(postgres.NewTransactor(pool), time.Now)
return v1.NewProfileHandler(service), pool.Close, nil
}