You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.1 KiB
91 lines
2.1 KiB
package handler
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"laic-backend/common"
|
|
"laic-backend/service"
|
|
"laic-backend/vo"
|
|
)
|
|
|
|
// GetDronePage 无人机分页列表
|
|
func GetDronePage(c *gin.Context) {
|
|
var req vo.DronePageReq
|
|
_ = c.ShouldBindQuery(&req)
|
|
if req.PageNum <= 0 {
|
|
req.PageNum = 1
|
|
}
|
|
if req.PageSize <= 0 {
|
|
req.PageSize = 10
|
|
}
|
|
page, busiErr := service.DefaultDroneService.GetPage(common.GetUserId(c), common.IsAdmin(c), &req)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
common.OKWithData(c, page)
|
|
}
|
|
|
|
// GetDrone 无人机详情
|
|
func GetDrone(c *gin.Context) {
|
|
id, busiErr := parseID(c)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
drone, busiErr := service.DefaultDroneService.GetDetail(common.GetUserId(c), common.IsAdmin(c), id)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
common.OKWithData(c, drone)
|
|
}
|
|
|
|
// GetDroneTelemetry 无人机实时遥测
|
|
func GetDroneTelemetry(c *gin.Context) {
|
|
id, busiErr := parseID(c)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
telemetry, busiErr := service.DefaultDroneService.GetTelemetry(common.GetUserId(c), common.IsAdmin(c), id)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
common.OKWithData(c, telemetry)
|
|
}
|
|
|
|
// UpdateDrone 更新无人机
|
|
func UpdateDrone(c *gin.Context) {
|
|
id, busiErr := parseID(c)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
var req vo.DroneUpdateReq
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
common.FailWithBindError(c, common.ErrParam, err)
|
|
return
|
|
}
|
|
drone, busiErr := service.DefaultDroneService.Update(common.GetUserId(c), common.IsAdmin(c), id, &req)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
common.OKWithData(c, drone)
|
|
}
|
|
|
|
// DeleteDrone 删除无人机
|
|
func DeleteDrone(c *gin.Context) {
|
|
id, busiErr := parseID(c)
|
|
if busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
if busiErr := service.DefaultDroneService.Delete(common.GetUserId(c), common.IsAdmin(c), id); busiErr != nil {
|
|
common.FailWithBusiError(c, busiErr)
|
|
return
|
|
}
|
|
common.OK(c)
|
|
}
|
|
|