feat: 회원정보 변경시 이메일 중복 검사

This commit is contained in:
박정민 2024-08-09 14:19:10 +09:00
parent 12c34005cd
commit 423332bacb
3 changed files with 11 additions and 5 deletions

View File

@ -37,7 +37,7 @@ public class UserController {
if (userService.isUserIdExist(requestJoinDto.getUserId()))
return new ResponseEntity<>("아이디가 중복 됐습니다.", HttpStatus.CONFLICT);
if(userService.isEmailExist(requestJoinDto.getEmail()))
if (userService.isEmailExist(requestJoinDto.getEmail()))
return new ResponseEntity<>("이메일이 중복 됐습니다.", HttpStatus.CONFLICT);
userService.join(requestJoinDto);
@ -65,7 +65,7 @@ public class UserController {
userService.changePassword(passwordDto, userId);
return ResponseEntity.ok("Password changed successfully");
} catch (Exception e) {
return ResponseEntity.badRequest().body(e.getMessage());
return ResponseEntity.status(HttpStatus.NOT_ACCEPTABLE).body(e.getMessage());
}
}

View File

@ -9,7 +9,7 @@ import org.springframework.data.repository.query.Param;
import java.util.Optional;
public interface UserRepository extends JpaRepository<User,Long> {
public interface UserRepository extends JpaRepository<User, Long> {
@Modifying
@Transactional
@Query("UPDATE User u SET u.refreshToken = :refreshToken WHERE u.id = :id")
@ -26,7 +26,7 @@ public interface UserRepository extends JpaRepository<User,Long> {
@Transactional
@Modifying
@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);

View File

@ -74,6 +74,12 @@ public class UserServiceImpl implements UserService {
User user = userRepository.findById(id).orElseThrow(IllegalArgumentException::new);
if (isEmailExist(infoDto.getEmail())) {
throw new IllegalArgumentException("이미 사용 중인 이메일입니다.");
}
if (infoDto.getName() != null)
user.setName(infoDto.getName());
@ -159,7 +165,7 @@ public class UserServiceImpl implements UserService {
}
@Override
public boolean isTeacher(long userId){
public boolean isTeacher(long userId) {
return userRepository.findById(userId).orElseThrow(IllegalArgumentException::new).getRole() == UserRole.ADMIN;
}
}