user_controller.go 2.5 KB
package controllers

import (
	"github.com/linmadan/egglib-go/web/beego"
	"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/user/command"
	"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/user/query"
	"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/application/user/service"
)

type UserController struct {
	beego.BaseController
}

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

func (controller *UserController) UpdateUser() {
	userService := service.NewUserService(nil)
	updateUserCommand := &command.UpdateUserCommand{}
	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{}
	offset, _ := controller.GetInt("offset")
	listUserQuery.Offset = offset
	limit, _ := controller.GetInt("limit")
	listUserQuery.Limit = limit
	data, err := userService.ListUser(listUserQuery)
	controller.Response(data, err)
}

func (controller *UserController) ConvertUserStatus() {
	userService := service.NewUserService(nil)
	convertUserStatusCommand := &command.ConvertUserStatusCommand{}
	controller.Unmarshal(convertUserStatusCommand)
	data, err := userService.ConvertUserStatus(convertUserStatusCommand)
	controller.Response(data, err)
}

func (controller *UserController) SetPermission() {
	userService := service.NewUserService(nil)
	setPermissionCommand := &command.SetPermissionCommand{}
	controller.Unmarshal(setPermissionCommand)
	data, err := userService.SetPermission(setPermissionCommand)
	controller.Response(data, err)
}