package repository import ( "encoding/json" "gorm.io/gorm" "wireguard-dashboard/client" "wireguard-dashboard/http/param" "wireguard-dashboard/model/vo" "wireguard-dashboard/utils" ) type clientRepo struct { *gorm.DB } func Client() clientRepo { return clientRepo{ client.DB, } } // List // @description: 列表 // @receiver r // @param p // @return data // @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"). Select("twc.id", "twc.created_at", "twc.updated_at", "twc.name", "twc.email", "twc.subnet_range", "twc.ip_allocation", "twc.allowed_ips", "twc.extra_allowed_ips", "twc.endpoint", "twc.use_server_dns", "twc.enable_after_creation", "twc.enabled", "twc.keys as keys_str", "tu.name as create_user"). Find(&data).Offset(-1).Limit(-1).Count(&total).Error if err != nil { return } for i, v := range data { if v.KeysStr != "" { _ = json.Unmarshal([]byte(v.KeysStr), &data[i].Keys) } } return }