...
|
...
|
@@ -376,6 +376,7 @@ func (userService *UserService) GetUser(getUserQuery *query.GetUserQuery) (inter |
|
|
}
|
|
|
if userBase != nil {
|
|
|
user.UserInfo = userBase.UserInfo
|
|
|
user.Favorite = userBase.Favorite
|
|
|
}
|
|
|
// TODO:后期可以移除有冗余roleType
|
|
|
for i := range user.UserRole {
|
...
|
...
|
@@ -540,6 +541,7 @@ func (userService *UserService) ListUser(listUserQuery *query.ListUserQuery) (in |
|
|
user.Organization = org.CloneSample()
|
|
|
user.Company = company.CloneSample()
|
|
|
user.UserInfo = userBase.UserInfo
|
|
|
user.Favorite = userBase.Favorite
|
|
|
}
|
|
|
}
|
|
|
if err := userDto.LoadDto(users[i], company); err != nil {
|
...
|
...
|
@@ -812,6 +814,45 @@ func (userService *UserService) UpdateUsersBase(updateUsersBaseCommand *command. |
|
|
return struct{}{}, nil
|
|
|
}
|
|
|
|
|
|
// 更新我喜欢菜单列表
|
|
|
func (userService *UserService) UpdateFavorite(updateFavoriteCommand *command.UpdateFavoriteCommand) (interface{}, error) {
|
|
|
if err := updateFavoriteCommand.ValidateCommand(); err != nil {
|
|
|
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
}
|
|
|
transactionContext, err := factory.CreateTransactionContext(nil)
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
userRepository, user, err := factory.FastPgUserBase(transactionContext, updateFavoriteCommand.UserBaseId)
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
switch updateFavoriteCommand.Action {
|
|
|
case domain.Follow:
|
|
|
err = user.AddFavorite(updateFavoriteCommand.Item, updateFavoriteCommand.ItemId)
|
|
|
case domain.Unfollow:
|
|
|
err = user.RemoveFavorite(updateFavoriteCommand.Item, updateFavoriteCommand.ItemId)
|
|
|
default:
|
|
|
err = fmt.Errorf("unkown action %v", updateFavoriteCommand.Action)
|
|
|
}
|
|
|
if err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
if _, err = userRepository.Save(user); err != nil {
|
|
|
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
|
|
|
}
|
|
|
if err := transactionContext.CommitTransaction(); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
}
|
|
|
return struct{}{}, nil
|
|
|
}
|
|
|
|
|
|
func NewUserService(options map[string]interface{}) *UserService {
|
|
|
newUserService := &UserService{}
|
|
|
return newUserService
|
...
|
...
|
|