Răsfoiți Sursa

refactor(admin): 优化网关 IP 管理功能

- 移除了 SearchGatewayIpParams 结构体中不必要的 gorm 标签
- 更新了 Gatewayip模型,添加了 json 和 form 标签
- 修改了网关 IP 管理相关 API 的请求绑定方式,从 ShouldBindJSON 改为 ShouldBind
- 优化了网关 IP 列表查询逻辑,去除了未使用的查询条件
fusu 2 săptămâni în urmă
părinte
comite
1e6c9f2215

+ 3 - 3
api/v1/admin/gatewayIp.go

@@ -5,8 +5,8 @@ type SearchGatewayIpParams struct {
 	Name     string `form:"name" json:"name"`
 	NodeArea string `form:"nodeArea" json:"nodeArea"`
 	Operator int	`form:"operator" json:"operator"`
-	BanUdp       int `gorm:"null" json:"banUdp" form:"banUdp" default:"0"`
-	BanOverseas int `gorm:"null" json:"banOverseas" form:"banOverseas" default:"0"`
+	BanUdp       int `json:"banUdp" form:"banUdp" default:"0"`
+	BanOverseas int `json:"banOverseas" form:"banOverseas" default:"0"`
 	Comment  string `form:"comment" json:"comment"`
 	Current  int	`form:"current" json:"current" default:"1"`
 	PageSize int	`form:"pageSize" json:"pageSize" default:"10"`
@@ -15,7 +15,7 @@ type SearchGatewayIpParams struct {
 }
 
 type GatewayIp struct {
-	Id int `json:"id" form:"id" validate:"required min=1" `
+	Id int `json:"id" form:"id" validate:"required,min=1" `
 }
 
 type DeleteGatewayIpRequest struct {

+ 6 - 6
internal/handler/admin/gatewayipadmin.go

@@ -27,7 +27,7 @@ func NewGatewayIpAdminHandler(
 
 func (h *GatewayIpAdminHandler) GetGatewayIpAdmin(ctx *gin.Context) {
 	var req v1admin.GatewayIp
-	if err := ctx.ShouldBindJSON(&req); err != nil {
+	if err := ctx.ShouldBind(&req); err != nil {
 		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, nil)
 		return
 	}
@@ -42,7 +42,7 @@ func (h *GatewayIpAdminHandler) GetGatewayIpAdmin(ctx *gin.Context) {
 
 func (h *GatewayIpAdminHandler) GetGatewayIpAdminList(ctx *gin.Context) {
 	var req v1admin.SearchGatewayIpParams
-	if err := ctx.ShouldBindJSON(&req); err != nil {
+	if err := ctx.ShouldBind(&req); err != nil {
 		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, nil)
 		return
 	}
@@ -56,7 +56,7 @@ func (h *GatewayIpAdminHandler) GetGatewayIpAdminList(ctx *gin.Context) {
 
 func (h *GatewayIpAdminHandler) AddGatewayIpAdmin(ctx *gin.Context) {
 	var req model.Gatewayip
-	if err := ctx.ShouldBindJSON(&req); err != nil {
+	if err := ctx.ShouldBind(&req); err != nil {
 		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, nil)
 		return
 	}
@@ -70,7 +70,7 @@ func (h *GatewayIpAdminHandler) AddGatewayIpAdmin(ctx *gin.Context) {
 
 func (h *GatewayIpAdminHandler) EditGatewayIpAdmin(ctx *gin.Context) {
 	var req model.Gatewayip
-	if err := ctx.ShouldBindJSON(&req); err != nil {
+	if err := ctx.ShouldBind(&req); err != nil {
 		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, nil)
 		return
 	}
@@ -84,7 +84,7 @@ func (h *GatewayIpAdminHandler) EditGatewayIpAdmin(ctx *gin.Context) {
 
 func (h *GatewayIpAdminHandler) DeleteGatewayIpAdmin(ctx *gin.Context) {
 	var req v1admin.GatewayIp
-	if err := ctx.ShouldBindJSON(&req); err != nil {
+	if err := ctx.ShouldBind(&req); err != nil {
 		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, nil)
 		return
 	}
@@ -98,7 +98,7 @@ func (h *GatewayIpAdminHandler) DeleteGatewayIpAdmin(ctx *gin.Context) {
 
 func (h *GatewayIpAdminHandler) DeleteGatewayIpsAdmin(ctx *gin.Context) {
 	var req v1admin.DeleteGatewayIpRequest
-	if err := ctx.ShouldBindJSON(&req); err != nil {
+	if err := ctx.ShouldBind(&req); err != nil {
 		v1.HandleError(ctx, http.StatusBadRequest, v1.ErrBadRequest, nil)
 		return
 	}

+ 9 - 9
internal/model/gatewayip.go

@@ -5,15 +5,15 @@ import (
 )
 
 type Gatewayip struct {
-	Id           int `gorm:"primary"`
-	HostId       int `gorm:"not null"`
-	Ip           string `gorm:"not null"`
-	Name         string `gorm:"null"`
-	NodeArea     string `gorm:"null"`
-	Operator     int `gorm:"not null;default:1"`
-	BanOverseas  int `gorm:"null;default:0"`
-	BanUdp       int `gorm:"null;default:0"`
-	Comment      string `gorm:"null"`
+	Id           int `gorm:"primary" json:"id" form:"id"`
+	HostId       int `gorm:"not null" json:"hostId" form:"hostId"`
+	Ip           string `gorm:"not null" json:"ip" form:"ip"`
+	Name         string `gorm:"null" json:"name" form:"name"`
+	NodeArea     string `gorm:"null" json:"nodeArea" form:"nodeArea"`
+	Operator     int `gorm:"not null;default:1" json:"operator" form:"operator"`
+	BanOverseas  int `gorm:"null;default:0" json:"banOverseas" form:"banOverseas"`
+	BanUdp       int `gorm:"null;default:0" json:"banUdp" form:"banUdp"`
+	Comment      string `gorm:"null" json:"comment" form:"comment"`
 	CreatedAt    time.Time `json:"createdAt" form:"createdAt"`
 	UpdatedAt    time.Time `json:"updatedAt" form:"updatedAt"`
 }

+ 1 - 13
internal/repository/admin/gatewayipadmin.go

@@ -42,7 +42,7 @@ func (r *gatewayIpAdminRepository) GetGatewayGroupIpList(ctx context.Context,req
 	var res []model.Gatewayip
 	var total int64
 
-	query := r.Db.WithContext(ctx).Model(&model.GateWayGroupIp{})
+	query := r.Db.WithContext(ctx).Model(&model.Gatewayip{})
 	if  req.Ip != "" {
 		trimmedName := strings.TrimSpace(req.Ip)
 		// 使用 LIKE 进行模糊匹配
@@ -66,18 +66,6 @@ func (r *gatewayIpAdminRepository) GetGatewayGroupIpList(ctx context.Context,req
 		query = query.Where("node_area LIKE CONCAT('%', ?, '%')", trimmedName)
 	}
 
-	// 如果 Operator 被提供了
-	if req.Operator != 0 {
-		query = query.Where("operator = ?", req.Operator)
-	}
-
-	if req.BanUdp != 0 {
-		query = query.Where("ban_udp = ?", req.BanUdp)
-	}
-
-	if req.BanOverseas != 0 {
-		query = query.Where("ban_overseas = ?", req.BanOverseas)
-	}
 
 	if req.Comment != "" {
 		trimmedName := strings.TrimSpace(req.Comment)