From 11bff57f234b55137cc71a1f0825826c600b2bca Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Thu, 20 Apr 2023 19:16:06 +0200 Subject: [PATCH] [feature] add getClientTraffics api --- web/controller/api.go | 4 ++++ web/controller/inbound.go | 9 +++++++++ web/service/inbound.go | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/web/controller/api.go b/web/controller/api.go index 570f39d1..652fe640 100644 --- a/web/controller/api.go +++ b/web/controller/api.go @@ -19,6 +19,7 @@ func (a *APIController) initRouter(g *gin.RouterGroup) { g.GET("/", a.inbounds) g.GET("/get/:id", a.inbound) + g.GET("/getClientTraffics/:email", a.getClientTraffics) g.POST("/add", a.addInbound) g.POST("/del/:id", a.delInbound) g.POST("/update/:id", a.updateInbound) @@ -38,6 +39,9 @@ func (a *APIController) inbounds(c *gin.Context) { func (a *APIController) inbound(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) } diff --git a/web/controller/inbound.go b/web/controller/inbound.go index 9ca03696..82b227fe 100644 --- a/web/controller/inbound.go +++ b/web/controller/inbound.go @@ -75,6 +75,15 @@ 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{} diff --git a/web/service/inbound.go b/web/service/inbound.go index d12f3604..344c3910 100644 --- a/web/service/inbound.go +++ b/web/service/inbound.go @@ -672,7 +672,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)