feat: added first api route

This commit is contained in:
2026-02-18 08:32:27 -05:00
parent e1f0a638b9
commit 150f95ee0b
6 changed files with 149 additions and 18 deletions

View File

@@ -0,0 +1,36 @@
package routes
import (
"blog/internal/echo/handlers"
"blog/internal/echo/middleware"
"blog/internal/services"
"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
}
func SetupRoutes(e *echo.Echo, s *services.StrapiService) {
// Global middleware
e.Use(middleware.ServerHandler)
// Post routes
posts := e.Group("/posts") // Routing group
// GET /posts/all
posts.GET("/all", func(c *echo.Context) error {
pageSize := getIntParam(c, "pageSize", 10)
page := getIntParam(c, "page", 1)
return handlers.GetAllPosts(c, s, pageSize, page)
})
}