/ web / actions / actions.go
actions.go
 1  package actions
 2  
 3  import (
 4  	"github.com/gofiber/fiber/v2"
 5  	"github.com/mrusme/journalist/ent"
 6  	"github.com/mrusme/journalist/lib"
 7  	"go.uber.org/zap"
 8  )
 9  
10  type handler struct {
11  	jctx *lib.JournalistContext
12  
13  	config    *lib.Config
14  	entClient *ent.Client
15  	logger    *zap.Logger
16  }
17  
18  func Register(
19  	jctx *lib.JournalistContext,
20  	fiberRouter *fiber.Router,
21  ) {
22  	endpoint := new(handler)
23  	endpoint.jctx = jctx
24  	endpoint.config = endpoint.jctx.Config
25  	endpoint.entClient = endpoint.jctx.EntClient
26  	endpoint.logger = endpoint.jctx.Logger
27  
28  	actionsRouter := (*fiberRouter).Group("/actions")
29  	actionsRouter.Get("/read/:id", endpoint.Read)
30  	actionsRouter.Get("/read_older/:id", endpoint.ReadOlder)
31  	actionsRouter.Get("/read_newer/:id", endpoint.ReadNewer)
32  	// actionsRouter.Get("/read_all/:id", endpoint.ReadAll)
33  }
34  
35  func (h *handler) resp(ctx *fiber.Ctx, content fiber.Map) error {
36  	err := ctx.Render("views/actions", content)
37  	ctx.Set("Content-type", "text/html; charset=utf-8")
38  	return err
39  }