Prototype plugin
This commit is contained in:
parent
d4351af8f1
commit
9322e59b96
|
@ -10,10 +10,17 @@ import (
|
||||||
|
|
||||||
type EntryService struct {
|
type EntryService struct {
|
||||||
EntryRepository repository.EntryRepository
|
EntryRepository repository.EntryRepository
|
||||||
|
CreationBus *EntryCreationBus
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEntryService(entryRepository repository.EntryRepository) *EntryService {
|
func NewEntryService(
|
||||||
return &EntryService{EntryRepository: entryRepository}
|
entryRepository repository.EntryRepository,
|
||||||
|
creationBus *EntryCreationBus,
|
||||||
|
) *EntryService {
|
||||||
|
return &EntryService{
|
||||||
|
EntryRepository: entryRepository,
|
||||||
|
CreationBus: creationBus,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *EntryService) Create(entry model.Entry) error {
|
func (s *EntryService) Create(entry model.Entry) error {
|
||||||
|
@ -33,7 +40,12 @@ func (s *EntryService) Create(entry model.Entry) error {
|
||||||
}
|
}
|
||||||
entry.SetID(title)
|
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 {
|
func (s *EntryService) Update(entry model.Entry) error {
|
||||||
|
|
|
@ -14,7 +14,7 @@ func setupService() *app.EntryService {
|
||||||
register := app.NewEntryTypeRegistry()
|
register := app.NewEntryTypeRegistry()
|
||||||
register.Register(&test.MockEntry{})
|
register.Register(&test.MockEntry{})
|
||||||
repo := infra.NewEntryRepository(db, register)
|
repo := infra.NewEntryRepository(db, register)
|
||||||
service := app.NewEntryService(repo)
|
service := app.NewEntryService(repo, app.NewEntryCreationBus())
|
||||||
return service
|
return service
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
entrytypes "owl-blogs/entry_types"
|
entrytypes "owl-blogs/entry_types"
|
||||||
"owl-blogs/infra"
|
"owl-blogs/infra"
|
||||||
"owl-blogs/interactions"
|
"owl-blogs/interactions"
|
||||||
|
"owl-blogs/plugings"
|
||||||
"owl-blogs/web"
|
"owl-blogs/web"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
@ -52,8 +53,14 @@ func App(db infra.Database) *web.WebApp {
|
||||||
// Create External Services
|
// Create External Services
|
||||||
httpClient := &infra.OwlHttpClient{}
|
httpClient := &infra.OwlHttpClient{}
|
||||||
|
|
||||||
|
// busses
|
||||||
|
entryCreationBus := app.NewEntryCreationBus()
|
||||||
|
|
||||||
|
// plugins
|
||||||
|
plugings.NewEcho(entryCreationBus)
|
||||||
|
|
||||||
// Create Services
|
// Create Services
|
||||||
entryService := app.NewEntryService(entryRepo)
|
entryService := app.NewEntryService(entryRepo, entryCreationBus)
|
||||||
binaryService := app.NewBinaryFileService(binRepo)
|
binaryService := app.NewBinaryFileService(binRepo)
|
||||||
authorService := app.NewAuthorService(authorRepo, siteConfigRepo)
|
authorService := app.NewAuthorService(authorRepo, siteConfigRepo)
|
||||||
webmentionService := app.NewWebmentionService(
|
webmentionService := app.NewWebmentionService(
|
||||||
|
|
|
@ -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())
|
||||||
|
}
|
Loading…
Reference in New Issue