Added Fiber and layouts
This commit is contained in:
parent
f8e7ea482b
commit
63b19a249a
17 changed files with 331 additions and 37 deletions
38
handlers/site.go
Normal file
38
handlers/site.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"lmika.dev/lmika/hugo-crm/services/sites"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Site struct {
|
||||
Site *sites.Service
|
||||
}
|
||||
|
||||
func (s *Site) Create() fiber.Handler {
|
||||
return func(c *fiber.Ctx) error {
|
||||
site, err := s.Site.CreateSite(c.UserContext(), "New Site "+time.Now().Format("2006-01-02 15:04:05"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.Redirect(fmt.Sprintf("/sites/%v", site.ID))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Site) Show() fiber.Handler {
|
||||
return func(c *fiber.Ctx) error {
|
||||
id, err := c.ParamsInt("siteId")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
site, err := s.Site.GetSite(c.UserContext(), id)
|
||||
|
||||
return c.Render("sites/index", fiber.Map{
|
||||
"site": site,
|
||||
}, "layouts/main")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue