From 484cbee1ea349188f73b6e8387460dbdedc3edb1 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Sun, 7 Jul 2024 08:02:00 -0700 Subject: [PATCH] after a bunch of distractions, starting to work on adding sources --- internal/handlers/sources.go | 28 ++++++++++++++++------------ internal/models/sources.go | 4 ++++ internal/views/sources/add.templ | 10 ++++++++++ 3 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 internal/views/sources/add.templ diff --git a/internal/handlers/sources.go b/internal/handlers/sources.go index f912e61..5a23c69 100644 --- a/internal/handlers/sources.go +++ b/internal/handlers/sources.go @@ -3,32 +3,36 @@ package handlers import ( "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/views/layout" "git.jamestombleson.com/jtom38/newsbot-portal/internal/views/sources" + + apidomain "git.jamestombleson.com/jtom38/newsbot-api/domain" "github.com/labstack/echo/v4" ) 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 { - 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 { - return Render(c, http.StatusBadRequest, layout.Error(err)) - } - - resp, err := h.api.Sources.ListAll(userToken.Value, 0) - if err != nil { - return Render(c, http.StatusOK, layout.Error(err)) + return RenderError(c, err) } return Render(c, http.StatusOK, sources.ListAll(models.ListAllSourcesViewModel{ - Items: resp.Payload, + Items: resp.Payload, IsError: resp.IsError, 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{})) +} diff --git a/internal/models/sources.go b/internal/models/sources.go index ac44124..aee1894 100644 --- a/internal/models/sources.go +++ b/internal/models/sources.go @@ -7,3 +7,7 @@ type ListAllSourcesViewModel struct { Message string Items []domain.SourceDto } + +type AddSourcePayloadModel struct { + +} \ No newline at end of file diff --git a/internal/views/sources/add.templ b/internal/views/sources/add.templ new file mode 100644 index 0000000..a61a503 --- /dev/null +++ b/internal/views/sources/add.templ @@ -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() { +
+ } +}