feat: 迁移商务账号层级和列表管理

This commit is contained in:
Yvan
2026-11-03 17:56:33 +08:00
parent ce4b54a2e2
commit 794001dfbe
24 changed files with 1229 additions and 12 deletions
+1 -1
View File
@@ -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)
}
}
+59 -2
View File
@@ -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) {
+4
View File
@@ -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)
}