All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 4m17s
- 为 enterprise_card_authorization_dto.go 中的 DTO 添加 path 标签 - 为 customer_account_dto.go 中的 DTO 添加 path 标签并重构结构 - 为 enterprise_dto.go 中的 DTO 添加 path 标签并重构结构 - 更新 handler 和 service 层使用正确的请求体类型
107 lines
2.7 KiB
Go
107 lines
2.7 KiB
Go
package admin
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
"github.com/break/junhong_cmp_fiber/internal/model"
|
|
enterpriseService "github.com/break/junhong_cmp_fiber/internal/service/enterprise"
|
|
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
|
"github.com/break/junhong_cmp_fiber/pkg/response"
|
|
)
|
|
|
|
type EnterpriseHandler struct {
|
|
service *enterpriseService.Service
|
|
}
|
|
|
|
func NewEnterpriseHandler(service *enterpriseService.Service) *EnterpriseHandler {
|
|
return &EnterpriseHandler{service: service}
|
|
}
|
|
|
|
func (h *EnterpriseHandler) Create(c *fiber.Ctx) error {
|
|
var req model.CreateEnterpriseReq
|
|
if err := c.BodyParser(&req); err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
|
}
|
|
|
|
result, err := h.service.Create(c.UserContext(), &req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Success(c, result)
|
|
}
|
|
|
|
func (h *EnterpriseHandler) List(c *fiber.Ctx) error {
|
|
var req model.EnterpriseListReq
|
|
if err := c.QueryParser(&req); err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
|
}
|
|
|
|
result, err := h.service.List(c.UserContext(), &req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.SuccessWithPagination(c, result.Items, result.Total, result.Page, result.Size)
|
|
}
|
|
|
|
func (h *EnterpriseHandler) Update(c *fiber.Ctx) error {
|
|
idStr := c.Params("id")
|
|
id, err := strconv.ParseUint(idStr, 10, 64)
|
|
if err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "无效的企业ID")
|
|
}
|
|
|
|
var req model.UpdateEnterpriseBody
|
|
if err := c.BodyParser(&req); err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
|
}
|
|
|
|
result, err := h.service.Update(c.UserContext(), uint(id), &req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Success(c, result)
|
|
}
|
|
|
|
func (h *EnterpriseHandler) UpdateStatus(c *fiber.Ctx) error {
|
|
idStr := c.Params("id")
|
|
id, err := strconv.ParseUint(idStr, 10, 64)
|
|
if err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "无效的企业ID")
|
|
}
|
|
|
|
var req model.UpdateEnterpriseStatusBody
|
|
if err := c.BodyParser(&req); err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
|
}
|
|
|
|
if err := h.service.UpdateStatus(c.UserContext(), uint(id), req.Status); err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Success(c, nil)
|
|
}
|
|
|
|
func (h *EnterpriseHandler) UpdatePassword(c *fiber.Ctx) error {
|
|
idStr := c.Params("id")
|
|
id, err := strconv.ParseUint(idStr, 10, 64)
|
|
if err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "无效的企业ID")
|
|
}
|
|
|
|
var req model.UpdateEnterprisePasswordBody
|
|
if err := c.BodyParser(&req); err != nil {
|
|
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
|
}
|
|
|
|
if err := h.service.UpdatePassword(c.UserContext(), uint(id), req.Password); err != nil {
|
|
return err
|
|
}
|
|
|
|
return response.Success(c, nil)
|
|
}
|