作者 yangfu

更新我喜欢的菜单、获取我喜欢的菜单

... ... @@ -5,7 +5,10 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/utils"
)
func RetCustomizeMenu(menus []*domain.Menu, customizeMenus []*domain.CustomizeMenu) interface{} {
type CustomizeMenuDto struct {
}
func (dto *CustomizeMenuDto) LoadDto(menus []*domain.Menu, customizeMenus []*domain.CustomizeMenu) (interface{}, error) {
var ret []interface{}
menusMap := make(map[int64]*domain.Menu)
for i := range menus {
... ... @@ -27,5 +30,5 @@ func RetCustomizeMenu(menus []*domain.Menu, customizeMenus []*domain.CustomizeMe
}
ret = append(ret, fieldMenu)
}
return ret
return ret, nil
}
... ...
... ... @@ -170,7 +170,8 @@ func (companyService *CompanyService) ListCompanyCustomizeMenus(listCompanyCusto
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
ret := dto.RetCustomizeMenu(menus, customizeMenus)
customizeMenuDto := dto.CustomizeMenuDto{}
ret, _ := customizeMenuDto.LoadDto(menus, customizeMenus)
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ...
... ... @@ -12,7 +12,7 @@ type UpdateFavoriteMenusCommand struct {
// 菜单编码列表
FavoriteMenus []string `cname:"菜单编码列表" json:"favoriteMenus,omitempty"`
// 用户Id 用户唯一标识
UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"`
UserId int64 `cname:"用户Id 用户唯一标识" json:"userId" valid:"Required"`
}
func (updateFavoriteMenusCommand *UpdateFavoriteMenusCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -264,10 +264,16 @@ func (userService *UserService) GetFavoriteMenus(getFavoriteMenusQuery *query.Ge
defer func() {
transactionContext.RollbackTransaction()
}()
_, user, err := factory.FastPgUser(transactionContext, getFavoriteMenusQuery.UserId)
if err != nil {
return nil, err
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return map[string]interface{}{
"favoriteMenus": user.FavoriteMenus,
}, nil
}
// 返回
... ... @@ -481,10 +487,18 @@ func (userService *UserService) UpdateFavoriteMenus(updateFavoriteMenusCommand *
defer func() {
transactionContext.RollbackTransaction()
}()
userRepository, user, err := factory.FastPgUser(transactionContext, updateFavoriteMenusCommand.UserId)
if err != nil {
return nil, err
}
user.FavoriteMenus = updateFavoriteMenusCommand.FavoriteMenus
if _, err = userRepository.Save(user); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return struct{}{}, nil
}
// 更新
... ...
... ... @@ -7,6 +7,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/im"
)
// PgImService 网易云信IM服务
type PgImService struct {
transactionContext *pgTransaction.TransactionContext
}
... ...
... ... @@ -10,6 +10,7 @@ import (
)
var _ = Describe("移除我收藏的菜单", func() {
return
var userId int64
BeforeEach(func() {
_, err := pG.DB.QueryOne(
... ...
... ... @@ -14,15 +14,15 @@ var _ = Describe("获取我收藏的菜单", func() {
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&userId),
"INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",
"testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt")
"INSERT INTO \"users\".\"user\"(\"user_id\", \"company_id\", \"user_base_id\", \"user_type\", \"user_code\", \"organization_id\", \"department_id\", \"user_org\", \"user_role\", \"favorite_menus\", \"cooperation_info\", \"enable_status\", \"ext\", \"created_at\", \"updated_at\") VALUES (999, 5, 999, 1025, 'ADMIN01', 5, 5, '[{\"orgId\": 5, \"orgName\": \"string1\", \"createdAt\": \"0001-01-01T00:00:00Z\", \"deletedAt\": \"0001-01-01T00:00:00Z\", \"updatedAt\": \"0001-01-01T00:00:00Z\"}]', '[{\"ext\": {\"orgName\": \"string1\"}, \"roleId\": 5, \"roleName\": \"企业管理员\", \"createdAt\": \"0001-01-01T00:00:00Z\", \"updatedAt\": \"0001-01-01T00:00:00Z\"}]', '[\"favorite-menu\"]', '{\"cooperationCompany\": \"\", \"cooperationDeadline\": \"0001-01-01T00:00:00Z\"}', 1, '{\"phone\": \"18860183031\", \"depName\": \"string1\", \"orgName\": \"string1\"}', '2021-07-24 10:16:17.680805+08', '2021-07-24 10:16:17.680805+08');\n",
)
Expect(err).NotTo(HaveOccurred())
})
Describe("获取我收藏的菜单", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/user/{userId}/favorite-menus").
httpExpect.GET("/user/999/favorite-menus").
Expect().
Status(http.StatusOK).
JSON().
... ... @@ -34,7 +34,7 @@ var _ = Describe("获取我收藏的菜单", func() {
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM users WHERE true")
_, err := pG.DB.Exec("DELETE FROM users.\"user\" WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
... ...
... ... @@ -14,8 +14,8 @@ var _ = Describe("更新我喜欢菜单列表", func() {
BeforeEach(func() {
_, err := pG.DB.QueryOne(
pg.Scan(&userId),
"INSERT INTO users (user_id, company_id, user_base_id, user_type, user_code, organization_id, department_id, user_info, user_org, user_role, favorite_menus, cooperation_info, enable_status, ext, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING user_id",
"testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt")
"INSERT INTO \"users\".\"user\"(\"user_id\", \"company_id\", \"user_base_id\", \"user_type\", \"user_code\", \"organization_id\", \"department_id\", \"user_org\", \"user_role\", \"favorite_menus\", \"cooperation_info\", \"enable_status\", \"ext\", \"created_at\", \"updated_at\") VALUES (999, 5, 999, 1025, 'ADMIN01', 5, 5, '[{\"orgId\": 5, \"orgName\": \"string1\", \"createdAt\": \"0001-01-01T00:00:00Z\", \"deletedAt\": \"0001-01-01T00:00:00Z\", \"updatedAt\": \"0001-01-01T00:00:00Z\"}]', '[{\"ext\": {\"orgName\": \"string1\"}, \"roleId\": 5, \"roleName\": \"企业管理员\", \"createdAt\": \"0001-01-01T00:00:00Z\", \"updatedAt\": \"0001-01-01T00:00:00Z\"}]', '[]', '{\"cooperationCompany\": \"\", \"cooperationDeadline\": \"0001-01-01T00:00:00Z\"}', 1, '{\"phone\": \"18860183031\", \"depName\": \"string1\", \"orgName\": \"string1\"}', '2021-07-24 10:16:17.680805+08', '2021-07-24 10:16:17.680805+08');\n",
)
Expect(err).NotTo(HaveOccurred())
})
Describe("更新我喜欢菜单列表", func() {
... ... @@ -23,9 +23,10 @@ var _ = Describe("更新我喜欢菜单列表", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"favoriteMenus": "array",
"favoriteMenus": []string{"favorite-menu"},
//"userId":999,
}
httpExpect.PUT("/user/{userId}/favorite-menus").
httpExpect.PUT("/user/999/favorite-menus").
WithJSON(body).
Expect().
Status(http.StatusOK).
... ... @@ -38,7 +39,7 @@ var _ = Describe("更新我喜欢菜单列表", func() {
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM users WHERE true")
_, err := pG.DB.Exec(`DELETE FROM users."user" WHERE true`)
Expect(err).NotTo(HaveOccurred())
})
})
... ...