user_controller.go 4.4 KB
package mobile_client

import (
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/user/command"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/user/query"
	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/user/service"
)

type UserController struct {
	baseController
}

func (controller *UserController) SendSmsCode() {
	authService := service.UserService{}
	cmd := &command.SendSmsCodeCommand{}
	err := controller.Unmarshal(cmd)
	if err != nil {
		controller.Response(nil, err)
		return
	}
	err = authService.SendSmsCaptcha(cmd)
	controller.Response(nil, err)
}

func (controller *UserController) CheckSmsCode() {
	authService := service.UserService{}
	cmd := &command.CheckSmsCodeCommand{}
	err := controller.Unmarshal(cmd)
	if err != nil {
		controller.Response(nil, err)
		return
	}
	data, err := authService.CheckSmsCode(cmd)
	controller.Response(data, err)
}

func (controller *UserController) ChangePassword() {
	authService := service.UserService{}
	cmd := &command.ChangePasswordCommand{}
	err := controller.Unmarshal(cmd)
	if err != nil {
		controller.Response(nil, err)
		return
	}
	cmd.Operator = controller.GetOperator()
	data, err := authService.ChangePassword(cmd)
	controller.Response(data, err)
}

func (controller *UserController) ChangePhone() {
	authService := service.UserService{}
	cmd := &command.ResetPhoneCommand{}
	err := controller.Unmarshal(cmd)
	if err != nil {
		controller.Response(nil, err)
		return
	}
	cmd.Operator = controller.GetOperator()
	data, err := authService.ChangePhone(cmd)
	controller.Response(data, err)
}

func (controller *UserController) UpdateUserInfo() {
	authService := service.UserService{}
	cmd := &command.UpdateUserInfoCommand{}
	err := controller.Unmarshal(cmd)
	if err != nil {
		controller.Response(nil, err)
		return
	}
	cmd.Operator = controller.GetOperator()
	cmd.BodyKV = controller.BodyKeys()
	data, err := authService.UpdateUserBaseInfo(cmd)
	controller.Response(data, err)
}

func (controller *UserController) DestroyAccount() {
	authService := service.UserService{}
	cmd := &command.DestroyAccountCommand{}
	err := controller.Unmarshal(cmd)
	if err != nil {
		controller.Response(nil, err)
		return
	}
	cmd.Operator = controller.GetOperator()
	data, err := authService.DestroyAccount(cmd)
	controller.Response(data, err)
}

func (controller *UserController) DepartmentUsers() {
	orgService := service.UserService{}
	departmentsUsersQuery := &query.DepartmentsUsersQuery{}
	err := controller.Unmarshal(departmentsUsersQuery)
	if err != nil {
		controller.Response(nil, err)
		return
	}
	departmentsUsersQuery.Operator = controller.GetOperator()
	data, err := orgService.DepartmentsUsers(departmentsUsersQuery)
	controller.Response(data, err)
}

func (controller *UserController) Messages() {
	svr := service.UserService{}
	messagesListQuery := &query.MessagesListQuery{}
	err := controller.Unmarshal(messagesListQuery)
	if err != nil {
		controller.Response(nil, err)
		return
	}
	messagesListQuery.Operator = controller.GetOperator()
	total, data, err := svr.MessagesList(messagesListQuery)
	controller.ReturnPageListData(total, data, err, messagesListQuery.PageNumber)
}

func (controller *UserController) MessagesMarkRead() {
	svr := service.UserService{}
	cmd := &command.MessageMarkReadCommand{}
	err := controller.Unmarshal(cmd)
	if err != nil {
		controller.Response(nil, err)
		return
	}
	cmd.Operator = controller.GetOperator()
	data, err := svr.MessagesMarkRead(cmd)
	controller.Response(data, err)
}

func (controller *UserController) UpdateMenuFavorite() {
	svr := service.UserService{}
	cmd := &command.MenuFavoriteCommand{}
	err := controller.Unmarshal(cmd)
	if err != nil {
		controller.Response(nil, err)
		return
	}
	cmd.Operator = controller.GetOperator()
	data, err := svr.UpdateMenuFavorite(cmd)
	controller.Response(data, err)
}

func (controller *UserController) CooperationOrg() {
	svr := service.UserService{}
	operator := controller.GetOperator()
	data, err := svr.CooperationOrg(operator)
	controller.Response(data, err)
}

func (controller *UserController) UpdateOrgFavorite() {
	svr := service.UserService{}
	cmd := &command.UpdateFavoriteCommand{}
	err := controller.Unmarshal(cmd)
	if err != nil {
		controller.Response(nil, err)
		return
	}
	cmd.Operator = controller.GetOperator()
	data, err := svr.UpdateFavorite(cmd)
	controller.Response(data, err)
}