feat: added strapi echo routes

This commit is contained in:
darwincereska
2026-02-18 20:25:24 -05:00
parent 9a0e8d46c8
commit 2740d223cb
6 changed files with 117 additions and 47 deletions

View File

@@ -1,27 +0,0 @@
package handlers
import (
"strconv"
"github.com/labstack/echo/v5"
)
// Helper method to get int param or default value
func GetIntParam(c *echo.Context, name string, defaultValue int) int {
value, err := strconv.Atoi(c.ParamOr(name, strconv.Itoa(defaultValue)))
if err != nil {
return defaultValue
}
return value
}
// Helper method to get bool param or default value
func GetBoolParam(c *echo.Context, name string, defaultValue bool) bool {
value, err := strconv.ParseBool(c.ParamOr(name, strconv.FormatBool(defaultValue)))
if err != nil {
return defaultValue
}
return value
}

View File

@@ -8,10 +8,7 @@ import (
)
// GetAllPosts returns a list of all posts
func GetAllPosts(c *echo.Context, s *services.StrapiService) error {
pageSize := GetIntParam(c, "pageSize", 10)
page := GetIntParam(c, "page", 1)
func GetAllPosts(c *echo.Context, s *services.StrapiService, pageSize, page int) error {
posts, err := s.GetAllPosts(c.Request().Context(), pageSize, page)
if err != nil {
return c.JSON(http.StatusInternalServerError, err)
@@ -21,10 +18,7 @@ func GetAllPosts(c *echo.Context, s *services.StrapiService) error {
}
// GetFeaturedPosts returns a list of featured posts
func GetFeaturedPosts(c *echo.Context, s *services.StrapiService) error {
pageSize := GetIntParam(c, "pageSize", 10)
page := GetIntParam(c, "page", 1)
func GetFeaturedPosts(c *echo.Context, s *services.StrapiService, pageSize, page int) error {
posts, err := s.GetFeaturedPosts(c.Request().Context(), pageSize, page)
if err != nil {
return c.JSON(http.StatusInternalServerError, err)
@@ -44,10 +38,7 @@ func GetPost(c *echo.Context, s *services.StrapiService, slug string) error {
}
// GetPostSummaries returns post summaries
func GetPostSummaries(c *echo.Context, s *services.StrapiService) error {
pageSize := GetIntParam(c, "pageSize", 10)
page := GetIntParam(c, "page", 1)
func GetPostSummaries(c *echo.Context, s *services.StrapiService, pageSize, page int) error {
posts, err := s.GetPostSummaries(c.Request().Context(), pageSize, page)
if err != nil {
return c.JSON(http.StatusInternalServerError, err)