user_controller.go 5.0 KB
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 UserController struct {
	beego.BaseController
}

func (controller *UserController) CreateUser() {
	userService := service.NewUserService(nil)
	createUserCommand := &command.CreateUserCommand{}
	Must(controller.Unmarshal(createUserCommand))
	data, err := userService.CreateUser(createUserCommand)
	controller.Response(data, err)
}

func (controller *UserController) UpdateUser() {
	userService := service.NewUserService(nil)
	updateUserCommand := &command.UpdateUserCommand{}
	Must(controller.Unmarshal(updateUserCommand))
	userId, _ := controller.GetInt64(":userId")
	updateUserCommand.UserId = userId
	data, err := userService.UpdateUser(updateUserCommand)
	controller.Response(data, err)
}

func (controller *UserController) GetUser() {
	userService := service.NewUserService(nil)
	getUserQuery := &query.GetUserQuery{}
	userId, _ := controller.GetInt64(":userId")
	getUserQuery.UserId = userId
	data, err := userService.GetUser(getUserQuery)
	controller.Response(data, err)
}

func (controller *UserController) RemoveUser() {
	userService := service.NewUserService(nil)
	removeUserCommand := &command.RemoveUserCommand{}
	controller.Unmarshal(removeUserCommand)
	userId, _ := controller.GetInt64(":userId")
	removeUserCommand.UserId = userId
	data, err := userService.RemoveUser(removeUserCommand)
	controller.Response(data, err)
}

func (controller *UserController) ListUser() {
	userService := service.NewUserService(nil)
	listUserQuery := &query.ListUserQuery{}
	data, err := userService.ListUser(listUserQuery)
	controller.Response(data, err)
}

func (controller *UserController) GetUserAccessMenus() {
	userService := service.NewUserService(nil)
	getUserAccessMenusQuery := &query.GetUserAccessMenusQuery{}
	userId, _ := controller.GetInt64(":userId")
	getUserAccessMenusQuery.UserId = userId
	menuCategory := controller.GetString("menuCategory")
	getUserAccessMenusQuery.MenuCategory = menuCategory
	getUserAccessMenusQuery.OrgId, _ = controller.GetInt64("orgId", 0)
	getUserAccessMenusQuery.ALLDisableMenu, _ = controller.GetInt("allDisableMenu", 0)
	data, err := userService.GetUserAccessMenus(getUserAccessMenusQuery)
	controller.Response(data, err)
}

func (controller *UserController) GetUserProfile() {
	userService := service.NewUserService(nil)
	getUserProfileQuery := &query.GetUserProfileQuery{}
	userId, _ := controller.GetInt64(":userId")
	getUserProfileQuery.UserId = userId
	data, err := userService.GetUserProfile(getUserProfileQuery)
	controller.Response(data, err)
}

func (controller *UserController) BatchAdd() {
	userService := service.NewUserService(nil)
	batchAddCommand := &command.BatchAddCommand{}
	Must(controller.Unmarshal(batchAddCommand))
	data, err := userService.BatchAdd(batchAddCommand)
	controller.Response(data, err)
}

func (controller *UserController) BatchEnable() {
	userService := service.NewUserService(nil)
	batchEnableCommand := &command.BatchEnableCommand{}
	controller.Unmarshal(batchEnableCommand)
	data, err := userService.BatchEnable(batchEnableCommand)
	controller.Response(data, err)
}

func (controller *UserController) BatchResetPassword() {
	userService := service.NewUserService(nil)
	batchResetPasswordCommand := &command.BatchResetPasswordCommand{}
	controller.Unmarshal(batchResetPasswordCommand)
	data, err := userService.BatchResetPassword(batchResetPasswordCommand)
	controller.Response(data, err)
}

func (controller *UserController) UpdateUsersBase() {
	userService := service.NewUserService(nil)
	updateUsersBaseCommand := &command.UpdateUsersBaseCommand{}
	controller.Unmarshal(updateUsersBaseCommand)
	userId, _ := controller.GetInt64(":userId")
	updateUsersBaseCommand.UserId = userId
	data, err := userService.UpdateUsersBase(updateUsersBaseCommand)
	controller.Response(data, err)
}

func (controller *UserController) CreateCooperator() {
	userService := service.NewUserService(nil)
	createCooperatorCommand := &command.CreateCooperatorCommand{}
	Must(controller.Unmarshal(createCooperatorCommand))
	data, err := userService.CreateCooperator(createCooperatorCommand)
	controller.Response(data, err)
}

func (controller *UserController) UpdateCooperator() {
	userService := service.NewUserService(nil)
	updateCooperatorCommand := &command.UpdateCooperatorCommand{}
	controller.Unmarshal(updateCooperatorCommand)
	userId, _ := controller.GetInt64(":userId")
	updateCooperatorCommand.UserId = userId
	data, err := userService.UpdateCooperator(updateCooperatorCommand)
	controller.Response(data, err)
}

func (controller *UserController) SearchUser() {
	userService := service.NewUserService(nil)
	listUserQuery := &query.ListUserQuery{}
	Must(controller.Unmarshal(listUserQuery))
	data, err := userService.ListUser(listUserQuery)
	controller.Response(data, err)
}