diff --git a/handler/agentgroup.go b/handler/agentgroup.go index 6bf7cd1..f7fa4de 100644 --- a/handler/agentgroup.go +++ b/handler/agentgroup.go @@ -14,7 +14,8 @@ import ( // GetAgentByID filters a slice of Agents for a matching Agent.Agent_ID. // It returns a JSON response with fiber.StatusOK or fiber.StatusNotFound. func GetAgentByID(c *fiber.Ctx) error { - id, err := strconv.Atoi(c.Params("id")) + + id, err := strconv.Atoi(c.Query("id")) if err != nil { fmt.Println(err) } @@ -73,7 +74,8 @@ func RegisterAgent(c *fiber.Ctx) error { // GetHostByAgentID finds the host for a given agent ID. func GetHostByAgentID(c *fiber.Ctx) error { - id, err := strconv.Atoi(c.Params("id")) + + id, err := strconv.Atoi(c.Query("id")) if err != nil { fmt.Println(err) } @@ -99,7 +101,7 @@ func GetHostByAgentID(c *fiber.Ctx) error { // TODO: Filter all hosts for agent id filter = bson.D{ - {"id", agents[0].Host_ID}, + {"id", agents[0].HostID}, } fmt.Println(filter) diff --git a/server/router.go b/server/router.go index c93959c..d179232 100644 --- a/server/router.go +++ b/server/router.go @@ -21,10 +21,9 @@ type Routes struct { // addAgentHandler sets up agent-related routes in Fiber. func (r Routes) addAgentHandler(group fiber.Router) { - AgentGroup := group.Group("/agent") + AgentGroup := group.Group("/agents") - AgentGroup.Get("/:id", handler.GetAgentByID) - AgentGroup.Get("/:id/host", handler.GetHostByAgentID) + AgentGroup.Get("/", handler.GetAgentByID) AgentGroup.Post("/register", handler.RegisterAgent) } @@ -38,8 +37,9 @@ func (r Routes) addGeneralHandler(group fiber.Router) { // addHostHandler sets up host-related routes in Fiber. func (r Routes) addHostHandler(group fiber.Router) { - HostGroup := group.Group("/host") + HostGroup := group.Group("/hosts") + HostGroup.Get("/", handler.GetHostByAgentID) HostGroup.Post("/register", handler.RegisterHost) }