Skip to content

Commit

Permalink
🩹 fix: 修复 UsersService.java 中的 findByCode 为 findByUsername,并更新操作以匹配更改
Browse files Browse the repository at this point in the history
  • Loading branch information
vnobo committed May 21, 2024
1 parent 4186b63 commit b9315db
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@
*/
public interface UsersRepository extends R2dbcRepository<User, Long> {
/**
* get tenant by code
* find by user code
*
* @param code tenant code
* @return tenant result
* @param code user code
* @return user response
*/
Mono<User> findByCode(String code);

/**
* get tenant by username
*
* @param username username
* @return user entity
*/
Mono<User> findByUsername(String username);

/**
* check exists by username
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,15 @@ public Mono<User> add(UserRequest request) {
}

public Mono<User> modify(UserRequest request) {
return this.usersRepository.findByCode(request.getCode())
return this.usersRepository.findByUsername(request.getUsername())
.switchIfEmpty(Mono.defer(() -> Mono.error(RestServerException.withMsg(417,
"User not found!", "User by code [" + request.getCode() + "] not found!"))))
.flatMap(user -> this.usersRepository.existsByUsernameIgnoreCase(request.getUsername())
.flatMap(exists -> {
if (exists) {
return Mono.error(RestServerException.withMsg(417,
"Username already exists!",
"Username [" + request.getUsername() + "] already exists!"));
}
BeanUtils.copyProperties(request, user, true);
return this.save(user);
})).doAfterTerminate(() -> this.cache.clear());
"User not found!", "User by username [" + request.getUsername() + "] not found!"))))
.flatMap(user -> {
request.setId(user.getId());
request.setCode(user.getCode());
request.setUsername(user.getUsername());
return this.operate(request);
});
}

public Mono<User> operate(UserRequest request) {
Expand Down

0 comments on commit b9315db

Please sign in to comment.