Browse Source

add getClientTraffics api

Co-Authored-By: Alireza Ahmadi <[email protected]>
MHSanaei 1 year ago
parent
commit
f817f922fe
3 changed files with 15 additions and 1 deletions
  1. 4 0
      web/controller/api.go
  2. 10 0
      web/controller/inbound.go
  3. 1 1
      web/service/inbound.go

+ 4 - 0
web/controller/api.go

@@ -19,6 +19,7 @@ func (a *APIController) initRouter(g *gin.RouterGroup) {
 
 	g.GET("/list", a.getAllInbounds)
 	g.GET("/get/:id", a.getSingleInbound)
+	g.GET("/getClientTraffics/:email", a.getClientTraffics)
 	g.POST("/add", a.addInbound)
 	g.POST("/del/:id", a.delInbound)
 	g.POST("/update/:id", a.updateInbound)
@@ -39,6 +40,9 @@ func (a *APIController) getAllInbounds(c *gin.Context) {
 func (a *APIController) getSingleInbound(c *gin.Context) {
 	a.inboundController.getInbound(c)
 }
+func (a *APIController) getClientTraffics(c *gin.Context) {
+	a.inboundController.getClientTraffics(c)
+}
 func (a *APIController) addInbound(c *gin.Context) {
 	a.inboundController.addInbound(c)
 }

+ 10 - 0
web/controller/inbound.go

@@ -78,6 +78,16 @@ func (a *InboundController) getInbound(c *gin.Context) {
 	jsonObj(c, inbound, nil)
 }
 
+func (a *InboundController) getClientTraffics(c *gin.Context) {
+	email := c.Param("email")
+	clientTraffics, err := a.inboundService.GetClientTrafficByEmail(email)
+	if err != nil {
+		jsonMsg(c, "Error getting traffics", err)
+		return
+	}
+	jsonObj(c, clientTraffics, nil)
+}
+
 func (a *InboundController) addInbound(c *gin.Context) {
 	inbound := &model.Inbound{}
 	err := c.ShouldBind(inbound)

+ 1 - 1
web/service/inbound.go

@@ -710,7 +710,7 @@ func (s *InboundService) GetClientTrafficByEmail(email string) (traffic []*xray.
 	db := database.GetDB()
 	var traffics []*xray.ClientTraffic
 
-	err = db.Model(xray.ClientTraffic{}).Where("email like ?", "%"+email+"%").Find(&traffics).Error
+	err = db.Model(xray.ClientTraffic{}).Where("email = ?", email).Find(&traffics).Error
 	if err != nil {
 		if err == gorm.ErrRecordNotFound {
 			logger.Warning(err)