From 6538235f3fedb9df6655c8534d1704746e7b9f84 Mon Sep 17 00:00:00 2001 From: sungone <20200999@sungshin.ac.kr> Date: Mon, 17 Apr 2023 22:03:02 +0900 Subject: [PATCH] =?UTF-8?q?#3=20fix=20:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=9D=91=EB=8B=B5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zatchserver/controller/UserController.java | 13 ++++++++++--- .../zatchserver/repository/JdbcUserRepository.java | 14 ++++++++++++++ .../zatchserver/repository/UserRepository.java | 3 +++ .../com/zatch/zatchserver/service/UserService.java | 2 ++ .../zatch/zatchserver/service/UserServiceImpl.java | 5 +++++ 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/zatch/zatchserver/controller/UserController.java b/src/main/java/com/zatch/zatchserver/controller/UserController.java index fec695e..3206ad0 100644 --- a/src/main/java/com/zatch/zatchserver/controller/UserController.java +++ b/src/main/java/com/zatch/zatchserver/controller/UserController.java @@ -34,7 +34,7 @@ public class UserController { examples = @Example(@ExampleProperty(value = "{'property1': 'value1', 'property2': 'value2'}", mediaType = MediaType.APPLICATION_JSON_VALUE))) }) @PostMapping("/new") - @ApiOperation(value = "회원가입", notes = "회원가입 API", produces = MediaType.APPLICATION_JSON_VALUE) + @ApiOperation(value = "회원가입/로그인", notes = "회원가입/로그인 API", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity postUser(@RequestBody PostUserReqDto postUserReqDto, HttpServletResponse response) { // 이메일을 통해 회원가입 or 로그인 check String isSignup = userService.loginOrSignup(postUserReqDto.getEmail()); @@ -79,13 +79,16 @@ public ResponseEntity postUser(@RequestBody PostUserReqDto postUserReqDto, HttpS // 토큰 String email = postUserReqDto.getEmail(); String userId = userService.getUserId(email); + String nickname = userService.getNickname(email); String accessToken = authService.issueAccessToken(Long.valueOf(userId)); response.addHeader("ACCESS_TOKEN", accessToken); String token = userService.token(Long.valueOf(userId), accessToken); System.out.println("token >>>>> "+token); - return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.LOGIN_SUCCESS, new GetUserReqDto(email)+" / accessToken : "+token+" / userId : "+userId), HttpStatus.OK); + GetUserResDto getUserResDto = new GetUserResDto(Long.valueOf(userId), postUserReqDto.getName(), nickname, email); + + return ResponseEntity.ok().body(getUserResDto); } @GetMapping("/logout") @@ -151,8 +154,12 @@ public ResponseEntity getMypage(@PathVariable("userId") Long userId) { } } + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Success", response = GetUserResDto.class, + examples = @Example(@ExampleProperty(value = "{'property1': 'value1', 'property2': 'value2'}", mediaType = MediaType.APPLICATION_JSON_VALUE))) + }) @PostMapping("/{userId}/upload_profile") - @ApiOperation(value = "회원 프로필 이미지 업로드", notes = "회원 프로필 이미지 업로드 API") + @ApiOperation(value = "회원 프로필 이미지 업로드", notes = "회원 프로필 이미지 업로드 API", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity uploadProfile(@PathVariable("userId") Long userId, @RequestParam(value="image") MultipartFile image) { try { System.out.println("param_image : "+image); diff --git a/src/main/java/com/zatch/zatchserver/repository/JdbcUserRepository.java b/src/main/java/com/zatch/zatchserver/repository/JdbcUserRepository.java index e53ba5e..e556a1d 100644 --- a/src/main/java/com/zatch/zatchserver/repository/JdbcUserRepository.java +++ b/src/main/java/com/zatch/zatchserver/repository/JdbcUserRepository.java @@ -92,6 +92,20 @@ public Long insert(User user) { } } + @Override + public String getNickname(String email) { + try{ + String sql = "SELECT nickname from user WHERE email = ?"; + Object[] params = {email}; + System.out.println("Get Nickname SQL select"); + String nickname = String.valueOf(jdbcTemplate.queryForList(sql, params).get(0).get("nickname")); + System.out.println("Nickname : " + nickname); + return nickname; + } catch (Exception e){ + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Nickname Not Found"); + } + } + // 닉네임 수정 @Override public Long modifyNickname(Long userId, String newNickname) { diff --git a/src/main/java/com/zatch/zatchserver/repository/UserRepository.java b/src/main/java/com/zatch/zatchserver/repository/UserRepository.java index 49c08ff..cb15134 100644 --- a/src/main/java/com/zatch/zatchserver/repository/UserRepository.java +++ b/src/main/java/com/zatch/zatchserver/repository/UserRepository.java @@ -17,6 +17,8 @@ public interface UserRepository { Long insert(User user); + String getNickname(String email); + Long modifyNickname(Long userId, String newNickname); List> profile(Long userId); @@ -30,4 +32,5 @@ public interface UserRepository { String uploadProfile(MultipartFile image, Long userId); String patchProfile(MultipartFile image, Long userId); + } diff --git a/src/main/java/com/zatch/zatchserver/service/UserService.java b/src/main/java/com/zatch/zatchserver/service/UserService.java index 18f6d39..c805029 100644 --- a/src/main/java/com/zatch/zatchserver/service/UserService.java +++ b/src/main/java/com/zatch/zatchserver/service/UserService.java @@ -16,6 +16,8 @@ public interface UserService { List getAll(); + String getNickname(String email); + Long modifyNickname(Long userId, String newNickname); String profile(Long userId); diff --git a/src/main/java/com/zatch/zatchserver/service/UserServiceImpl.java b/src/main/java/com/zatch/zatchserver/service/UserServiceImpl.java index 00d4946..ef9b070 100644 --- a/src/main/java/com/zatch/zatchserver/service/UserServiceImpl.java +++ b/src/main/java/com/zatch/zatchserver/service/UserServiceImpl.java @@ -46,6 +46,11 @@ public List getAll() { return null; } + @Override + public String getNickname(String email) { + return userRepository.getNickname(email); + } + @Override public Long modifyNickname(Long userId, String newNickname) { return userRepository.modifyNickname(userId, newNickname);