作者 yangfu

菜单收藏、移除

... ... @@ -279,7 +279,7 @@ func (svr AuthService) GetUserInfo(userInfoCommand *command.UserInfoCommand) (in
}
//GetUserMenus 获取用户信息-额外的数据
func (svr AuthService) GetUserInfoExtra(userInfoCommand *command.UserInfoCommand) (interface{}, error) {
func (svr AuthService) GetFavoriteMenus(userInfoCommand *command.UserInfoCommand) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
userInfoCommand.Operator)
resultUser, err := creationUserGateway.UserGet(allied_creation_user.ReqGetUser{
... ...
package command
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"github.com/beego/beego/v2/core/validation"
)
type MenuFavoriteCommand struct {
//操作人
Operator domain.Operator `json:"-"`
// 1:添加菜单 2:移除菜单 3.全量更新
Action int `json:"action" valid:"Required"`
// 对应菜单的code
FavoriteMenus []string `json:"favoriteMenus,omitempty"`
}
func (menuFavoriteCommand *MenuFavoriteCommand) Valid(validation *validation.Validation) {
}
func (menuFavoriteCommand *MenuFavoriteCommand) ValidateCommand() error {
valid := validation.Validation{}
b, err := valid.Valid(menuFavoriteCommand)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
... ... @@ -199,3 +199,22 @@ func (srv UserService) MessagesMarkRead(cmd *command.MessageMarkReadCommand) (in
//}
return struct{}{}, nil
}
// 设置收藏菜单
func (srv UserService) UpdateMenuFavorite(menuFavoriteCommand *command.MenuFavoriteCommand) (interface{}, error) {
if err := menuFavoriteCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
menuFavoriteCommand.Operator,
)
result, err := creationUserGateway.FavoriteMenusUpadate(allied_creation_user.ReqFavoriteMenusUpdate{
UserId: menuFavoriteCommand.Operator.UserId,
FavoriteMenus: menuFavoriteCommand.FavoriteMenus,
Action: menuFavoriteCommand.Action,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return result, nil
}
... ...
... ... @@ -5,6 +5,8 @@ type (
ReqFavoriteMenusUpdate struct {
UserId int64 `json:"userId"`
FavoriteMenus []string `json:"favoriteMenus"`
// 1:添加菜单 2:移除菜单 3.全量更新
Action int `json:"action" valid:"Required"`
}
DataFavoriteMenusUpdate struct {
... ...
... ... @@ -85,7 +85,7 @@ func (controller *AuthController) GetUserInfo() {
controller.Response(data, err)
}
func (controller *AuthController) GetUserInfoExtra() {
func (controller *AuthController) GetFavoriteMenus() {
authService := service.AuthService{}
userInfoCommand := &command.UserInfoCommand{}
err := controller.Unmarshal(userInfoCommand)
... ... @@ -94,7 +94,7 @@ func (controller *AuthController) GetUserInfoExtra() {
return
}
userInfoCommand.Operator = controller.GetOperator()
data, err := authService.GetUserInfoExtra(userInfoCommand)
data, err := authService.GetFavoriteMenus(userInfoCommand)
controller.Response(data, err)
}
... ...
... ... @@ -124,3 +124,16 @@ func (controller *UserController) MessagesMarkRead() {
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)
}
... ...
... ... @@ -25,6 +25,10 @@ func (controller *UsersController) CompanyUserUpdate() {
usersService := service.NewUsersService(nil)
companyUserUpdateCommand := &command.CompanyUserUpdateCommand{}
controller.Unmarshal(companyUserUpdateCommand)
if len(companyUserUpdateCommand.UsersId) == 0 {
userId := controller.GetString(":userId")
companyUserUpdateCommand.UsersId = userId
}
companyUserUpdateCommand.Operator = controller.GetOperator()
data, err := usersService.CompanyUserUpdate(companyUserUpdateCommand)
controller.Response(data, err)
... ...
... ... @@ -11,9 +11,10 @@ func init() {
web.Router("/v1/user/company-orgs", &controllers.AuthController{}, "Post:GetCompanyOrgsByUser")
web.Router("/v1/user/user-info", &controllers.AuthController{}, "Post:GetUserInfo")
web.Router("/v1/user/favorite-menus", &controllers.AuthController{}, "Post:GetUserInfoExtra")
web.Router("/v1/user/user-menu", &controllers.AuthController{}, "Post:GetUserMenus")
web.Router("/v1/user/user-orgs", &controllers.AuthController{}, "Post:GetUserOrg")
web.Router("/v1/user/user-menu", &controllers.AuthController{}, "Post:GetUserMenus")
web.Router("/v1/user/favorite-menus", &controllers.AuthController{}, "Get:GetFavoriteMenus")
web.Router("/v1/user/favorite-menus", &mobile_client.UserController{}, "Post:UpdateMenuFavorite")
web.Router("/v1/user/change-password", &mobile_client.UserController{}, "Post:ChangePassword")
web.Router("/v1/user/change-phone", &mobile_client.UserController{}, "Post:ChangePhone")
... ...