deletion of webmentions
This commit is contained in:
parent
723a6000bf
commit
653efcc487
|
@ -130,10 +130,6 @@ func (s *WebmentionService) ProcessWebmention(source string, target string) erro
|
||||||
}
|
}
|
||||||
|
|
||||||
entryId := UrlToEntryId(target)
|
entryId := UrlToEntryId(target)
|
||||||
println(entryId)
|
|
||||||
println(entryId)
|
|
||||||
println(entryId)
|
|
||||||
println(entryId)
|
|
||||||
_, err = s.EntryRepository.FindById(entryId)
|
_, err = s.EntryRepository.FindById(entryId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -70,6 +70,9 @@ func (r *DefaultEntryRepo) Create(entry model.Entry) error {
|
||||||
|
|
||||||
// Delete implements repository.EntryRepository.
|
// Delete implements repository.EntryRepository.
|
||||||
func (r *DefaultEntryRepo) Delete(entry model.Entry) error {
|
func (r *DefaultEntryRepo) Delete(entry model.Entry) error {
|
||||||
|
if entry.ID() == "" {
|
||||||
|
return errors.New("entry not found")
|
||||||
|
}
|
||||||
_, err := r.db.Exec("DELETE FROM entries WHERE id = ?", entry.ID())
|
_, err := r.db.Exec("DELETE FROM entries WHERE id = ?", entry.ID())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,8 +78,12 @@ func (repo *DefaultInteractionRepo) Create(interaction model.Interaction) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete implements repository.InteractionRepository.
|
// Delete implements repository.InteractionRepository.
|
||||||
func (*DefaultInteractionRepo) Delete(interaction model.Interaction) error {
|
func (repo *DefaultInteractionRepo) Delete(interaction model.Interaction) error {
|
||||||
panic("unimplemented")
|
if interaction.ID() == "" {
|
||||||
|
return errors.New("interaction not found")
|
||||||
|
}
|
||||||
|
_, err := repo.db.Exec("DELETE FROM interactions WHERE id = ?", interaction.ID())
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindAll implements repository.InteractionRepository.
|
// FindAll implements repository.InteractionRepository.
|
||||||
|
|
|
@ -51,6 +51,15 @@
|
||||||
{{range .Interactions}}
|
{{range .Interactions}}
|
||||||
<li>
|
<li>
|
||||||
{{ .Content }}
|
{{ .Content }}
|
||||||
|
{{ if $.LoggedIn }}
|
||||||
|
<form method="post" action="/admin/interactions/{{.ID}}/delete/" class="grid">
|
||||||
|
<label for="confirm">
|
||||||
|
Confirm deletion
|
||||||
|
<input type="checkbox" name="confirm" id="confirm" required />
|
||||||
|
</label>
|
||||||
|
<input type="submit" class="secondary outline" value="Delete" />
|
||||||
|
</form>
|
||||||
|
{{ end }}
|
||||||
</li>
|
</li>
|
||||||
{{end}}
|
{{end}}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package web
|
||||||
|
|
||||||
|
import (
|
||||||
|
"owl-blogs/app/repository"
|
||||||
|
|
||||||
|
"github.com/gofiber/fiber/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AdminInteractionHandler struct {
|
||||||
|
interactionRepo repository.InteractionRepository
|
||||||
|
configRepo repository.ConfigRepository
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAdminInteractionHandler(configRepo repository.ConfigRepository, interactionRepo repository.InteractionRepository) *AdminInteractionHandler {
|
||||||
|
return &AdminInteractionHandler{
|
||||||
|
interactionRepo: interactionRepo,
|
||||||
|
configRepo: configRepo,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *AdminInteractionHandler) HandleDelete(c *fiber.Ctx) error {
|
||||||
|
c.Set(fiber.HeaderContentType, fiber.MIMETextHTML)
|
||||||
|
|
||||||
|
id := c.Params("id")
|
||||||
|
inter, err := h.interactionRepo.FindById(id)
|
||||||
|
entryId := inter.EntryID()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
confirm := c.FormValue("confirm")
|
||||||
|
if confirm != "on" {
|
||||||
|
return c.Redirect("/posts/" + inter.ID() + "/")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = h.interactionRepo.Delete(inter)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return c.Redirect("/posts/" + entryId + "/")
|
||||||
|
}
|
|
@ -57,6 +57,7 @@ func NewWebApp(
|
||||||
adminHandler := NewAdminHandler(configRepo, configRegister, typeRegistry)
|
adminHandler := NewAdminHandler(configRepo, configRegister, typeRegistry)
|
||||||
draftHandler := NewDraftHandler(entryService, configRepo)
|
draftHandler := NewDraftHandler(entryService, configRepo)
|
||||||
binaryManageHandler := NewBinaryManageHandler(configRepo, binService)
|
binaryManageHandler := NewBinaryManageHandler(configRepo, binService)
|
||||||
|
adminInteractionHandler := NewAdminInteractionHandler(configRepo, interactionRepo)
|
||||||
admin := app.Group("/admin")
|
admin := app.Group("/admin")
|
||||||
admin.Use(middleware.NewAuthMiddleware(authorService).Handle)
|
admin.Use(middleware.NewAuthMiddleware(authorService).Handle)
|
||||||
admin.Get("/", adminHandler.Handle)
|
admin.Get("/", adminHandler.Handle)
|
||||||
|
@ -66,6 +67,7 @@ func NewWebApp(
|
||||||
admin.Get("/binaries/", binaryManageHandler.Handle)
|
admin.Get("/binaries/", binaryManageHandler.Handle)
|
||||||
admin.Post("/binaries/new/", binaryManageHandler.HandleUpload)
|
admin.Post("/binaries/new/", binaryManageHandler.HandleUpload)
|
||||||
admin.Post("/binaries/delete", binaryManageHandler.HandleDelete)
|
admin.Post("/binaries/delete", binaryManageHandler.HandleDelete)
|
||||||
|
admin.Post("/interactions/:id/delete/", adminInteractionHandler.HandleDelete)
|
||||||
|
|
||||||
// Editor
|
// Editor
|
||||||
editor := app.Group("/editor")
|
editor := app.Group("/editor")
|
||||||
|
|
|
@ -26,6 +26,7 @@ func (h *WebmentionHandler) Handle(c *fiber.Ctx) error {
|
||||||
target := c.FormValue("target")
|
target := c.FormValue("target")
|
||||||
source := c.FormValue("source")
|
source := c.FormValue("source")
|
||||||
|
|
||||||
|
println("Incoming webmention")
|
||||||
println("target", target)
|
println("target", target)
|
||||||
println("source", source)
|
println("source", source)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue