feat:完善信息
This commit is contained in:
99
app/common/api/api.go
Normal file
99
app/common/api/api.go
Normal file
@ -0,0 +1,99 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"SciencesServer/config"
|
||||
"SciencesServer/serve/logger"
|
||||
"SciencesServer/utils"
|
||||
"errors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
SuccessCode = 200 //成功的状态码
|
||||
FailureCode = 999 //失败的状态码
|
||||
)
|
||||
|
||||
type response struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
type ApiHandle func(c *gin.Context) interface{}
|
||||
|
||||
func GetSession() ApiHandle {
|
||||
return func(c *gin.Context) interface{} {
|
||||
value, _ := c.Get(config.TokenForSession)
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
func Bind(req interface{}) ApiHandle {
|
||||
return func(c *gin.Context) interface{} {
|
||||
var err error
|
||||
|
||||
if c.Request.Method == "GET" {
|
||||
err = c.ShouldBindQuery(req)
|
||||
} else {
|
||||
err = c.ShouldBindBodyWith(req, binding.JSON)
|
||||
}
|
||||
if err != nil {
|
||||
logger.ErrorF("Request URL【%s】Params Bind Error:%v", c.Request.URL, err)
|
||||
return errors.New("参数异常/缺失")
|
||||
}
|
||||
c.Set("params", utils.AnyToJSON(req))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func APISuccess(data ...interface{}) ApiHandle {
|
||||
return func(c *gin.Context) interface{} {
|
||||
resp := &response{
|
||||
Code: SuccessCode,
|
||||
Message: "ok",
|
||||
}
|
||||
if len(data) > 0 {
|
||||
resp.Data = data[0]
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func APIFailure(err error) ApiHandle {
|
||||
return func(c *gin.Context) interface{} {
|
||||
resp := &response{
|
||||
Code: FailureCode,
|
||||
Message: "failure",
|
||||
}
|
||||
if err != nil {
|
||||
resp.Message = err.Error()
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
c.Abort()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func APIResponse(err error, data ...interface{}) ApiHandle {
|
||||
return func(c *gin.Context) interface{} {
|
||||
resp := &response{
|
||||
Code: SuccessCode,
|
||||
Message: "ok",
|
||||
}
|
||||
if err != nil {
|
||||
resp.Code = FailureCode
|
||||
resp.Message = err.Error()
|
||||
c.JSON(http.StatusOK, resp)
|
||||
c.Abort()
|
||||
return nil
|
||||
}
|
||||
if len(data) > 0 {
|
||||
resp.Data = data[0]
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return nil
|
||||
}
|
||||
}
|
4
app/common/model/sys_sms.go
Normal file
4
app/common/model/sys_sms.go
Normal file
@ -0,0 +1,4 @@
|
||||
package model
|
||||
|
||||
type SysSms struct {
|
||||
}
|
21
app/common/model/tenant_user.go
Normal file
21
app/common/model/tenant_user.go
Normal file
@ -0,0 +1,21 @@
|
||||
package model
|
||||
|
||||
type TenantUser struct {
|
||||
Model
|
||||
ModelTenant
|
||||
UUID uint64 `gorm:"column:uuid;uniqueIndex:idx_sys_user_uuid;type:int;default:0;comment:用户唯一UUID" json:"-"`
|
||||
Avatar string `gorm:"column:avatar;type:varchar(255);default:null;comment:头像" json:"avatar"`
|
||||
Name string `gorm:"column:name;type:varchar(20);default:null;comment:真实姓名" json:"name"`
|
||||
Mobile string `gorm:"column:mobile;index:idx_sys_user_mobile;type:varchar(15);default:null;comment:联系方式" json:"mobile"`
|
||||
Email string `gorm:"column:email;type:varchar(50);default:null;comment:邮箱" json:"email"`
|
||||
ModelDeleted
|
||||
ModelAt
|
||||
}
|
||||
|
||||
func (m *TenantUser) TableName() string {
|
||||
return m.NewTableName("tenant_user")
|
||||
}
|
||||
|
||||
func NewTenantUser() *TenantUser {
|
||||
return &TenantUser{}
|
||||
}
|
Reference in New Issue
Block a user