Skip to content

Commit

Permalink
chore: refactor library to use usecases
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwellgithinji committed Sep 6, 2021
1 parent 3195cee commit b6525ec
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
63 changes: 63 additions & 0 deletions pkg/engagement/usecases/library/library.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package library

import (
"context"

"github.com/savannahghi/engagementcore/pkg/engagement/domain"
"github.com/savannahghi/engagementcore/pkg/engagement/infrastructure"
"github.com/savannahghi/feedlib"
)

// UsecaseLibrary defines Libray service usecases interface
type UsecaseLibrary interface {
GetFeedContent(
ctx context.Context,
flavour feedlib.Flavour,
) ([]*domain.GhostCMSPost, error)
GetFaqsContent(
ctx context.Context,
flavour feedlib.Flavour,
) ([]*domain.GhostCMSPost, error)
GetLibraryContent(
ctx context.Context,
) ([]*domain.GhostCMSPost, error)
}

// ImplLibrary is the library service implementation
type ImplLibrary struct {
infrastructure infrastructure.Interactor
}

// NewLibrary initializes a Library service instance
func NewLibrary(infrastructure infrastructure.Interactor) *ImplLibrary {
return &ImplLibrary{
infrastructure: infrastructure,
}
}

// GetFeedContent gets feed content from ghost cms
func (l *ImplLibrary) GetFeedContent(
ctx context.Context,
flavour feedlib.Flavour,
) ([]*domain.GhostCMSPost, error) {
i := l.infrastructure.ServiceLibraryImpl
return i.GetFeedContent(ctx, flavour)
}

// GetFaqsContent gets FAQ content from ghost cms
func (l *ImplLibrary) GetFaqsContent(
ctx context.Context,
flavour feedlib.Flavour,
) ([]*domain.GhostCMSPost, error) {
i := l.infrastructure.ServiceLibraryImpl
return i.GetFaqsContent(ctx, flavour)

}

// GetLibraryContent gets Library content from ghost cms
func (l *ImplLibrary) GetLibraryContent(
ctx context.Context,
) ([]*domain.GhostCMSPost, error) {
i := l.infrastructure.ServiceLibraryImpl
return i.GetLibraryContent(ctx)
}
4 changes: 4 additions & 0 deletions pkg/engagement/usecases/usecases.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@ package usecases
import (
"github.com/savannahghi/engagementcore/pkg/engagement/infrastructure"
"github.com/savannahghi/engagementcore/pkg/engagement/usecases/feed"
"github.com/savannahghi/engagementcore/pkg/engagement/usecases/library"
)

// Interactor is an implementation of the usecases interface
type Interactor struct {
*feed.UseCaseImpl
*feed.NotificationImpl
*library.ImplLibrary
}

// NewInteractor initializes a new usecases interactor
func NewInteractor(infrastructure infrastructure.Interactor) Interactor {

notification := feed.NewNotification(infrastructure)
feed := feed.NewFeed(infrastructure)
library := library.NewLibrary(infrastructure)

return Interactor{
feed,
notification,
library,
}
}

0 comments on commit b6525ec

Please sign in to comment.