Skip to content

Commit

Permalink
Hook up events bb adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
petyos committed Jan 16, 2024
1 parent ecf2cc6 commit 6742db4
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
12 changes: 9 additions & 3 deletions core/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ type Application struct {

storage interfaces.Storage

eventsBBAdapter interfaces.EventsBBAdapter

//events logic
eventsLogic eventsLogic
}
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
7 changes: 7 additions & 0 deletions core/interfaces/driven.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions core/logic_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package core

import (
"application/core/interfaces"
"application/core/model"
"encoding/xml"
"fmt"
Expand All @@ -31,6 +32,8 @@ import (
type eventsLogic struct {
app *Application
logger *logs.Logger

eventsBBAdapter interfaces.EventsBBAdapter
}

func (e eventsLogic) start() {
Expand Down Expand Up @@ -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}
}
8 changes: 4 additions & 4 deletions driven/eventsbb/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6742db4

Please sign in to comment.