Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(controller): exception that occurs when the register_info does not exist #1082

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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