feat: 회원정보 변경시 이메일 중복 검사
This commit is contained in:
parent
12c34005cd
commit
423332bacb
@ -37,7 +37,7 @@ public class UserController {
|
|||||||
if (userService.isUserIdExist(requestJoinDto.getUserId()))
|
if (userService.isUserIdExist(requestJoinDto.getUserId()))
|
||||||
return new ResponseEntity<>("아이디가 중복 됐습니다.", HttpStatus.CONFLICT);
|
return new ResponseEntity<>("아이디가 중복 됐습니다.", HttpStatus.CONFLICT);
|
||||||
|
|
||||||
if(userService.isEmailExist(requestJoinDto.getEmail()))
|
if (userService.isEmailExist(requestJoinDto.getEmail()))
|
||||||
return new ResponseEntity<>("이메일이 중복 됐습니다.", HttpStatus.CONFLICT);
|
return new ResponseEntity<>("이메일이 중복 됐습니다.", HttpStatus.CONFLICT);
|
||||||
|
|
||||||
userService.join(requestJoinDto);
|
userService.join(requestJoinDto);
|
||||||
@ -65,7 +65,7 @@ public class UserController {
|
|||||||
userService.changePassword(passwordDto, userId);
|
userService.changePassword(passwordDto, userId);
|
||||||
return ResponseEntity.ok("Password changed successfully");
|
return ResponseEntity.ok("Password changed successfully");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return ResponseEntity.badRequest().body(e.getMessage());
|
return ResponseEntity.status(HttpStatus.NOT_ACCEPTABLE).body(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import org.springframework.data.repository.query.Param;
|
|||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface UserRepository extends JpaRepository<User,Long> {
|
public interface UserRepository extends JpaRepository<User, Long> {
|
||||||
@Modifying
|
@Modifying
|
||||||
@Transactional
|
@Transactional
|
||||||
@Query("UPDATE User u SET u.refreshToken = :refreshToken WHERE u.id = :id")
|
@Query("UPDATE User u SET u.refreshToken = :refreshToken WHERE u.id = :id")
|
||||||
@ -26,7 +26,7 @@ public interface UserRepository extends JpaRepository<User,Long> {
|
|||||||
@Transactional
|
@Transactional
|
||||||
@Modifying
|
@Modifying
|
||||||
@Query("UPDATE User u set u.password = :password where u.id= :id")
|
@Query("UPDATE User u set u.password = :password where u.id= :id")
|
||||||
void updatePassword(@Param("id") Long id , @Param("password") String password);
|
void updatePassword(@Param("id") Long id, @Param("password") String password);
|
||||||
|
|
||||||
|
|
||||||
Optional<User> findByUserId(String userId);
|
Optional<User> findByUserId(String userId);
|
||||||
|
@ -74,6 +74,12 @@ public class UserServiceImpl implements UserService {
|
|||||||
|
|
||||||
User user = userRepository.findById(id).orElseThrow(IllegalArgumentException::new);
|
User user = userRepository.findById(id).orElseThrow(IllegalArgumentException::new);
|
||||||
|
|
||||||
|
|
||||||
|
if (isEmailExist(infoDto.getEmail())) {
|
||||||
|
throw new IllegalArgumentException("이미 사용 중인 이메일입니다.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (infoDto.getName() != null)
|
if (infoDto.getName() != null)
|
||||||
user.setName(infoDto.getName());
|
user.setName(infoDto.getName());
|
||||||
|
|
||||||
@ -159,7 +165,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isTeacher(long userId){
|
public boolean isTeacher(long userId) {
|
||||||
return userRepository.findById(userId).orElseThrow(IllegalArgumentException::new).getRole() == UserRole.ADMIN;
|
return userRepository.findById(userId).orElseThrow(IllegalArgumentException::new).getRole() == UserRole.ADMIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user