features/token-things #2
@ -3,40 +3,34 @@ package handlers
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"git.jamestombleson.com/jtom38/newsbot-portal/internal/domain"
|
apidomain "git.jamestombleson.com/jtom38/newsbot-api/domain"
|
||||||
"git.jamestombleson.com/jtom38/newsbot-portal/internal/models"
|
"git.jamestombleson.com/jtom38/newsbot-portal/internal/models"
|
||||||
"git.jamestombleson.com/jtom38/newsbot-portal/internal/views/articles"
|
"git.jamestombleson.com/jtom38/newsbot-portal/internal/views/articles"
|
||||||
"git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout"
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *Handler) ArticlesList(c echo.Context) error {
|
func (h *Handler) ArticlesList(c echo.Context) error {
|
||||||
_, err := ValidateJwt(c, h.config.JwtSecret, h.config.ServerAddress)
|
err := HasValidScope(c, apidomain.ScopeArticleRead)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Render(c, http.StatusOK, layout.Error(err))
|
return RenderError(c, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
userToken, err := c.Cookie(domain.CookieToken)
|
resp, err := h.api.Articles.List(GetJwtToken(c), 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Render(c, http.StatusBadRequest, layout.Error(err))
|
return RenderError(c, err)
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := h.api.Articles.List(userToken.Value, 0)
|
|
||||||
if err != nil {
|
|
||||||
return Render(c, http.StatusBadRequest, layout.Error(err))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vm := models.ListArticlesViewModel{}
|
vm := models.ListArticlesViewModel{}
|
||||||
|
|
||||||
for _, article := range resp.Payload {
|
for _, article := range resp.Payload {
|
||||||
source, err := h.api.Sources.GetById(userToken.Value, article.SourceID)
|
source, err := h.api.Sources.GetById(GetJwtToken(c), article.SourceID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Render(c, http.StatusBadRequest, layout.Error(err))
|
return RenderError(c, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
item := models.ListArticleSourceModel {
|
item := models.ListArticleSourceModel{
|
||||||
Article: article,
|
Article: article,
|
||||||
Source: source.Payload[0],
|
Source: source.Payload[0],
|
||||||
}
|
}
|
||||||
vm.Items = append(vm.Items, item)
|
vm.Items = append(vm.Items, item)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user