Skip to content

Commit

Permalink
Merge branch 'master' into sb3-tracing-zipkin-jms-feign
Browse files Browse the repository at this point in the history
  • Loading branch information
gtiwari333 committed Mar 16, 2023
2 parents 9836390 + 2e441f5 commit c3b3fb9
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,4 @@ interface LiteUserRepository extends JpaRepository<LiteUser, Long> {
@Transactional(readOnly = true)
@Cacheable(value = "userByUsername", unless = "#result == null")
Optional<LiteUser> findOneByUsername(String username);

@Cacheable("userExistsById")
boolean existsByUsername(String id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ interface UserRepository extends JpaRepository<AppUser, Long> {
Optional<AppUser> findOneWithAuthoritiesByUsername(String username);

@Transactional(readOnly = true)
@Cacheable("userExistsByUserName")
@Cacheable("userExistsByUsername")
boolean existsByUsername(String username);

@Cacheable("userExistsByEmail")
boolean existsByEmail(String email);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ public void updatePassword(PasswordUpdateDTO toUpdate, AppUserDetails userDetail

public AppUser create(UserSignUpDTO toCreate) {

if (liteUserRepository.existsByUsername(toCreate.getUsername())) {
throw new DuplicateRecordException("User", "login", toCreate.getUsername());
}
//validation is already done

var user = new AppUser(toCreate.getUsername(), toCreate.getFirstName(), toCreate.getLastName(), toCreate.getEmail());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public void validate(Object target, Errors errors) {
if (userRepository.existsByUsername(toCreate.getUsername())) {
errors.rejectValue("username", "user.alreadyexists", "Username " + toCreate.getUsername() + " already exists");
}

if (userRepository.existsByEmail(toCreate.getEmail())) {
errors.rejectValue("email", "email.alreadyexists", "User with email " + toCreate.getEmail() + " already exists");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public String register(Model model) {
public String register(@Valid @ModelAttribute("user") UserSignUpDTO user, BindingResult bindingResult,
RedirectAttributes redirectAttrs) {

//do custom validation along with the BeanValidation
//do custom validation(MVC style) along with the BeanValidation
userSignupValidator.validate(user, bindingResult);

if (bindingResult.hasErrors()) {
Expand Down

0 comments on commit c3b3fb9

Please sign in to comment.