features/token-things #2

Merged
jtom38 merged 7 commits from features/token-things into main 2024-07-07 08:03:00 -07:00
3 changed files with 30 additions and 12 deletions
Showing only changes of commit 484cbee1ea - Show all commits

View File

@ -3,27 +3,22 @@ package handlers
import ( import (
"net/http" "net/http"
"git.jamestombleson.com/jtom38/newsbot-portal/internal/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/layout"
"git.jamestombleson.com/jtom38/newsbot-portal/internal/views/sources" "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/sources"
apidomain "git.jamestombleson.com/jtom38/newsbot-api/domain"
"github.com/labstack/echo/v4" "github.com/labstack/echo/v4"
) )
func (h *Handler) ListAllSources(c echo.Context) error { func (h *Handler) ListAllSources(c echo.Context) error {
_, err := ValidateJwt(c, h.config.JwtSecret, h.config.ServerAddress) err := HasValidScope(c, apidomain.ScopeSourceRead)
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.Sources.ListAll(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.Sources.ListAll(userToken.Value, 0)
if err != nil {
return Render(c, http.StatusOK, layout.Error(err))
} }
return Render(c, http.StatusOK, sources.ListAll(models.ListAllSourcesViewModel{ return Render(c, http.StatusOK, sources.ListAll(models.ListAllSourcesViewModel{
@ -32,3 +27,12 @@ func (h *Handler) ListAllSources(c echo.Context) error {
Message: resp.Message, Message: resp.Message,
})) }))
} }
func (h *Handler) AddSource(c echo.Context) error {
err := HasValidScope(c, apidomain.ScopeSourceCreate)
if err != nil {
return RenderError(c, err)
}
return Render(c, http.StatusOK, sources.Add(models.AddSourcePayloadModel{}))
}

View File

@ -7,3 +7,7 @@ type ListAllSourcesViewModel struct {
Message string Message string
Items []domain.SourceDto Items []domain.SourceDto
} }
type AddSourcePayloadModel struct {
}

View File

@ -0,0 +1,10 @@
package sources
import "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/layout"
import "git.jamestombleson.com/jtom38/newsbot-portal/internal/models"
templ Add(model models.AddSourcePayloadModel) {
@layout.WithTemplate() {
<form hx-post="/sources/add"></form>
}
}