Skip to content

Commit

Permalink
get clients per nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rushikeshnimkar committed Jun 11, 2024
1 parent d37af2a commit c3a48b5
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions api/v1/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func ApplyRoutes(r *gin.RouterGroup) {
g.GET("/clients", GetAllClients)
g.DELETE("/client/:uuid", DeleteClient)
// g.GET("/config/:region/:uuid", GetConfig)
g.GET("/clients/node/:nodeId", GetClientsByNode)
}
}
func RegisterClient(c *gin.Context) {
Expand Down Expand Up @@ -273,3 +274,18 @@ func GetClientsByCollectionId(c *gin.Context) {

httpo.NewSuccessResponseP(200, "VPN clients fetched successfully", clients).SendD(c)
}

func GetClientsByNode(c *gin.Context) {
nodeId := c.Param("nodeId")
db := dbconfig.GetDb()

var clients []models.Erebrus
err := db.Model(&models.Erebrus{}).Where("node_id = ?", nodeId).Find(&clients).Error
if err != nil {
logwrapper.Errorf("failed to fetch clients from database: %s", err)
httpo.NewErrorResponse(http.StatusInternalServerError, err.Error()).SendD(c)
return
}

httpo.NewSuccessResponseP(200, "VPN clients fetched successfully", clients).SendD(c)
}

0 comments on commit c3a48b5

Please sign in to comment.