新增设备模块
This commit is contained in:
57
api/device.go
Normal file
57
api/device.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go-desk-service/libs"
|
||||
"go-desk-service/models"
|
||||
"go-desk-service/services"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type DeviceApi struct{}
|
||||
|
||||
type DeviceInfo struct {
|
||||
Hostname string `form:"hostname" json:"hostname" uri:"hostname" xml:"hostname" binding:"required"`
|
||||
Platform string `form:"platform" json:"platform" uri:"platform" xml:"platform" binding:"required"`
|
||||
PlatformVersion string `form:"platform_version" json:"platform_version" uri:"platform_version" xml:"platform_version" binding:"required"`
|
||||
Mac string `form:"mac" json:"mac" uri:"mac" xml:"mac" binding:"required"`
|
||||
CPU string `form:"cpu" json:"cpu" uri:"cpu" xml:"cpu" binding:"required"`
|
||||
Mem string `form:"mem" json:"mem" uri:"mem" xml:"mem" binding:"required"`
|
||||
Disk string `form:"disk" json:"disk" uri:"disk" xml:"disk" binding:"required"`
|
||||
}
|
||||
|
||||
func (*DeviceApi) SevaDeviceInfo(ctx *gin.Context) {
|
||||
var res *libs.ErrorInfo
|
||||
var paramsJson DeviceInfo
|
||||
if err := ctx.ShouldBindJSON(¶msJson); err != nil {
|
||||
res = libs.ErrorCode["ParamsError"]
|
||||
fmt.Println(err)
|
||||
ctx.JSON(http.StatusOK, gin.H{
|
||||
"code": res.Code,
|
||||
"msg": res.Msg,
|
||||
"data": res.Data,
|
||||
})
|
||||
return
|
||||
}
|
||||
// 获取当前的用户ID跟token信息
|
||||
token, _ := ctx.Get("token")
|
||||
// 保存当前的设备
|
||||
DeviceService := services.InitDeviceService()
|
||||
DeviceService.UpdateByToken(token.(string), &models.Device{
|
||||
Hostname: paramsJson.Hostname,
|
||||
Platform: paramsJson.Platform,
|
||||
PlatformVersion: paramsJson.PlatformVersion,
|
||||
Mac: paramsJson.Mac,
|
||||
Cpu: paramsJson.CPU,
|
||||
Mem: paramsJson.Mem,
|
||||
Disk: paramsJson.Disk,
|
||||
})
|
||||
res = libs.ErrorCode["SevaSuccessful"]
|
||||
ctx.JSON(http.StatusOK, gin.H{
|
||||
"code": res.Code,
|
||||
"msg": res.Msg,
|
||||
"data": res.Data,
|
||||
})
|
||||
}
|
||||
@@ -72,6 +72,7 @@ func (*User) Login(ctx *gin.Context) {
|
||||
})
|
||||
// 登录成功之后查看设备是否是当前设备
|
||||
DeviceService := services.InitDeviceService()
|
||||
DeviceService.SetUserLoginStatus(loginResp.UserId, loginResp.AccessToken, paramsJson.DeviceId)
|
||||
ctx.JSON(http.StatusOK, gin.H{
|
||||
"code": 200,
|
||||
"msg": "登录成功",
|
||||
|
||||
Reference in New Issue
Block a user