diff --git a/app/entry_service.go b/app/entry_service.go index 08b6442..a9886a8 100644 --- a/app/entry_service.go +++ b/app/entry_service.go @@ -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 { diff --git a/app/entry_service_test.go b/app/entry_service_test.go index da6cbcb..5619ca9 100644 --- a/app/entry_service_test.go +++ b/app/entry_service_test.go @@ -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 } diff --git a/cmd/owl/main.go b/cmd/owl/main.go index 724c332..3fb2e1b 100644 --- a/cmd/owl/main.go +++ b/cmd/owl/main.go @@ -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( diff --git a/plugings/echo.go b/plugings/echo.go new file mode 100644 index 0000000..76e8e7f --- /dev/null +++ b/plugings/echo.go @@ -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()) +}