diff --git a/app/webmention_service.go b/app/webmention_service.go index 1732d4f..940ec77 100644 --- a/app/webmention_service.go +++ b/app/webmention_service.go @@ -109,7 +109,7 @@ func (s *WebmentionService) GetExistingWebmention(entryId string, source string, } for _, interaction := range inters { if webm, ok := interaction.(*interactions.Webmention); ok { - m := webm.MetaData().(interactions.WebmentionMetaData) + m := webm.MetaData().(*interactions.WebmentionMetaData) if m.Source == source && m.Target == target { return webm, nil } @@ -149,7 +149,7 @@ func (s *WebmentionService) ProcessWebmention(source string, target string) erro Target: target, Title: hEntry.Title, } - webmention.SetMetaData(data) + webmention.SetMetaData(&data) webmention.SetEntryID(entryId) webmention.SetCreatedAt(time.Now()) err = s.InteractionRepository.Update(webmention) diff --git a/cmd/owl/main.go b/cmd/owl/main.go index a86661e..724c332 100644 --- a/cmd/owl/main.go +++ b/cmd/owl/main.go @@ -64,7 +64,7 @@ func App(db infra.Database) *web.WebApp { return web.NewWebApp( entryService, entryRegister, binaryService, authorService, siteConfigRepo, configRegister, - webmentionService, + webmentionService, interactionRepo, ) } diff --git a/infra/interaction_repository.go b/infra/interaction_repository.go index c5b4f83..e9e88fe 100644 --- a/infra/interaction_repository.go +++ b/infra/interaction_repository.go @@ -103,13 +103,38 @@ func (repo *DefaultInteractionRepo) FindAll(entryId string) ([]model.Interaction } // FindById implements repository.InteractionRepository. -func (*DefaultInteractionRepo) FindById(id string) (model.Interaction, error) { - panic("unimplemented") +func (repo *DefaultInteractionRepo) FindById(id string) (model.Interaction, error) { + data := sqlInteraction{} + err := repo.db.Get(&data, "SELECT * FROM interactions WHERE id = ?", id) + if err != nil { + return nil, err + } + if data.Id == "" { + return nil, errors.New("interaction not found") + } + return repo.sqlInteractionToInteraction(data) } // Update implements repository.InteractionRepository. -func (*DefaultInteractionRepo) Update(interaction model.Interaction) error { - panic("unimplemented") +func (repo *DefaultInteractionRepo) Update(interaction model.Interaction) error { + exInter, _ := repo.FindById(interaction.ID()) + if exInter == nil { + return errors.New("interaction not found") + } + + _, err := repo.typeRegistry.TypeName(interaction) + if err != nil { + return errors.New("interaction type not registered") + } + + var metaDataJson []byte + if interaction.MetaData() != nil { + metaDataJson, _ = json.Marshal(interaction.MetaData()) + } + + _, err = repo.db.Exec("UPDATE interactions SET entry_id = ?, meta_data = ? WHERE id = ?", interaction.EntryID(), metaDataJson, interaction.ID()) + + return err } func (repo *DefaultInteractionRepo) sqlInteractionToInteraction(interaction sqlInteraction) (model.Interaction, error) { diff --git a/interactions/webmention.go b/interactions/webmention.go index 09d8fc0..d60b45f 100644 --- a/interactions/webmention.go +++ b/interactions/webmention.go @@ -1,6 +1,10 @@ package interactions -import "owl-blogs/domain/model" +import ( + "fmt" + "owl-blogs/domain/model" + "owl-blogs/render" +) type Webmention struct { model.InteractionBase @@ -14,7 +18,11 @@ type WebmentionMetaData struct { } func (i *Webmention) Content() model.InteractionContent { - return model.InteractionContent(i.meta.Source) + str, err := render.RenderTemplateToString("interaction/Webmention", i) + if err != nil { + fmt.Println(err) + } + return model.InteractionContent(str) } func (i *Webmention) MetaData() interface{} { diff --git a/render/templates/base.tmpl b/render/templates/base.tmpl index d0b0815..2fac1dd 100644 --- a/render/templates/base.tmpl +++ b/render/templates/base.tmpl @@ -6,6 +6,7 @@ {{template "title" .Data}} - {{ .SiteConfig.Title }} +