Skip to content

Commit

Permalink
fix(controller): exception that occurs when the register_info does no…
Browse files Browse the repository at this point in the history
…t exist (#1082)

fix bug: exception that occurs when the register_info does not exist
  • Loading branch information
dreamlandliu authored Aug 31, 2022
1 parent 1e3917c commit c6d8c07
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ public UserVO currentUser() {
throw new StarWhaleApiException(new SWProcessException(ErrorType.DB)
.tip(String.format("Unable to find user by name %s", user.getName())), HttpStatus.INTERNAL_SERVER_ERROR);
}
if(userMapper.existRegister() != null) {
userEntity.setUserEmail(userMapper.getUserEmail(userEntity.getId()));
}
return userConvertor.convert(userEntity);
}

Expand All @@ -153,6 +156,9 @@ public User currentUserDetail() {

public UserVO findUserById(Long id) {
UserEntity entity = userMapper.findUser(id);
if(userMapper.existRegister() != null) {
entity.setUserEmail(userMapper.getUserEmail(entity.getId()));
}
return userConvertor.convert(entity);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public interface UserMapper {

UserEntity findUserByName(@Param("userName") String userName);

String existRegister();

String getUserEmail(@Param("id")Long id);

List<UserEntity> listUsers(@Param("userNamePrefix") String userNamePrefix);

int changePassword(@Param("user")UserEntity user);
Expand Down
18 changes: 10 additions & 8 deletions server/controller/src/main/resources/mapper/UserMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
u.user_pwd_salt,
u.user_enabled,
u.created_time as user_created_time,
u.modified_time as user_modified_time,
(select if((select 1 from information_schema.tables where table_schema='starwhale' and table_name ='register_info'),
(select email from register_info where user_id = u.id),
null)) as user_email
u.modified_time as user_modified_time
from user_info as u
where u.id = #{id}
</select>
Expand All @@ -35,14 +32,19 @@
u.user_pwd_salt,
u.user_enabled,
u.created_time as user_created_time,
u.modified_time as user_modified_time,
(select if((select 1 from information_schema.tables where table_schema='starwhale' and table_name ='register_info'),
(select email from register_info where user_id = u.id),
null)) as user_email
u.modified_time as user_modified_time
from user_info as u
where u.user_name = #{userName}
</select>

<select id="existRegister" resultType="String">
show tables like 'register_info'
</select>

<select id="getUserEmail" resultType="String">
select email from register_info where user_id = #{id}
</select>

<select id="listUsers" resultMap="userResultMap">
select u.id as user_id,
u.user_name,
Expand Down

0 comments on commit c6d8c07

Please sign in to comment.