12345678910111213141516171819202122232425262728293031323334353637383940 |
- package admin
- import (
- "git.dmitriygnatenko.ru/dima/go-common/logger"
- "github.com/gofiber/fiber/v2"
- "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/mapper"
- "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/services/i18n"
- )
- type articleListPage struct {
- articleRepository ArticleRepository
- }
- func NewArticleListPageHandler(
- articleRepository ArticleRepository,
- ) fiber.Handler {
- handler := articleListPage{
- articleRepository: articleRepository,
- }
- return handler.handler()
- }
- func (h articleListPage) handler() fiber.Handler {
- return func(ctx *fiber.Ctx) error {
- lang := i18n.LanguageFromContext(ctx)
- articles, err := h.articleRepository.GetAll(ctx.Context())
- if err != nil {
- logger.Error(ctx.Context(), err.Error())
- return err
- }
- return ctx.Render("admin/article", fiber.Map{
- "section": "article",
- "lang": lang,
- "articles": mapper.ToArticlesList(lang, articles),
- }, "admin/_layout")
- }
- }
|