From f139395112418af2095b1b1bb4a5af2061ca6d82 Mon Sep 17 00:00:00 2001 From: sungone <20200999@sungshin.ac.kr> Date: Fri, 14 Apr 2023 15:06:42 +0900 Subject: [PATCH] =?UTF-8?q?#3=20feat=20:=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EC=82=AC=EC=A7=84=20=EB=B3=80=EA=B2=BD=20patch,=20=EB=A7=88?= =?UTF-8?q?=EC=9D=B4=ED=8E=98=EC=9D=B4=EC=A7=80=20->=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=ED=95=84=EC=82=AC=EC=A7=84=20get=20(SocketException)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UserController.java | 12 ++++++ .../repository/JdbcUserRepository.java | 38 +++++++++++++++++-- .../repository/UserRepository.java | 2 + .../zatchserver/service/UserService.java | 4 ++ .../zatchserver/service/UserServiceImpl.java | 5 +++ 5 files changed, 58 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 347964a..04d46ec 100644 --- a/src/main/java/com/zatch/zatchserver/controller/UserController.java +++ b/src/main/java/com/zatch/zatchserver/controller/UserController.java @@ -146,4 +146,16 @@ public ResponseEntity uploadProfile(@PathVariable("userId") Long userId, @Reques return new ResponseEntity(DefaultRes.res(StatusCode.INTERNAL_SERVER_ERROR, ResponseMessage.INTERNAL_SERVER_ERROR, "Error Image Upload"), HttpStatus.INTERNAL_SERVER_ERROR); } } + + @PatchMapping("/{userId}/patch_profile") + @ApiOperation(value = "회원 프로필 이미지 수정", notes = "회원 프로필 이미지 수정 API") + public ResponseEntity patchProfile(@PathVariable("userId") Long userId, @RequestParam(value="image") MultipartFile image) { + try { + System.out.println("param_image : "+image); + userService.patchProfile(userId, image); + return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.PROFILE_IMAGE_UPLOAD_SUCCESS, image), HttpStatus.OK); + } catch (Exception e) { + return new ResponseEntity(DefaultRes.res(StatusCode.INTERNAL_SERVER_ERROR, ResponseMessage.INTERNAL_SERVER_ERROR, "Error Image Upload"), HttpStatus.INTERNAL_SERVER_ERROR); + } + } } diff --git a/src/main/java/com/zatch/zatchserver/repository/JdbcUserRepository.java b/src/main/java/com/zatch/zatchserver/repository/JdbcUserRepository.java index 4d67c55..8dc48ed 100644 --- a/src/main/java/com/zatch/zatchserver/repository/JdbcUserRepository.java +++ b/src/main/java/com/zatch/zatchserver/repository/JdbcUserRepository.java @@ -35,6 +35,7 @@ public List selectAll() { return null; } + // 회원가입 or 로그인 확인 @Override public String isSignup(String email) { try{ @@ -64,6 +65,7 @@ public String getUserId(String email) { } } + // 회원가입 @Override public Long insert(User user) { try { @@ -80,6 +82,7 @@ public Long insert(User user) { } } + // 닉네임 수정 @Override public Long modifyNickname(Long userId, String newNickname) { try { @@ -93,10 +96,16 @@ public Long modifyNickname(Long userId, String newNickname) { } } + // 프로필 보기 @Override public List> profile(Long userId) { try { - String sql = "SELECT user.user_id, user.nickname, zatch.zatch_id, zatch.item_name review_context, star_rating " + + // 재치 없을 때 + + // 후기 없을 때 + + // DB 바뀌면서 item_name -> md_name 변경됨 + String sql = "SELECT user.user_id, user.nickname, user.profile_img_url, zatch.zatch_id, zatch.md_name review_context, star_rating " + "FROM zatch.review_star LEFT JOIN zatch.zatch on review_star.send_user_id = zatch.user_id LEFT JOIN zatch.user on zatch.user_id = user.user_id " + "WHERE user.user_id = ? ORDER BY review_star.created_at DESC;"; Object[] params = {userId}; @@ -107,6 +116,7 @@ public List> profile(Long userId) { } } + // 동네 설정 @Override public String townInsert(Long userId, String town){ try { @@ -134,6 +144,7 @@ else if (town3 == null){ } } + // 토큰 @Override public String insertToken(Long userId, String token) { try { @@ -145,12 +156,13 @@ public String insertToken(Long userId, String token) { } } + // 마이페이지 보기 @Override public List> getMypage(Long userId) { try { - String sql = "SELECT user.user_id, user.nickname, COUNT(*) AS zatch_count, (SELECT COUNT(zatch_like.zatch_id) AS zatch_like_count FROM zatch.zatch_like WHERE user_id = 6) AS zatch_like_count " + + String sql = "SELECT user.user_id, user.nickname, user.profile_img_url, COUNT(*) AS zatch_count, (SELECT COUNT(zatch_like.zatch_id) AS zatch_like_count FROM zatch.zatch_like WHERE user_id = ?) AS zatch_like_count " + "FROM zatch.zatch AS A LEFT JOIN zatch.user on user.user_id = A.user_id WHERE user.user_id = ?;"; - Object[] params = {userId}; + Object[] params = {userId, userId}; System.out.println("User's My Page SQL select"); return jdbcTemplate.queryForList(sql, params); } catch (Exception e){ @@ -158,9 +170,11 @@ public List> getMypage(Long userId) { } } + // S3 @Autowired private S3Uploader s3Uploader; + // 프로필 이미지 업로드 @Override public String uploadProfile(MultipartFile image, Long userId) { if(!image.isEmpty()) { @@ -177,4 +191,22 @@ public String uploadProfile(MultipartFile image, Long userId) { } throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User Profile Empty Error"); } + + // 프로필 이미지 수정 + @Override + public String patchProfile(MultipartFile image, Long userId) { + if(!image.isEmpty()) { + String storedFileName = null; + try { + storedFileName = s3Uploader.upload(image,"images"); + System.out.println("filename : "+storedFileName); + jdbcTemplate.update("UPDATE zatch.user SET profile_img_url = ? WHERE user_id = ?", storedFileName, userId); + System.out.println("Profile image upload sql update"); + return String.valueOf(image); + } catch (IOException e) { + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User Profile Upload Error"); + } + } + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User Profile Empty Error"); + } } diff --git a/src/main/java/com/zatch/zatchserver/repository/UserRepository.java b/src/main/java/com/zatch/zatchserver/repository/UserRepository.java index e57c05f..ea57fe2 100644 --- a/src/main/java/com/zatch/zatchserver/repository/UserRepository.java +++ b/src/main/java/com/zatch/zatchserver/repository/UserRepository.java @@ -28,4 +28,6 @@ public interface UserRepository { List> getMypage(Long userId); 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 a63bc6a..d58cc6e 100644 --- a/src/main/java/com/zatch/zatchserver/service/UserService.java +++ b/src/main/java/com/zatch/zatchserver/service/UserService.java @@ -23,6 +23,10 @@ public interface UserService { String town(Long userId, String town); String token(Long userId, String token); + String mypage(Long userId); + String uploadProfile(Long userId, MultipartFile image); + + String patchProfile(Long userId, MultipartFile image); } diff --git a/src/main/java/com/zatch/zatchserver/service/UserServiceImpl.java b/src/main/java/com/zatch/zatchserver/service/UserServiceImpl.java index b05062e..74acd40 100644 --- a/src/main/java/com/zatch/zatchserver/service/UserServiceImpl.java +++ b/src/main/java/com/zatch/zatchserver/service/UserServiceImpl.java @@ -75,4 +75,9 @@ public String mypage(Long userId) { public String uploadProfile(Long userId, MultipartFile image) { return userRepository.uploadProfile(image, userId); } + + @Override + public String patchProfile(Long userId, MultipartFile image) { + return userRepository.patchProfile(image, userId); + } }