Prototype plugin

This commit is contained in:
Niko Abeler 2023-08-09 21:56:56 +02:00
parent d4351af8f1
commit 9322e59b96
4 changed files with 47 additions and 5 deletions

View File

@ -10,10 +10,17 @@ import (
type EntryService struct {
EntryRepository repository.EntryRepository
CreationBus *EntryCreationBus
}
func NewEntryService(entryRepository repository.EntryRepository) *EntryService {
return &EntryService{EntryRepository: entryRepository}
func NewEntryService(
entryRepository repository.EntryRepository,
creationBus *EntryCreationBus,
) *EntryService {
return &EntryService{
EntryRepository: entryRepository,
CreationBus: creationBus,
}
}
func (s *EntryService) Create(entry model.Entry) error {
@ -33,7 +40,12 @@ func (s *EntryService) Create(entry model.Entry) error {
}
entry.SetID(title)
return s.EntryRepository.Create(entry)
err := s.EntryRepository.Create(entry)
if err != nil {
return err
}
s.CreationBus.Notify(entry)
return nil
}
func (s *EntryService) Update(entry model.Entry) error {

View File

@ -14,7 +14,7 @@ func setupService() *app.EntryService {
register := app.NewEntryTypeRegistry()
register.Register(&test.MockEntry{})
repo := infra.NewEntryRepository(db, register)
service := app.NewEntryService(repo)
service := app.NewEntryService(repo, app.NewEntryCreationBus())
return service
}

View File

@ -7,6 +7,7 @@ import (
entrytypes "owl-blogs/entry_types"
"owl-blogs/infra"
"owl-blogs/interactions"
"owl-blogs/plugings"
"owl-blogs/web"
"github.com/spf13/cobra"
@ -52,8 +53,14 @@ func App(db infra.Database) *web.WebApp {
// Create External Services
httpClient := &infra.OwlHttpClient{}
// busses
entryCreationBus := app.NewEntryCreationBus()
// plugins
plugings.NewEcho(entryCreationBus)
// Create Services
entryService := app.NewEntryService(entryRepo)
entryService := app.NewEntryService(entryRepo, entryCreationBus)
binaryService := app.NewBinaryFileService(binRepo)
authorService := app.NewAuthorService(authorRepo, siteConfigRepo)
webmentionService := app.NewWebmentionService(

23
plugings/echo.go Normal file
View File

@ -0,0 +1,23 @@
package plugings
import (
"fmt"
"owl-blogs/app"
"owl-blogs/domain/model"
)
type Echo struct {
}
func NewEcho(bus *app.EntryCreationBus) *Echo {
echo := &Echo{}
bus.Subscribe(echo)
return echo
}
func (e *Echo) NotifyEntryCreation(entry model.Entry) {
fmt.Println("Entry Created:")
fmt.Println("\tID: ", entry.ID())
fmt.Println("\tTitle: ", entry.Title())
fmt.Println("\tPublishedAt: ", entry.PublishedAt())
}