diff --git a/internal/sbi/api_lab6.go b/internal/sbi/api_lab6.go new file mode 100644 index 0000000..12379af --- /dev/null +++ b/internal/sbi/api_lab6.go @@ -0,0 +1,44 @@ +package sbi + +import ( + "net/http" + + "github.com/gin-gonic/gin" +) + +// Rutas del nuevo servicio /lab6 +func (s *Server) getLab6Route() []Route { + return []Route{ + { + Name: "Lab6 Info", + Method: http.MethodGet, + Pattern: "/", // -> /lab6/ + APIFunc: func(c *gin.Context) { + c.JSON(http.StatusOK, gin.H{ + "message": "Lab 6 OK", + "author": "ValentinoV", + }) + }, + }, + { + Name: "Lab6 Echo", + Method: http.MethodPost, + Pattern: "/echo", // -> /lab6/echo + APIFunc: func(c *gin.Context) { + var body map[string]interface{} + + if err := c.BindJSON(&body); err != nil { + c.JSON(http.StatusBadRequest, gin.H{ + "error": "invalid JSON body", + }) + return + } + + c.JSON(http.StatusOK, gin.H{ + "message": "Lab 6 echo", + "received": body, + }) + }, + }, + } +} diff --git a/internal/sbi/router.go b/internal/sbi/router.go index 6fa35e1..168b433 100644 --- a/internal/sbi/router.go +++ b/internal/sbi/router.go @@ -45,6 +45,9 @@ func newRouter(s *Server) *gin.Engine { spyFamilyGroup := router.Group("/spyfamily") applyRoutes(spyFamilyGroup, s.getSpyFamilyRoute()) + lab6Group := router.Group("/lab6") + applyRoutes(lab6Group, s.getLab6Route()) + return router }