Files
kra-new/internal/server/handler/business_portrait.go
T

49 lines
1.2 KiB
Go

package handler
import (
"github.com/gin-gonic/gin"
"github.com/go-kratos/kratos/v3/errors"
"kra/internal/service/business"
"kra/internal/service/dto"
"strconv"
)
type BusinessPortrait struct {
service *business.BusinessPortraitService
}
func NewBusinessPortrait(service *business.BusinessPortraitService) *BusinessPortrait {
return &BusinessPortrait{service: service}
}
func (h *BusinessPortrait) ForUser(c *gin.Context) {
id, err := strconv.ParseUint(c.Param("userId"), 10, 64)
if err != nil {
Fail(c, "商务用户 ID 不正确")
return
}
var req dto.BusinessPortraitQuery
if c.ShouldBindQuery(&req) != nil {
Fail(c, "商务画像查询参数不正确")
return
}
result, err := h.service.ForUser(c.Request.Context(), uint(id), &req)
if err != nil {
Fail(c, errors.FromError(err).Message)
return
}
OKWithData(c, result)
}
func (h *BusinessPortrait) ForBinding(c *gin.Context) {
var req dto.BindingPortraitQuery
if c.ShouldBindQuery(&req) != nil {
Fail(c, "商务画像查询参数不正确")
return
}
result, err := h.service.ForBinding(c.Request.Context(), &req)
if err != nil {
Fail(c, errors.FromError(err).Message)
return
}
OKWithData(c, result)
}