作者 yangfu

add user

package controllers
import (
"github.com/linmadan/egglib-go/web/beego"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/user/service"
)
type UserFavoriteMenusController struct {
beego.BaseController
}
func (controller *UserFavoriteMenusController) UpdateFavoriteMenus() {
userService := service.NewUserService(nil)
updateFavoriteMenusCommand := &command.UpdateFavoriteMenusCommand{}
controller.Unmarshal(updateFavoriteMenusCommand)
userId, _ := controller.GetInt64(":userId")
updateFavoriteMenusCommand.UserId = userId
data, err := userService.UpdateFavoriteMenus(updateFavoriteMenusCommand)
controller.Response(data, err)
}
func (controller *UserFavoriteMenusController) GetFavoriteMenus() {
userService := service.NewUserService(nil)
getFavoriteMenusQuery := &query.GetFavoriteMenusQuery{}
userId, _ := controller.GetInt64(":userId")
getFavoriteMenusQuery.UserId = userId
data, err := userService.GetFavoriteMenus(getFavoriteMenusQuery)
controller.Response(data, err)
}
func (controller *UserFavoriteMenusController) DeleteFavoriteMenus() {
userService := service.NewUserService(nil)
deleteFavoriteMenusCommand := &command.DeleteFavoriteMenusCommand{}
controller.Unmarshal(deleteFavoriteMenusCommand)
userId, _ := controller.GetInt64(":userId")
deleteFavoriteMenusCommand.UserId = userId
code, _ := controller.GetInt(":code")
deleteFavoriteMenusCommand.Code = code
data, err := userService.DeleteFavoriteMenus(deleteFavoriteMenusCommand)
controller.Response(data, err)
}
... ...
package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/port/beego/controllers"
)
func init() {
web.Router("/user/:userId/favorite-menus", &controllers.UserFavoriteMenusController{}, "Put:UpdateFavoriteMenus")
web.Router("/user/:userId/favorite-menus", &controllers.UserFavoriteMenusController{}, "Get:GetFavoriteMenus")
web.Router("/user/:userId/favorite-menus/:code", &controllers.UserFavoriteMenusController{}, "Delete:DeleteFavoriteMenus")
}
... ...
package user-favorite-menus
import (
"github.com/gavv/httpexpect"
"github.com/go-pg/pg/v10"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"net/http"
)
var _ = Describe("移除我收藏的菜单", func() {
var userId int64
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")
Expect(err).NotTo(HaveOccurred())
})
Describe("移除我收藏的菜单", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.DELETE("/user/{userId}/favorite-menus/{code}").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM users WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
\ No newline at end of file
... ...
package user-favorite-menus
import (
"github.com/gavv/httpexpect"
"github.com/go-pg/pg/v10"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"net/http"
)
var _ = Describe("获取我收藏的菜单", func() {
var userId int64
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")
Expect(err).NotTo(HaveOccurred())
})
Describe("获取我收藏的菜单", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
httpExpect.GET("/user/{userId}/favorite-menus").
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM users WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
\ No newline at end of file
... ...
package user-favorite-menus
import (
"github.com/gavv/httpexpect"
"github.com/go-pg/pg/v10"
pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"net/http"
)
var _ = Describe("更新我喜欢菜单列表", func() {
var userId int64
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")
Expect(err).NotTo(HaveOccurred())
})
Describe("更新我喜欢菜单列表", func() {
Context("", func() {
It("", func() {
httpExpect := httpexpect.New(GinkgoT(), server.URL)
body := map[string]interface{}{
"favoriteMenus": "array",
}
httpExpect.PUT("/user/{userId}/favorite-menus").
WithJSON(body).
Expect().
Status(http.StatusOK).
JSON().
Object().
ContainsKey("code").ValueEqual("code", 0).
ContainsKey("msg").ValueEqual("msg", "ok").
ContainsKey("data").Value("data").Object()
})
})
})
AfterEach(func() {
_, err := pG.DB.Exec("DELETE FROM users WHERE true")
Expect(err).NotTo(HaveOccurred())
})
})
\ No newline at end of file
... ...
package user-favorite-menus
import (
"github.com/beego/beego/v2/server/web"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"net/http"
"net/http/httptest"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/pg"
_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/port/beego"
"testing"
)
func TestUserFavoriteMenus(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Beego Port UserFavoriteMenus Correlations Test Case Suite")
}
var handler http.Handler
var server *httptest.Server
var _ = BeforeSuite(func() {
handler = web.BeeApp.Handlers
server = httptest.NewServer(handler)
})
var _ = AfterSuite(func() {
server.Close()
})
\ No newline at end of file
... ...