作者 yangfu

add user

  1 +package controllers
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/web/beego"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/command"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/query"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/service"
  8 +)
  9 +
  10 +type UserFavoriteMenusController struct {
  11 + beego.BaseController
  12 +}
  13 +
  14 +func (controller *UserFavoriteMenusController) UpdateFavoriteMenus() {
  15 + userService := service.NewUserService(nil)
  16 + updateFavoriteMenusCommand := &command.UpdateFavoriteMenusCommand{}
  17 + controller.Unmarshal(updateFavoriteMenusCommand)
  18 + userId, _ := controller.GetInt64(":userId")
  19 + updateFavoriteMenusCommand.UserId = userId
  20 + data, err := userService.UpdateFavoriteMenus(updateFavoriteMenusCommand)
  21 + controller.Response(data, err)
  22 +}
  23 +
  24 +func (controller *UserFavoriteMenusController) GetFavoriteMenus() {
  25 + userService := service.NewUserService(nil)
  26 + getFavoriteMenusQuery := &query.GetFavoriteMenusQuery{}
  27 + userId, _ := controller.GetInt64(":userId")
  28 + getFavoriteMenusQuery.UserId = userId
  29 + data, err := userService.GetFavoriteMenus(getFavoriteMenusQuery)
  30 + controller.Response(data, err)
  31 +}
  32 +
  33 +func (controller *UserFavoriteMenusController) DeleteFavoriteMenus() {
  34 + userService := service.NewUserService(nil)
  35 + deleteFavoriteMenusCommand := &command.DeleteFavoriteMenusCommand{}
  36 + controller.Unmarshal(deleteFavoriteMenusCommand)
  37 + userId, _ := controller.GetInt64(":userId")
  38 + deleteFavoriteMenusCommand.UserId = userId
  39 + code, _ := controller.GetInt(":code")
  40 + deleteFavoriteMenusCommand.Code = code
  41 + data, err := userService.DeleteFavoriteMenus(deleteFavoriteMenusCommand)
  42 + controller.Response(data, err)
  43 +}
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/beego/beego/v2/server/web"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/port/beego/controllers"
  6 +)
  7 +
  8 +func init() {
  9 + web.Router("/user/:userId/favorite-menus", &controllers.UserFavoriteMenusController{}, "Put:UpdateFavoriteMenus")
  10 + web.Router("/user/:userId/favorite-menus", &controllers.UserFavoriteMenusController{}, "Get:GetFavoriteMenus")
  11 + web.Router("/user/:userId/favorite-menus/:code", &controllers.UserFavoriteMenusController{}, "Delete:DeleteFavoriteMenus")
  12 +}
  1 +
  2 +package user-favorite-menus
  3 +import (
  4 +"github.com/gavv/httpexpect"
  5 +"github.com/go-pg/pg/v10"
  6 +pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
  7 +. "github.com/onsi/ginkgo"
  8 +. "github.com/onsi/gomega"
  9 +"net/http"
  10 +)
  11 +
  12 +var _ = Describe("移除我收藏的菜单", func() {
  13 + var userId int64
  14 + BeforeEach(func() {
  15 + _, err := pG.DB.QueryOne(
  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")
  19 + Expect(err).NotTo(HaveOccurred())
  20 + })
  21 + Describe("移除我收藏的菜单", func() {
  22 + Context("", func() {
  23 + It("", func() {
  24 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  25 + httpExpect.DELETE("/user/{userId}/favorite-menus/{code}").
  26 + Expect().
  27 + Status(http.StatusOK).
  28 + JSON().
  29 + Object().
  30 + ContainsKey("code").ValueEqual("code", 0).
  31 + ContainsKey("msg").ValueEqual("msg", "ok").
  32 + ContainsKey("data").Value("data").Object()
  33 + })
  34 + })
  35 + })
  36 + AfterEach(func() {
  37 + _, err := pG.DB.Exec("DELETE FROM users WHERE true")
  38 + Expect(err).NotTo(HaveOccurred())
  39 + })
  40 +})
  1 +
  2 +package user-favorite-menus
  3 +import (
  4 +"github.com/gavv/httpexpect"
  5 +"github.com/go-pg/pg/v10"
  6 +pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
  7 +. "github.com/onsi/ginkgo"
  8 +. "github.com/onsi/gomega"
  9 +"net/http"
  10 +)
  11 +
  12 +var _ = Describe("获取我收藏的菜单", func() {
  13 + var userId int64
  14 + BeforeEach(func() {
  15 + _, err := pG.DB.QueryOne(
  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")
  19 + Expect(err).NotTo(HaveOccurred())
  20 + })
  21 + Describe("获取我收藏的菜单", func() {
  22 + Context("", func() {
  23 + It("", func() {
  24 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  25 + httpExpect.GET("/user/{userId}/favorite-menus").
  26 + Expect().
  27 + Status(http.StatusOK).
  28 + JSON().
  29 + Object().
  30 + ContainsKey("code").ValueEqual("code", 0).
  31 + ContainsKey("msg").ValueEqual("msg", "ok").
  32 + ContainsKey("data").Value("data").Object()
  33 + })
  34 + })
  35 + })
  36 + AfterEach(func() {
  37 + _, err := pG.DB.Exec("DELETE FROM users WHERE true")
  38 + Expect(err).NotTo(HaveOccurred())
  39 + })
  40 +})
  1 +
  2 +package user-favorite-menus
  3 +import (
  4 +"github.com/gavv/httpexpect"
  5 +"github.com/go-pg/pg/v10"
  6 +pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
  7 +. "github.com/onsi/ginkgo"
  8 +. "github.com/onsi/gomega"
  9 +"net/http"
  10 +)
  11 +
  12 +var _ = Describe("更新我喜欢菜单列表", func() {
  13 + var userId int64
  14 + BeforeEach(func() {
  15 + _, err := pG.DB.QueryOne(
  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")
  19 + Expect(err).NotTo(HaveOccurred())
  20 + })
  21 + Describe("更新我喜欢菜单列表", func() {
  22 + Context("", func() {
  23 + It("", func() {
  24 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  25 + body := map[string]interface{}{
  26 + "favoriteMenus": "array",
  27 + }
  28 + httpExpect.PUT("/user/{userId}/favorite-menus").
  29 + WithJSON(body).
  30 + Expect().
  31 + Status(http.StatusOK).
  32 + JSON().
  33 + Object().
  34 + ContainsKey("code").ValueEqual("code", 0).
  35 + ContainsKey("msg").ValueEqual("msg", "ok").
  36 + ContainsKey("data").Value("data").Object()
  37 + })
  38 + })
  39 + })
  40 + AfterEach(func() {
  41 + _, err := pG.DB.Exec("DELETE FROM users WHERE true")
  42 + Expect(err).NotTo(HaveOccurred())
  43 + })
  44 +})
  1 +
  2 +package user-favorite-menus
  3 +import (
  4 +"github.com/beego/beego/v2/server/web"
  5 +. "github.com/onsi/ginkgo"
  6 +. "github.com/onsi/gomega"
  7 +"net/http"
  8 +"net/http/httptest"
  9 +_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application"
  10 +_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
  11 +_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/port/beego"
  12 +"testing"
  13 +)
  14 +
  15 +func TestUserFavoriteMenus(t *testing.T) {
  16 + RegisterFailHandler(Fail)
  17 + RunSpecs(t, "Beego Port UserFavoriteMenus Correlations Test Case Suite")
  18 +}
  19 +
  20 +var handler http.Handler
  21 +var server *httptest.Server
  22 +
  23 +var _ = BeforeSuite(func() {
  24 + handler = web.BeeApp.Handlers
  25 + server = httptest.NewServer(handler)
  26 +})
  27 +
  28 +var _ = AfterSuite(func() {
  29 + server.Close()
  30 +})