🎨做了一些bug修复和变动

This commit is contained in:
coward
2024-05-24 15:19:26 +08:00
parent e216725096
commit e172b3c838
12 changed files with 64 additions and 49 deletions

View File

@@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"gitee.ltd/lxh/logger/log"
"github.com/spf13/cast"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"gorm.io/gorm"
"strings"
@@ -34,10 +33,29 @@ func Client() clientRepo {
// @return total
// @return err
func (r clientRepo) List(p param.ClientList) (data []vo.Client, total int64, err error) {
err = r.Table("t_wg_client as twc").Scopes(utils.Page(p.Current, p.Size)).Joins("LEFT JOIN t_user as tu ON twc.user_id = tu.id").
sel := r.Table("t_wg_client as twc").
Scopes(utils.Page(p.Current, p.Size)).
Joins("LEFT JOIN t_user as tu ON twc.user_id = tu.id").
Select("twc.id", "twc.created_at", "twc.updated_at", "twc.name", "twc.email", "twc.subnet_range", "twc.ip_allocation as ip_allocation_str", "twc.allowed_ips as allowed_ips_str",
"twc.extra_allowed_ips as extra_allowed_ips_str", "twc.endpoint", "twc.use_server_dns", "twc.enable_after_creation", "twc.enabled", "twc.keys as keys_str", "tu.name as create_user").
Order("twc.created_at DESC").Find(&data).Offset(-1).Limit(-1).Count(&total).Error
"twc.extra_allowed_ips as extra_allowed_ips_str", "twc.endpoint", "twc.use_server_dns", "twc.enable_after_creation", "twc.enabled", "twc.keys as keys_str", "tu.name as create_user")
if p.Name != "" {
sel.Where("twc.name LIKE ?", "%"+p.Name+"%")
}
if p.Email != "" {
sel.Where("twc.email = ?", p.Email)
}
if p.Ip != "" {
sel.Where("twc.ip_allocation LIKE ?", "%"+p.Ip+"%")
}
if p.Enabled != nil {
sel.Where("twc.enabled = ?", p.Enabled)
}
err = sel.Order("twc.created_at DESC").Find(&data).Offset(-1).Limit(-1).Count(&total).Error
if err != nil {
return
@@ -84,7 +102,7 @@ func (r clientRepo) Save(p param.SaveClient, adminId string) (client *entity.Cli
UseServerDns: p.UseServerDNS,
EnableAfterCreation: p.EnabledAfterCreation,
UserId: adminId,
Enabled: cast.ToBool(p.Enabled),
Enabled: p.Enabled,
}
// id不为空更新信息
@@ -138,7 +156,7 @@ func (r clientRepo) Save(p param.SaveClient, adminId string) (client *entity.Cli
EnableAfterCreation: p.EnabledAfterCreation,
Keys: string(keysStr),
UserId: adminId,
Enabled: true,
Enabled: p.Enabled,
}
err = r.Model(&entity.Client{}).Create(ent).Error

View File

@@ -24,7 +24,7 @@ func Server() server {
// @return data
// @return err
func (r server) GetServer() (data *vo.Server, err error) {
err = r.Model(&entity.Server{}).Select("id", "ip_scope as ip_scope_str", "listen_port", "private_key", "public_key", "post_up_script", "pre_down_script", "post_down_script").First(&data).Error
err = r.Model(&entity.Server{}).Select("id", "ip_scope", "listen_port", "private_key", "public_key", "post_up_script", "pre_down_script", "post_down_script").First(&data).Error
return
}