Skip to content

Commit

Permalink
#3 feat : 프로필 사진 변경 patch, 마이페이지 -> 프로필사진 get (SocketException)
Browse files Browse the repository at this point in the history
  • Loading branch information
Suanna01 committed Apr 14, 2023
1 parent 55818ee commit f139395
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/main/java/com/zatch/zatchserver/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public List<User> selectAll() {
return null;
}

// 회원가입 or 로그인 확인
@Override
public String isSignup(String email) {
try{
Expand Down Expand Up @@ -64,6 +65,7 @@ public String getUserId(String email) {
}
}

// 회원가입
@Override
public Long insert(User user) {
try {
Expand All @@ -80,6 +82,7 @@ public Long insert(User user) {
}
}

// 닉네임 수정
@Override
public Long modifyNickname(Long userId, String newNickname) {
try {
Expand All @@ -93,10 +96,16 @@ public Long modifyNickname(Long userId, String newNickname) {
}
}

// 프로필 보기
@Override
public List<Map<String, Object>> 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};
Expand All @@ -107,6 +116,7 @@ public List<Map<String, Object>> profile(Long userId) {
}
}

// 동네 설정
@Override
public String townInsert(Long userId, String town){
try {
Expand Down Expand Up @@ -134,6 +144,7 @@ else if (town3 == null){
}
}

// 토큰
@Override
public String insertToken(Long userId, String token) {
try {
Expand All @@ -145,22 +156,25 @@ public String insertToken(Long userId, String token) {
}
}

// 마이페이지 보기
@Override
public List<Map<String, Object>> 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){
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User My Page Not Found");
}
}

// S3
@Autowired
private S3Uploader s3Uploader;

// 프로필 이미지 업로드
@Override
public String uploadProfile(MultipartFile image, Long userId) {
if(!image.isEmpty()) {
Expand All @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ public interface UserRepository {
List<Map<String, Object>> getMypage(Long userId);

String uploadProfile(MultipartFile image, Long userId);

String patchProfile(MultipartFile image, Long userId);
}
4 changes: 4 additions & 0 deletions src/main/java/com/zatch/zatchserver/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit f139395

Please sign in to comment.