正在显示
8 个修改的文件
包含
36 行增加
和
15 行删除
| @@ -5,7 +5,10 @@ import ( | @@ -5,7 +5,10 @@ import ( | ||
| 5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/utils" | 5 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/utils" |
| 6 | ) | 6 | ) |
| 7 | 7 | ||
| 8 | -func RetCustomizeMenu(menus []*domain.Menu, customizeMenus []*domain.CustomizeMenu) interface{} { | 8 | +type CustomizeMenuDto struct { |
| 9 | +} | ||
| 10 | + | ||
| 11 | +func (dto *CustomizeMenuDto) LoadDto(menus []*domain.Menu, customizeMenus []*domain.CustomizeMenu) (interface{}, error) { | ||
| 9 | var ret []interface{} | 12 | var ret []interface{} |
| 10 | menusMap := make(map[int64]*domain.Menu) | 13 | menusMap := make(map[int64]*domain.Menu) |
| 11 | for i := range menus { | 14 | for i := range menus { |
| @@ -27,5 +30,5 @@ func RetCustomizeMenu(menus []*domain.Menu, customizeMenus []*domain.CustomizeMe | @@ -27,5 +30,5 @@ func RetCustomizeMenu(menus []*domain.Menu, customizeMenus []*domain.CustomizeMe | ||
| 27 | } | 30 | } |
| 28 | ret = append(ret, fieldMenu) | 31 | ret = append(ret, fieldMenu) |
| 29 | } | 32 | } |
| 30 | - return ret | 33 | + return ret, nil |
| 31 | } | 34 | } |
| @@ -170,7 +170,8 @@ func (companyService *CompanyService) ListCompanyCustomizeMenus(listCompanyCusto | @@ -170,7 +170,8 @@ func (companyService *CompanyService) ListCompanyCustomizeMenus(listCompanyCusto | ||
| 170 | if err != nil { | 170 | if err != nil { |
| 171 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 171 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 172 | } | 172 | } |
| 173 | - ret := dto.RetCustomizeMenu(menus, customizeMenus) | 173 | + customizeMenuDto := dto.CustomizeMenuDto{} |
| 174 | + ret, _ := customizeMenuDto.LoadDto(menus, customizeMenus) | ||
| 174 | 175 | ||
| 175 | if err := transactionContext.CommitTransaction(); err != nil { | 176 | if err := transactionContext.CommitTransaction(); err != nil { |
| 176 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 177 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| @@ -12,7 +12,7 @@ type UpdateFavoriteMenusCommand struct { | @@ -12,7 +12,7 @@ type UpdateFavoriteMenusCommand struct { | ||
| 12 | // 菜单编码列表 | 12 | // 菜单编码列表 |
| 13 | FavoriteMenus []string `cname:"菜单编码列表" json:"favoriteMenus,omitempty"` | 13 | FavoriteMenus []string `cname:"菜单编码列表" json:"favoriteMenus,omitempty"` |
| 14 | // 用户Id 用户唯一标识 | 14 | // 用户Id 用户唯一标识 |
| 15 | - UserId int64 `cname:"用户Id 用户唯一标识" json:"userId,string" valid:"Required"` | 15 | + UserId int64 `cname:"用户Id 用户唯一标识" json:"userId" valid:"Required"` |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | func (updateFavoriteMenusCommand *UpdateFavoriteMenusCommand) Valid(validation *validation.Validation) { | 18 | func (updateFavoriteMenusCommand *UpdateFavoriteMenusCommand) Valid(validation *validation.Validation) { |
| @@ -264,10 +264,16 @@ func (userService *UserService) GetFavoriteMenus(getFavoriteMenusQuery *query.Ge | @@ -264,10 +264,16 @@ func (userService *UserService) GetFavoriteMenus(getFavoriteMenusQuery *query.Ge | ||
| 264 | defer func() { | 264 | defer func() { |
| 265 | transactionContext.RollbackTransaction() | 265 | transactionContext.RollbackTransaction() |
| 266 | }() | 266 | }() |
| 267 | + _, user, err := factory.FastPgUser(transactionContext, getFavoriteMenusQuery.UserId) | ||
| 268 | + if err != nil { | ||
| 269 | + return nil, err | ||
| 270 | + } | ||
| 267 | if err := transactionContext.CommitTransaction(); err != nil { | 271 | if err := transactionContext.CommitTransaction(); err != nil { |
| 268 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 272 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 269 | } | 273 | } |
| 270 | - return nil, nil | 274 | + return map[string]interface{}{ |
| 275 | + "favoriteMenus": user.FavoriteMenus, | ||
| 276 | + }, nil | ||
| 271 | } | 277 | } |
| 272 | 278 | ||
| 273 | // 返回 | 279 | // 返回 |
| @@ -481,10 +487,18 @@ func (userService *UserService) UpdateFavoriteMenus(updateFavoriteMenusCommand * | @@ -481,10 +487,18 @@ func (userService *UserService) UpdateFavoriteMenus(updateFavoriteMenusCommand * | ||
| 481 | defer func() { | 487 | defer func() { |
| 482 | transactionContext.RollbackTransaction() | 488 | transactionContext.RollbackTransaction() |
| 483 | }() | 489 | }() |
| 490 | + userRepository, user, err := factory.FastPgUser(transactionContext, updateFavoriteMenusCommand.UserId) | ||
| 491 | + if err != nil { | ||
| 492 | + return nil, err | ||
| 493 | + } | ||
| 494 | + user.FavoriteMenus = updateFavoriteMenusCommand.FavoriteMenus | ||
| 495 | + if _, err = userRepository.Save(user); err != nil { | ||
| 496 | + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) | ||
| 497 | + } | ||
| 484 | if err := transactionContext.CommitTransaction(); err != nil { | 498 | if err := transactionContext.CommitTransaction(); err != nil { |
| 485 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | 499 | return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) |
| 486 | } | 500 | } |
| 487 | - return nil, nil | 501 | + return struct{}{}, nil |
| 488 | } | 502 | } |
| 489 | 503 | ||
| 490 | // 更新 | 504 | // 更新 |
| @@ -7,6 +7,7 @@ import ( | @@ -7,6 +7,7 @@ import ( | ||
| 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/im" | 7 | "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/im" |
| 8 | ) | 8 | ) |
| 9 | 9 | ||
| 10 | +// PgImService 网易云信IM服务 | ||
| 10 | type PgImService struct { | 11 | type PgImService struct { |
| 11 | transactionContext *pgTransaction.TransactionContext | 12 | transactionContext *pgTransaction.TransactionContext |
| 12 | } | 13 | } |
| @@ -10,6 +10,7 @@ import ( | @@ -10,6 +10,7 @@ import ( | ||
| 10 | ) | 10 | ) |
| 11 | 11 | ||
| 12 | var _ = Describe("移除我收藏的菜单", func() { | 12 | var _ = Describe("移除我收藏的菜单", func() { |
| 13 | + return | ||
| 13 | var userId int64 | 14 | var userId int64 |
| 14 | BeforeEach(func() { | 15 | BeforeEach(func() { |
| 15 | _, err := pG.DB.QueryOne( | 16 | _, err := pG.DB.QueryOne( |
| @@ -14,15 +14,15 @@ var _ = Describe("获取我收藏的菜单", func() { | @@ -14,15 +14,15 @@ var _ = Describe("获取我收藏的菜单", func() { | ||
| 14 | BeforeEach(func() { | 14 | BeforeEach(func() { |
| 15 | _, err := pG.DB.QueryOne( | 15 | _, err := pG.DB.QueryOne( |
| 16 | pg.Scan(&userId), | 16 | pg.Scan(&userId), |
| 17 | - "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", | ||
| 18 | - "testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt") | 17 | + "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", |
| 18 | + ) | ||
| 19 | Expect(err).NotTo(HaveOccurred()) | 19 | Expect(err).NotTo(HaveOccurred()) |
| 20 | }) | 20 | }) |
| 21 | Describe("获取我收藏的菜单", func() { | 21 | Describe("获取我收藏的菜单", func() { |
| 22 | Context("", func() { | 22 | Context("", func() { |
| 23 | It("", func() { | 23 | It("", func() { |
| 24 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 24 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
| 25 | - httpExpect.GET("/user/{userId}/favorite-menus"). | 25 | + httpExpect.GET("/user/999/favorite-menus"). |
| 26 | Expect(). | 26 | Expect(). |
| 27 | Status(http.StatusOK). | 27 | Status(http.StatusOK). |
| 28 | JSON(). | 28 | JSON(). |
| @@ -34,7 +34,7 @@ var _ = Describe("获取我收藏的菜单", func() { | @@ -34,7 +34,7 @@ var _ = Describe("获取我收藏的菜单", func() { | ||
| 34 | }) | 34 | }) |
| 35 | }) | 35 | }) |
| 36 | AfterEach(func() { | 36 | AfterEach(func() { |
| 37 | - _, err := pG.DB.Exec("DELETE FROM users WHERE true") | 37 | + _, err := pG.DB.Exec("DELETE FROM users.\"user\" WHERE true") |
| 38 | Expect(err).NotTo(HaveOccurred()) | 38 | Expect(err).NotTo(HaveOccurred()) |
| 39 | }) | 39 | }) |
| 40 | }) | 40 | }) |
| @@ -14,8 +14,8 @@ var _ = Describe("更新我喜欢菜单列表", func() { | @@ -14,8 +14,8 @@ var _ = Describe("更新我喜欢菜单列表", func() { | ||
| 14 | BeforeEach(func() { | 14 | BeforeEach(func() { |
| 15 | _, err := pG.DB.QueryOne( | 15 | _, err := pG.DB.QueryOne( |
| 16 | pg.Scan(&userId), | 16 | pg.Scan(&userId), |
| 17 | - "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", | ||
| 18 | - "testUserId", "testCompanyId", "testUserBaseId", "testUserType", "testUserCode", "testOrganizationId", "testDepartmentId", "testUserInfo", "testUserOrg", "testUserRole", "testFavoriteMenus", "testCooperationInfo", "testEnableStatus", "testExt", "testCreatedAt", "testUpdatedAt") | 17 | + "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", |
| 18 | + ) | ||
| 19 | Expect(err).NotTo(HaveOccurred()) | 19 | Expect(err).NotTo(HaveOccurred()) |
| 20 | }) | 20 | }) |
| 21 | Describe("更新我喜欢菜单列表", func() { | 21 | Describe("更新我喜欢菜单列表", func() { |
| @@ -23,9 +23,10 @@ var _ = Describe("更新我喜欢菜单列表", func() { | @@ -23,9 +23,10 @@ var _ = Describe("更新我喜欢菜单列表", func() { | ||
| 23 | It("", func() { | 23 | It("", func() { |
| 24 | httpExpect := httpexpect.New(GinkgoT(), server.URL) | 24 | httpExpect := httpexpect.New(GinkgoT(), server.URL) |
| 25 | body := map[string]interface{}{ | 25 | body := map[string]interface{}{ |
| 26 | - "favoriteMenus": "array", | 26 | + "favoriteMenus": []string{"favorite-menu"}, |
| 27 | + //"userId":999, | ||
| 27 | } | 28 | } |
| 28 | - httpExpect.PUT("/user/{userId}/favorite-menus"). | 29 | + httpExpect.PUT("/user/999/favorite-menus"). |
| 29 | WithJSON(body). | 30 | WithJSON(body). |
| 30 | Expect(). | 31 | Expect(). |
| 31 | Status(http.StatusOK). | 32 | Status(http.StatusOK). |
| @@ -38,7 +39,7 @@ var _ = Describe("更新我喜欢菜单列表", func() { | @@ -38,7 +39,7 @@ var _ = Describe("更新我喜欢菜单列表", func() { | ||
| 38 | }) | 39 | }) |
| 39 | }) | 40 | }) |
| 40 | AfterEach(func() { | 41 | AfterEach(func() { |
| 41 | - _, err := pG.DB.Exec("DELETE FROM users WHERE true") | 42 | + _, err := pG.DB.Exec(`DELETE FROM users."user" WHERE true`) |
| 42 | Expect(err).NotTo(HaveOccurred()) | 43 | Expect(err).NotTo(HaveOccurred()) |
| 43 | }) | 44 | }) |
| 44 | }) | 45 | }) |
-
请 注册 或 登录 后发表评论