diff --git a/src/main/java/com/zatch/zatchserver/controller/UserController.java b/src/main/java/com/zatch/zatchserver/controller/UserController.java index 427ce16..9f71362 100644 --- a/src/main/java/com/zatch/zatchserver/controller/UserController.java +++ b/src/main/java/com/zatch/zatchserver/controller/UserController.java @@ -28,10 +28,10 @@ public class UserController { @ApiOperation(value = "회원가입", notes = "회원가입 API") public ResponseEntity postUser(@RequestBody PostUserReqDto postUserReqDto) { // 이메일을 통해 회원가입 or 로그인 check - Boolean isSignup = userService.loginOrSignup(postUserReqDto.getEmail()); + String isSignup = userService.loginOrSignup(postUserReqDto.getEmail()); // 회원가입 - if (isSignup){ + if (isSignup.equals("signup")){ List adjectives = Arrays.asList("귀여운", "당황한", "어리둥절", "깜찍한", "동글동글", "초롱초롱", "배고픈", "의아한", "놀라운", "어여쁜", "차분한", "한가한", "화려한", "깨끗한", "정직한", "활발한", "긍정적인", "낙천적인", "다정한", "단호한", "겸손한", "매력적인", "발랄한", "민첩한", "상냥한", "솔직한", "신중한", "용감한", "수줍은", "소중한"); List animals = Arrays.asList("강아지", "거북이", "고래", "고양이", "공작", "기린", "까치", "낙타", "너구리", "늑대", "다람쥐", "부엉이", "사슴", "사자", "새우", "수달", "순록", @@ -55,9 +55,8 @@ public ResponseEntity postUser(@RequestBody PostUserReqDto postUserReqDto) { // 로그인 String email = postUserReqDto.getEmail(); String userId = userService.getUserId(email); - System.out.println("here : "+userService.getUserId(email)); - return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.CREATED_USER, new GetUserReqDto(email)), HttpStatus.OK); + return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.LOGIN_SUCCESS, new GetUserReqDto(email)), HttpStatus.OK); } @GetMapping("/logout") diff --git a/src/main/java/com/zatch/zatchserver/repository/JdbcUserRepository.java b/src/main/java/com/zatch/zatchserver/repository/JdbcUserRepository.java index 5207cb4..8dd441a 100644 --- a/src/main/java/com/zatch/zatchserver/repository/JdbcUserRepository.java +++ b/src/main/java/com/zatch/zatchserver/repository/JdbcUserRepository.java @@ -1,10 +1,13 @@ package com.zatch.zatchserver.repository; import com.zatch.zatchserver.domain.User; +import org.springframework.http.HttpStatus; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; +import org.springframework.web.server.ResponseStatusException; import javax.sql.DataSource; +import java.sql.SQLException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -30,33 +33,46 @@ public List selectAll() { } @Override - public Boolean isSignup(String email) { - String sql = "SELECT user_id from user WHERE email = ?"; - Object[] params = {email}; - System.out.println("Is Login or Signup SQL select"); - // empty >> signup, not_empty >> login - if (jdbcTemplate.queryForList(sql, params).isEmpty()){ - return true; + public String isSignup(String email) { + try{ + String sql = "SELECT user_id from user WHERE email = ?"; + Object[] params = {email}; + System.out.println("Is Login or Signup SQL select"); + // empty >> signup, not_empty >> login + if (jdbcTemplate.queryForList(sql, params).isEmpty()){ + return "signup"; + } + return "login"; + } catch (Exception e){ + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User Email Not Found"); } - return false; } @Override public String getUserId(String email) { - String sql = "SELECT user_id from user WHERE email = ?"; - Object[] params = {email}; - System.out.println("Login SQL select"); - String user_id = String.valueOf(jdbcTemplate.queryForList(sql, params).get(0).get("user_id")); - return user_id; + try{ + String sql = "SELECT user_id from user WHERE email = ?"; + Object[] params = {email}; + System.out.println("Login SQL select"); + String user_id = String.valueOf(jdbcTemplate.queryForList(sql, params).get(0).get("user_id")); + return user_id; + } catch (Exception e){ + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User Email Not Found"); + } } @Override public Long insert(User user) { - String sql = "INSERT INTO user(name, nickname, email) VALUES(?, ?, ?)"; - Object[] params = {user.getName(), user.getNickname(), user.getEmail()}; - jdbcTemplate.update(sql, params); - System.out.println("Signup sql insert"); - return user.getId(); + try { + System.out.println("user >>> : "+ user.getName()); + String sql = "INSERT INTO user(name, nickname, email) VALUES(?, ?, ?)"; + Object[] params = {user.getName(), user.getNickname(), user.getEmail()}; + jdbcTemplate.update(sql, params); + System.out.println("Signup sql insert"); + return user.getId(); + } catch (Exception e){ + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User Email Not Found"); + } } @Override diff --git a/src/main/java/com/zatch/zatchserver/repository/UserRepository.java b/src/main/java/com/zatch/zatchserver/repository/UserRepository.java index 4d14cea..bc91e39 100644 --- a/src/main/java/com/zatch/zatchserver/repository/UserRepository.java +++ b/src/main/java/com/zatch/zatchserver/repository/UserRepository.java @@ -10,7 +10,7 @@ public interface UserRepository { List selectAll(); - Boolean isSignup(String email); + String isSignup(String email); String getUserId(String email); diff --git a/src/main/java/com/zatch/zatchserver/service/UserService.java b/src/main/java/com/zatch/zatchserver/service/UserService.java index bec620f..e5f2b25 100644 --- a/src/main/java/com/zatch/zatchserver/service/UserService.java +++ b/src/main/java/com/zatch/zatchserver/service/UserService.java @@ -5,7 +5,7 @@ import java.util.List; public interface UserService { - Boolean loginOrSignup(String email); + String loginOrSignup(String email); Long join(User user); diff --git a/src/main/java/com/zatch/zatchserver/service/UserServiceImpl.java b/src/main/java/com/zatch/zatchserver/service/UserServiceImpl.java index e998f23..a3f05ed 100644 --- a/src/main/java/com/zatch/zatchserver/service/UserServiceImpl.java +++ b/src/main/java/com/zatch/zatchserver/service/UserServiceImpl.java @@ -14,7 +14,7 @@ public class UserServiceImpl implements UserService { private final UserRepository userRepository; @Override - public Boolean loginOrSignup(String email) { + public String loginOrSignup(String email) { return userRepository.isSignup(email); }