feat(platform): add the notification inbox and deterministic match search
This commit is contained in:
1 parent
5edff21d2d
commit
0b11021b16
169 files changed
+17083
-443
No files matched your search
@@ -0,0 +1,44 @@
|
||||
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/notification"
|
||||
)
|
||||
|
||||
const notificationPoolMaxConns = 4
|
||||
|
||||
// newNotificationHandler builds the inbox operations and the PostgreSQL pool
|
||||
// they own. Nothing connects here, so an unavailable database never blocks
|
||||
// startup. It returns no handler when DATABASE_URL is unset, and the
|
||||
// operations then answer 501.
|
||||
func newNotificationHandler(
|
||||
ctx context.Context,
|
||||
settings config.Config,
|
||||
logger *slog.Logger,
|
||||
) (*v1.NotificationHandler, func(), error) {
|
||||
if settings.DatabaseURL == "" {
|
||||
logger.Warn("notification inbox operations are not served because DATABASE_URL is not set")
|
||||
return nil, func() {}, nil
|
||||
}
|
||||
pool, err := postgres.NewSizedPool(ctx, settings.DatabaseURL, notificationPoolMaxConns)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("bootstrap.newNotificationHandler - create pool: %w", err)
|
||||
}
|
||||
service, err := notification.NewInboxService(
|
||||
postgres.NewTransactor(pool),
|
||||
notification.NewInboxContentResolver(notification.DefaultInboxSourceResolvers(settings.NotificationSyntheticEnabled)),
|
||||
time.Now,
|
||||
)
|
||||
if err != nil {
|
||||
pool.Close()
|
||||
return nil, nil, fmt.Errorf("bootstrap.newNotificationHandler - create service: %w", err)
|
||||
}
|
||||
return v1.NewNotificationHandler(service), pool.Close, nil
|
||||
}
|
||||
Reference in new issue
Block a user