feat: Sprint 2 — snippets + keychain CRUD, standalone templates, clipboard/utils JS
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"git.tukangketik.id/swanadiva/hostkeeper/v2/internal/model"
|
||||
)
|
||||
|
||||
var snippetStore = model.NewSnippetStore()
|
||||
|
||||
func Snippets(c *fiber.Ctx) error {
|
||||
snippets := snippetStore.All()
|
||||
return c.Render("snippets", fiber.Map{
|
||||
"View": "snippets",
|
||||
"Title": "Snippets",
|
||||
"Snippets": snippets,
|
||||
"NavItems": navItems,
|
||||
})
|
||||
}
|
||||
|
||||
func SnippetGrid(c *fiber.Ctx) error {
|
||||
q := c.Query("q", "")
|
||||
snippets := snippetStore.Search(q)
|
||||
return c.Render("snippet_grid", fiber.Map{"Snippets": snippets})
|
||||
}
|
||||
|
||||
func CreateSnippet(c *fiber.Ctx) error {
|
||||
name := c.FormValue("name")
|
||||
content := c.FormValue("content")
|
||||
language := c.FormValue("language")
|
||||
snippetStore.Add(name, content, language, nil)
|
||||
snippets := snippetStore.All()
|
||||
return c.Render("snippet_grid", fiber.Map{"Snippets": snippets})
|
||||
}
|
||||
|
||||
func DeleteSnippet(c *fiber.Ctx) error {
|
||||
id := c.Params("id")
|
||||
snippetStore.Delete(id)
|
||||
snippets := snippetStore.All()
|
||||
return c.Render("snippet_grid", fiber.Map{"Snippets": snippets})
|
||||
}
|
||||
Reference in New Issue
Block a user