feat: 迁移商务账号层级和列表管理
This commit is contained in:
@@ -98,7 +98,7 @@ func TestGinStartupLogsEveryRegisteredRoute(t *testing.T) {
|
||||
if got, want := strings.Count(text, `"msg":"router registered"`), len(engine.Routes()); got != want {
|
||||
t.Fatalf("registered route log count = %d, want %d", got, want)
|
||||
}
|
||||
if !strings.Contains(text, `"msg":"router register success"`) || !strings.Contains(text, `"route_count":199`) {
|
||||
if !strings.Contains(text, `"msg":"router register success"`) || !strings.Contains(text, `"route_count":203`) {
|
||||
t.Fatalf("startup route summary is missing: %s", text)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,14 +5,71 @@ import (
|
||||
"github.com/go-kratos/kratos/v3/errors"
|
||||
"kra/internal/service/business"
|
||||
"kra/internal/service/dto"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Business struct {
|
||||
preference *business.UserPreferenceService
|
||||
accounts *business.AccountService
|
||||
}
|
||||
|
||||
func NewBusiness(preference *business.UserPreferenceService) *Business {
|
||||
return &Business{preference: preference}
|
||||
func NewBusiness(preference *business.UserPreferenceService, accounts *business.AccountService) *Business {
|
||||
return &Business{preference: preference, accounts: accounts}
|
||||
}
|
||||
|
||||
func (h *Business) AccountList(c *gin.Context) {
|
||||
var req dto.BusinessAccountQuery
|
||||
if err := c.ShouldBindQuery(&req); err != nil {
|
||||
Fail(c, "查询参数格式错误")
|
||||
return
|
||||
}
|
||||
value, err := h.accounts.List(c.Request.Context(), &req)
|
||||
if err != nil {
|
||||
Fail(c, errors.FromError(err).Message)
|
||||
return
|
||||
}
|
||||
OKWithData(c, value)
|
||||
}
|
||||
|
||||
func (h *Business) Account(c *gin.Context) {
|
||||
id, err := strconv.ParseUint(c.Param("userId"), 10, 64)
|
||||
if err != nil || id == 0 {
|
||||
Fail(c, "商务用户 ID 不正确")
|
||||
return
|
||||
}
|
||||
value, err := h.accounts.Find(c.Request.Context(), uint(id))
|
||||
if err != nil {
|
||||
Fail(c, errors.FromError(err).Message)
|
||||
return
|
||||
}
|
||||
OKWithData(c, value)
|
||||
}
|
||||
|
||||
func (h *Business) CreateAccount(c *gin.Context) {
|
||||
var req dto.BusinessAccountRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, "商务账号参数格式错误")
|
||||
return
|
||||
}
|
||||
value, err := h.accounts.Create(c.Request.Context(), &req)
|
||||
if err != nil {
|
||||
Fail(c, errors.FromError(err).Message)
|
||||
return
|
||||
}
|
||||
OKWithData(c, value)
|
||||
}
|
||||
|
||||
func (h *Business) UpdateAccount(c *gin.Context) {
|
||||
var req dto.BusinessAccountRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
Fail(c, "商务账号参数格式错误")
|
||||
return
|
||||
}
|
||||
if err := h.accounts.Update(c.Request.Context(), &req); err != nil {
|
||||
Fail(c, errors.FromError(err).Message)
|
||||
return
|
||||
}
|
||||
OK(c)
|
||||
}
|
||||
|
||||
func (h *Business) UserPreference(c *gin.Context) {
|
||||
|
||||
@@ -6,6 +6,10 @@ import (
|
||||
)
|
||||
|
||||
func RegisterBusiness(private *gin.RouterGroup, h *handler.Business) {
|
||||
private.GET("/sw/business/list", h.AccountList)
|
||||
private.GET("/sw/business/:userId", h.Account)
|
||||
private.POST("/sw/business", h.CreateAccount)
|
||||
private.PUT("/sw/business", h.UpdateAccount)
|
||||
private.GET("/sw/user/preference", h.UserPreference)
|
||||
private.PUT("/sw/user/preference", h.UpdateUserPreference)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user