first retrieved webmention
This commit is contained in:
parent
df5215d943
commit
723a6000bf
|
@ -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)
|
||||
|
|
|
@ -64,7 +64,7 @@ func App(db infra.Database) *web.WebApp {
|
|||
return web.NewWebApp(
|
||||
entryService, entryRegister, binaryService,
|
||||
authorService, siteConfigRepo, configRegister,
|
||||
webmentionService,
|
||||
webmentionService, interactionRepo,
|
||||
)
|
||||
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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{} {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>{{template "title" .Data}} - {{ .SiteConfig.Title }}</title>
|
||||
<meta property="og:title" content="{{template "title" .Data}}" />
|
||||
<link rel="webmention" href="/webmention/" />
|
||||
|
||||
<link rel='stylesheet' href='/static/pico.min.css'>
|
||||
<style>
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<a href="{{.MetaData.Source}}">
|
||||
{{if .MetaData.Title}}
|
||||
{{.MetaData.Title}}
|
||||
{{else}}
|
||||
{{.MetaData.Source}}
|
||||
{{end}}
|
||||
</a>
|
|
@ -39,6 +39,25 @@
|
|||
|
||||
</div>
|
||||
|
||||
{{if .Interactions}}
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<hr>
|
||||
<h4>
|
||||
Interactions
|
||||
</h4>
|
||||
<ul>
|
||||
{{range .Interactions}}
|
||||
<li>
|
||||
{{ .Content }}
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
{{end}}
|
||||
|
||||
|
||||
|
||||
{{ if .LoggedIn }}
|
||||
<br>
|
||||
<br>
|
||||
|
|
|
@ -35,13 +35,14 @@ func NewWebApp(
|
|||
configRepo repository.ConfigRepository,
|
||||
configRegister *app.ConfigRegister,
|
||||
webmentionService *app.WebmentionService,
|
||||
interactionRepo repository.InteractionRepository,
|
||||
) *WebApp {
|
||||
app := fiber.New()
|
||||
app.Use(middleware.NewUserMiddleware(authorService).Handle)
|
||||
|
||||
indexHandler := NewIndexHandler(entryService, configRepo)
|
||||
listHandler := NewListHandler(entryService, configRepo)
|
||||
entryHandler := NewEntryHandler(entryService, typeRegistry, authorService, configRepo)
|
||||
entryHandler := NewEntryHandler(entryService, typeRegistry, authorService, configRepo, interactionRepo)
|
||||
mediaHandler := NewMediaHandler(binService)
|
||||
rssHandler := NewRSSHandler(entryService, configRepo)
|
||||
loginHandler := NewLoginHandler(authorService, configRepo)
|
||||
|
|
|
@ -10,16 +10,18 @@ import (
|
|||
)
|
||||
|
||||
type EntryHandler struct {
|
||||
configRepo repository.ConfigRepository
|
||||
entrySvc *app.EntryService
|
||||
authorSvc *app.AuthorService
|
||||
registry *app.EntryTypeRegistry
|
||||
configRepo repository.ConfigRepository
|
||||
entrySvc *app.EntryService
|
||||
authorSvc *app.AuthorService
|
||||
registry *app.EntryTypeRegistry
|
||||
interactionRepo repository.InteractionRepository
|
||||
}
|
||||
|
||||
type entryData struct {
|
||||
Entry model.Entry
|
||||
Author *model.Author
|
||||
LoggedIn bool
|
||||
Entry model.Entry
|
||||
Author *model.Author
|
||||
LoggedIn bool
|
||||
Interactions []model.Interaction
|
||||
}
|
||||
|
||||
func NewEntryHandler(
|
||||
|
@ -27,12 +29,14 @@ func NewEntryHandler(
|
|||
registry *app.EntryTypeRegistry,
|
||||
authorService *app.AuthorService,
|
||||
configRepo repository.ConfigRepository,
|
||||
interactionRepo repository.InteractionRepository,
|
||||
) *EntryHandler {
|
||||
return &EntryHandler{
|
||||
entrySvc: entryService,
|
||||
authorSvc: authorService,
|
||||
registry: registry,
|
||||
configRepo: configRepo,
|
||||
entrySvc: entryService,
|
||||
authorSvc: authorService,
|
||||
registry: registry,
|
||||
configRepo: configRepo,
|
||||
interactionRepo: interactionRepo,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,14 +62,17 @@ func (h *EntryHandler) Handle(c *fiber.Ctx) error {
|
|||
author = &model.Author{}
|
||||
}
|
||||
|
||||
inters, _ := h.interactionRepo.FindAll(entry.ID())
|
||||
|
||||
return render.RenderTemplateWithBase(
|
||||
c,
|
||||
getSiteConfig(h.configRepo),
|
||||
"views/entry",
|
||||
entryData{
|
||||
Entry: entry,
|
||||
Author: author,
|
||||
LoggedIn: loggedIn,
|
||||
Entry: entry,
|
||||
Author: author,
|
||||
LoggedIn: loggedIn,
|
||||
Interactions: inters,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -26,6 +26,9 @@ func (h *WebmentionHandler) Handle(c *fiber.Ctx) error {
|
|||
target := c.FormValue("target")
|
||||
source := c.FormValue("source")
|
||||
|
||||
println("target", target)
|
||||
println("source", source)
|
||||
|
||||
if target == "" {
|
||||
return c.Status(400).SendString("target is required")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue