diff --git a/core/application.go b/core/application.go index 6add6484..2cf785cd 100644 --- a/core/application.go +++ b/core/application.go @@ -55,6 +55,8 @@ type Application struct { storage interfaces.Storage + eventsBBAdapter interfaces.EventsBBAdapter + //events logic eventsLogic eventsLogic } @@ -82,8 +84,12 @@ func (a *Application) GetEnvConfigs() (*model.EnvConfigData, error) { } // NewApplication creates new Application -func NewApplication(version string, build string, storage interfaces.Storage, appntAdapters map[string]interfaces.Appointments, logger *logs.Logger) *Application { - application := Application{version: version, build: build, storage: storage, logger: logger, AppointmentAdapters: appntAdapters} +func NewApplication(version string, build string, + storage interfaces.Storage, + eventsBBAdapter interfaces.EventsBBAdapter, + appntAdapters map[string]interfaces.Appointments, + logger *logs.Logger) *Application { + application := Application{version: version, build: build, storage: storage, eventsBBAdapter: eventsBBAdapter, logger: logger, AppointmentAdapters: appntAdapters} //add the drivers ports/interfaces application.Default = newAppDefault(&application) @@ -93,7 +99,7 @@ func NewApplication(version string, build string, storage interfaces.Storage, ap application.TPS = newAppTPS(&application) application.System = newAppSystem(&application) application.shared = newAppShared(&application) - application.eventsLogic = newAppEventsLogic(&application) + application.eventsLogic = newAppEventsLogic(&application, eventsBBAdapter) return &application } diff --git a/core/interfaces/driven.go b/core/interfaces/driven.go index 66a2c2f5..471aa2f6 100644 --- a/core/interfaces/driven.go +++ b/core/interfaces/driven.go @@ -17,8 +17,15 @@ package interfaces import ( "application/core/model" "time" + + "github.com/rokwire/logging-library-go/v2/logs" ) +// EventsBBAdapter is used by core to communicate with the events BB +type EventsBBAdapter interface { + LoadAllLegacyEvents(log *logs.Log) ([]model.LegacyEvent, error) +} + // Storage is used by core to storage data - DB storage adapter, file storage adapter etc type Storage interface { RegisterStorageListener(listener StorageListener) diff --git a/core/logic_events.go b/core/logic_events.go index 9d6bad95..bc8e4e00 100644 --- a/core/logic_events.go +++ b/core/logic_events.go @@ -18,6 +18,7 @@ package core import ( + "application/core/interfaces" "application/core/model" "encoding/xml" "fmt" @@ -31,6 +32,8 @@ import ( type eventsLogic struct { app *Application logger *logs.Logger + + eventsBBAdapter interfaces.EventsBBAdapter } func (e eventsLogic) start() { @@ -119,6 +122,6 @@ func (e eventsLogic) getAllEvents() ([]model.WebToolsEvent, error) { } // newAppEventsLogic creates new appShared -func newAppEventsLogic(app *Application) eventsLogic { - return eventsLogic{app: app} +func newAppEventsLogic(app *Application, eventsBBAdapter interfaces.EventsBBAdapter) eventsLogic { + return eventsLogic{app: app, eventsBBAdapter: eventsBBAdapter} } diff --git a/driven/eventsbb/adapter.go b/driven/eventsbb/adapter.go index e2ea3304..375a8454 100644 --- a/driven/eventsbb/adapter.go +++ b/driven/eventsbb/adapter.go @@ -31,15 +31,15 @@ type Adapter struct { } // NewEventsBBAdapter creates new instance -func NewEventsBBAdapter(legacyEventsBaseURL, legacyEventsAPIKey string) *Adapter { - return &Adapter{ +func NewEventsBBAdapter(legacyEventsBaseURL, legacyEventsAPIKey string) Adapter { + return Adapter{ baseURL: legacyEventsBaseURL, apiKey: legacyEventsAPIKey, // pragma: allowlist secret } } -// LoadAllLegacyEvents sends notification to a user -func (na *Adapter) LoadAllLegacyEvents(log *logs.Log) ([]model.LegacyEvent, error) { +// LoadAllLegacyEvents loads all legacy events +func (na Adapter) LoadAllLegacyEvents(log *logs.Log) ([]model.LegacyEvent, error) { url := fmt.Sprintf("%s/events", na.baseURL) diff --git a/main.go b/main.go index 0eda151a..71fd7191 100644 --- a/main.go +++ b/main.go @@ -17,10 +17,10 @@ package main import ( "application/core" "application/core/interfaces" + "application/driven/eventsbb" "application/driven/storage" "application/driven/uiucadapters" "application/driver/web" - "log" "strings" "github.com/rokwire/core-auth-library-go/v3/authservice" @@ -65,14 +65,15 @@ func main() { } // events bb adapter + eventsBBBaseURL := envLoader.GetAndLogEnvVar(envPrefix+"EVENTS_BB_BASE_URL", true, true) eventsBBAPIKey := envLoader.GetAndLogEnvVar(envPrefix+"EVENTS_BB_ROKWIRE_API_KEY", true, true) - log.Println(eventsBBAPIKey) + eventsBBAdapter := eventsbb.NewEventsBBAdapter(eventsBBBaseURL, eventsBBAPIKey) // appointment adapters appointments := make(map[string]interfaces.Appointments) appointments["2"] = uiucadapters.NewEngineeringAppontmentsAdapter("KP") // application - application := core.NewApplication(Version, Build, storageAdapter, appointments, logger) + application := core.NewApplication(Version, Build, storageAdapter, eventsBBAdapter, appointments, logger) application.Start() // web adapter