All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m3s
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package h5
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
|
enterpriseDeviceService "github.com/break/junhong_cmp_fiber/internal/service/enterprise_device"
|
|
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
|
"github.com/break/junhong_cmp_fiber/pkg/response"
|
|
)
|
|
|
|
type EnterpriseDeviceHandler struct {
|
|
service *enterpriseDeviceService.Service
|
|
}
|
|
|
|
func NewEnterpriseDeviceHandler(service *enterpriseDeviceService.Service) *EnterpriseDeviceHandler {
|
|
return &EnterpriseDeviceHandler{service: service}
|
|
}
|
|
|
|
func (h *EnterpriseDeviceHandler) ListDevices(c *fiber.Ctx) error {
|
|
var req dto.H5EnterpriseDeviceListReq
|
|
if err := c.QueryParser(&req); err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
|
}
|
|
|
|
serviceReq := &dto.EnterpriseDeviceListReq{
|
|
Page: req.Page,
|
|
PageSize: req.PageSize,
|
|
VirtualNo: req.VirtualNo,
|
|
}
|
|
|
|
result, err := h.service.ListDevicesForEnterprise(c.UserContext(), serviceReq)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.SuccessWithPagination(c, result.List, result.Total, req.Page, req.PageSize)
|
|
}
|
|
|
|
func (h *EnterpriseDeviceHandler) GetDeviceDetail(c *fiber.Ctx) error {
|
|
deviceIDStr := c.Params("device_id")
|
|
deviceID, err := strconv.ParseUint(deviceIDStr, 10, 64)
|
|
if err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "设备ID格式错误")
|
|
}
|
|
|
|
result, err := h.service.GetDeviceDetail(c.UserContext(), uint(deviceID))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Success(c, result)
|
|
}
|