feat: client 增删改查
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package request
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// PageInfo Paging common input parameter structure
|
||||
type PageInfo struct {
|
||||
Current int `json:"current" form:"current"` // 页码
|
||||
PageSize int `json:"pageSize" form:"pageSize"` // 每页大小
|
||||
Keyword string `json:"keyword" form:"keyword"` // 关键字
|
||||
}
|
||||
|
||||
func (r *PageInfo) Paginate() func(db *gorm.DB) *gorm.DB {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
if r.Current <= 0 {
|
||||
r.Current = 1
|
||||
}
|
||||
switch {
|
||||
case r.PageSize > 100:
|
||||
r.PageSize = 100
|
||||
case r.PageSize <= 0:
|
||||
r.PageSize = 10
|
||||
}
|
||||
offset := (r.Current - 1) * r.PageSize
|
||||
return db.Offset(offset).Limit(r.PageSize)
|
||||
}
|
||||
}
|
||||
|
||||
// GetById Find by id structure
|
||||
type GetById struct {
|
||||
ID int `json:"id" form:"id"` // 主键ID
|
||||
}
|
||||
|
||||
func (r *GetById) Uint() uint {
|
||||
return uint(r.ID)
|
||||
}
|
||||
|
||||
type IdsReq struct {
|
||||
Ids []int `json:"ids" form:"ids"`
|
||||
}
|
||||
|
||||
// GetAuthorityId Get role by id structure
|
||||
type GetAuthorityId struct {
|
||||
AuthorityId uint `json:"authorityId" form:"authorityId"` // 角色ID
|
||||
}
|
||||
|
||||
type Empty struct{}
|
||||
@@ -0,0 +1,8 @@
|
||||
package response
|
||||
|
||||
type PageResult struct {
|
||||
List interface{} `json:"list"`
|
||||
Total int64 `json:"total"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"pageSize"`
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package response
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
Code int `json:"code"`
|
||||
Data interface{} `json:"data"`
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
const (
|
||||
SUCCESS = 200
|
||||
ERROR = 7
|
||||
)
|
||||
|
||||
// Result 返回结果
|
||||
func Result(code int, data interface{}, msg string, c *gin.Context) {
|
||||
c.JSON(http.StatusOK, Response{
|
||||
code,
|
||||
data,
|
||||
msg,
|
||||
})
|
||||
}
|
||||
|
||||
// Ok 成功返回
|
||||
func Ok(c *gin.Context) {
|
||||
Result(SUCCESS, map[string]interface{}{}, "操作成功", c)
|
||||
}
|
||||
|
||||
// OkWithData 带数据成功返回
|
||||
func OkWithData(data interface{}, c *gin.Context) {
|
||||
Result(SUCCESS, data, "操作成功", c)
|
||||
}
|
||||
|
||||
// OkWithMsg 带信息成功返回
|
||||
func OkWithMsg(msg string, c *gin.Context) {
|
||||
Result(SUCCESS, map[string]interface{}{}, msg, c)
|
||||
}
|
||||
|
||||
// Fail 失败返回
|
||||
func Fail(code int, msg string, c *gin.Context) {
|
||||
Result(code, map[string]interface{}{}, "操作失败", c)
|
||||
}
|
||||
|
||||
// FailWithMsg 带信息失败返回
|
||||
func FailWithMsg(msg string, c *gin.Context) {
|
||||
Result(ERROR, map[string]interface{}{}, msg, c)
|
||||
}
|
||||
|
||||
// NoAuth 未授权返回
|
||||
func NoAuth(message string, c *gin.Context) {
|
||||
c.JSON(http.StatusUnauthorized, Response{
|
||||
7,
|
||||
nil,
|
||||
message,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package request
|
||||
|
||||
import "github.com/mojocn/base64Captcha"
|
||||
|
||||
// configJsonBody json request body.
|
||||
type CaptchaReqBody struct {
|
||||
Id string
|
||||
CaptchaType string
|
||||
VerifyValue string
|
||||
DriverAudio *base64Captcha.DriverAudio
|
||||
DriverString *base64Captcha.DriverString
|
||||
DriverChinese *base64Captcha.DriverChinese
|
||||
DriverMath *base64Captcha.DriverMath
|
||||
DriverDigit *base64Captcha.DriverDigit
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package request
|
||||
|
||||
import common "sundynix-go/model/commom/request"
|
||||
|
||||
type GetClientList struct {
|
||||
common.PageInfo
|
||||
ClientId string `json:"clientId" form:"clientId"`
|
||||
Name string `json:"name" form:"name"`
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package request
|
||||
|
||||
import common "sundynix-go/model/commom/request"
|
||||
|
||||
type Login struct {
|
||||
Account string `json:"account"`
|
||||
Password string `json:"password"`
|
||||
Captcha string `json:"captcha"`
|
||||
CaptchaId string `json:"captchaId"`
|
||||
}
|
||||
|
||||
type GetUserList struct {
|
||||
common.PageInfo
|
||||
Account string `json:"account" form:"account"`
|
||||
Phone string `json:"phone" form:"phone"`
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package response
|
||||
|
||||
type CaptchaRes struct {
|
||||
CaptchaId string `json:"captchaId"`
|
||||
Captcha string `json:"captcha"`
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package response
|
||||
|
||||
import "sundynix-go/model/system"
|
||||
|
||||
type SysUserResponse struct {
|
||||
User system.User `json:"user"`
|
||||
}
|
||||
|
||||
type LoginResponse struct {
|
||||
User system.User `json:"user"`
|
||||
Token string `json:"token"`
|
||||
ExpiresAt int64 `json:"expiresAt"`
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package system
|
||||
|
||||
import "sundynix-go/global"
|
||||
|
||||
type Client struct {
|
||||
global.BaseModel
|
||||
ClientId string `gorm:"size:20;" json:"clientId"`
|
||||
Name string `gorm:"size:50;" json:"name"`
|
||||
GrantType string `gorm:"size:50;" json:"grantType"`
|
||||
AdditionalInfo string `gorm:"type:text" json:"additionalInfo"`
|
||||
ActiveTimeout uint `json:"activeTimeout"`
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SysOperationRecord struct {
|
||||
global.BaseModel
|
||||
Ip string `json:"ip" form:"ip" gorm:"column:ip;comment:请求ip"` // 请求ip
|
||||
Method string `json:"method" form:"method" gorm:"column:method;comment:请求方法"` // 请求方法
|
||||
Path string `json:"path" form:"path" gorm:"column:path;comment:请求路径"` // 请求路径
|
||||
Status int `json:"status" form:"status" gorm:"column:status;comment:请求状态"` // 请求状态
|
||||
Latency time.Duration `json:"latency" form:"latency" gorm:"column:latency;comment:延迟" swaggertype:"string"` // 延迟
|
||||
Agent string `json:"agent" form:"agent" gorm:"type:text;column:agent;comment:代理"` // 代理
|
||||
ErrorMessage string `json:"error_message" form:"error_message" gorm:"column:error_message;comment:错误信息"` // 错误信息
|
||||
Body string `json:"body" form:"body" gorm:"type:text;column:body;comment:请求Body"` // 请求Body
|
||||
Resp string `json:"resp" form:"resp" gorm:"type:text;column:resp;comment:响应Body"` // 响应Body
|
||||
UserID int `json:"user_id" form:"user_id" gorm:"column:user_id;comment:用户id"` // 用户id
|
||||
User User `json:"user"`
|
||||
}
|
||||
@@ -1,7 +1,14 @@
|
||||
package system
|
||||
|
||||
import "sundynix-go/global"
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
)
|
||||
|
||||
type Login interface {
|
||||
GetAccount() string
|
||||
GetUserId() uint
|
||||
GetUserInfo() any
|
||||
}
|
||||
type User struct {
|
||||
global.BaseModel
|
||||
ClientId string `gorm:"size:20;" json:"clientId"`
|
||||
@@ -9,3 +16,14 @@ type User struct {
|
||||
Password string `gorm:"size:100;" json:"-" form:"password"`
|
||||
Phone string `gorm:"size:11;" json:"phone" form:"phone"`
|
||||
}
|
||||
|
||||
func (u *User) GetAccount() string {
|
||||
return u.Account
|
||||
}
|
||||
func (u *User) GetUserId() uint {
|
||||
return u.Id
|
||||
}
|
||||
|
||||
func (u *User) GetUserInfo() any {
|
||||
return *u
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user