article_list.go 952 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package admin
  2. import (
  3. "git.dmitriygnatenko.ru/dima/go-common/logger"
  4. "github.com/gofiber/fiber/v2"
  5. "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/mapper"
  6. "git.dmitriygnatenko.ru/dima/dmitriygnatenko-v2/internal/services/i18n"
  7. )
  8. type articleListPage struct {
  9. articleRepository ArticleRepository
  10. }
  11. func NewArticleListPageHandler(
  12. articleRepository ArticleRepository,
  13. ) fiber.Handler {
  14. handler := articleListPage{
  15. articleRepository: articleRepository,
  16. }
  17. return handler.handler()
  18. }
  19. func (h articleListPage) handler() fiber.Handler {
  20. return func(ctx *fiber.Ctx) error {
  21. lang := i18n.LanguageFromContext(ctx)
  22. articles, err := h.articleRepository.GetAll(ctx.Context())
  23. if err != nil {
  24. logger.Error(ctx.Context(), err.Error())
  25. return err
  26. }
  27. return ctx.Render("admin/article", fiber.Map{
  28. "section": "article",
  29. "lang": lang,
  30. "articles": mapper.ToArticlesList(lang, articles),
  31. }, "admin/_layout")
  32. }
  33. }