Skip to content

Commit

Permalink
Initial-Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartoffel096 committed Oct 6, 2024
1 parent e2880a0 commit 8380669
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions handler/agentgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down

0 comments on commit 8380669

Please sign in to comment.