diff --git a/src/main/java/com/zatch/zatchserver/ResponseMessage.java b/src/main/java/com/zatch/zatchserver/ResponseMessage.java index 53fb9c4..df19c76 100644 --- a/src/main/java/com/zatch/zatchserver/ResponseMessage.java +++ b/src/main/java/com/zatch/zatchserver/ResponseMessage.java @@ -10,6 +10,8 @@ public class ResponseMessage { public static final String DELETE_USER = "회원 탈퇴 성공"; public static final String LOGOUT_SUCCESS = "로그아웃 성공"; public static final String USER_TOWN_SUCCESS = "회원 동네 설정 성공"; + public static final String USER_TOWN_EDIT_SUCCESS = "회원 동네 변경 성공"; + public static final String MY_PROFILE_SUCCESS = "내 프로필 불러오기 성공"; public static final String MYPAGE_SUCCESS = "마이페이지 불러오기 성공"; public static final String PROFILE_IMAGE_UPLOAD_SUCCESS = "프로필 업로드 성공"; diff --git a/src/main/java/com/zatch/zatchserver/controller/UserController.java b/src/main/java/com/zatch/zatchserver/controller/UserController.java index e4af211..edde8e0 100644 --- a/src/main/java/com/zatch/zatchserver/controller/UserController.java +++ b/src/main/java/com/zatch/zatchserver/controller/UserController.java @@ -40,10 +40,10 @@ public ResponseEntity postUser(@RequestBody PostUserReqDto postUserReqDto, HttpS String isSignup = userService.loginOrSignup(postUserReqDto.getEmail()); // 회원가입 - if (isSignup.equals("signup")){ + if (isSignup.equals("signup")) { List adjectives = Arrays.asList("귀여운", "당황한", "어리둥절", "깜찍한", "동글동글", "초롱초롱", "배고픈", "의아한", "놀라운", "어여쁜", "차분한", "한가한", "화려한", "깨끗한", "정직한", "활발한", "긍정적인", "낙천적인", "다정한", "단호한", "겸손한", "매력적인", "발랄한", "민첩한", "상냥한", "솔직한", "신중한", "용감한", "수줍은", "소중한"); - List animals = Arrays.asList("강아지", "거북이", "고래", "고양이", "공작", "기린", "까치", "낙타", "너구리", "늑대", "다람쥐", "부엉이", "사슴", "사자", "새우", "수달", "순록", + List animals = Arrays.asList("강아지", "거북이", "고래", "고양이", "공작", "기린", "까치", "낙타", "너구리", "늑대", "다람쥐", "부엉이", "사슴", "사자", "새우", "수달", "순록", "악어", "여우", "오리", "올빼미", "청설모", "치타", "코끼리", "토끼", "팬더", "펭귄", "표범", "햄스터", "호랑이"); Collections.shuffle(adjectives); Collections.shuffle(animals); @@ -89,13 +89,13 @@ public ResponseEntity postUser(@RequestBody PostUserReqDto postUserReqDto, HttpS } @GetMapping("/logout") - @ApiOperation(value="로그아웃", notes = "로그아웃 API") - public ResponseEntity logout(HttpServletRequest request, HttpServletResponse response) throws Exception{ + @ApiOperation(value = "로그아웃", notes = "로그아웃 API") + public ResponseEntity logout(HttpServletRequest request, HttpServletResponse response) throws Exception { try { HttpSession session = request.getSession(); session.invalidate(); return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.USER_NICKNAME_EDIT_SUCCESS, "Success Logout"), HttpStatus.OK); - } catch (Exception e){ + } catch (Exception e) { return new ResponseEntity(DefaultRes.res(StatusCode.INTERNAL_SERVER_ERROR, ResponseMessage.INTERNAL_SERVER_ERROR, "Error Logout"), HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -106,13 +106,13 @@ public ResponseEntity logout(HttpServletRequest request, HttpServletResponse res }) @PatchMapping("/{userId}/nickname") @ApiOperation(value = "회원 닉네임 수정", notes = "회원 닉네임 수정 API") - public ResponseEntity patchNickname(@PathVariable("userId") Long userId , @RequestBody PatchUserNicknameReqDto pathUserNicknameReqDto) { + public ResponseEntity patchNickname(@PathVariable("userId") Long userId, @RequestBody PatchUserNicknameReqDto pathUserNicknameReqDto) { try { String newNickname = pathUserNicknameReqDto.getNewNickname(); Long idOfModifiedUser = userId; userService.modifyNickname(idOfModifiedUser, newNickname); return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.USER_NICKNAME_EDIT_SUCCESS, new PatchUserNicknameResDto(newNickname)), HttpStatus.OK); - } catch (Exception e){ + } catch (Exception e) { return new ResponseEntity(DefaultRes.res(StatusCode.INTERNAL_SERVER_ERROR, ResponseMessage.INTERNAL_SERVER_ERROR, "Error Modify Nickname"), HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -150,6 +150,21 @@ public ResponseEntity postAddress(@PathVariable("userId") Long userId, @RequestB } } + @ApiResponses(value = { + @ApiResponse(code = 200, message = "Success", response = PostUserAddressEditReqDto.class, + examples = @Example(@ExampleProperty(value = "{'property1': 'value1'}", mediaType = MediaType.APPLICATION_JSON_VALUE))) + }) + @PostMapping("/{userId}/edit_address") + @ApiOperation(value = "회원 동네 변경", notes = "회원 동네 변경 API") + public ResponseEntity editAddress(@PathVariable("userId") Long userId, @RequestBody PostUserAddressEditReqDto postUserAddressEditReqDto) { + try { + int addressNum = postUserAddressEditReqDto.getAddress_num(); + return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.USER_TOWN_EDIT_SUCCESS, new PostUserAddressEditReqDto(addressNum)), HttpStatus.OK); + } catch (Exception e) { + return new ResponseEntity(DefaultRes.res(StatusCode.INTERNAL_SERVER_ERROR, ResponseMessage.INTERNAL_SERVER_ERROR, "Error User Town Edit"), HttpStatus.INTERNAL_SERVER_ERROR); + } + } + @ApiResponses(value = { @ApiResponse(code = 200, message = "Success", response = GetMypageResDto.class, examples = @Example(@ExampleProperty(value = "{'property1': 'value1', 'property2': 'value2'}", mediaType = MediaType.APPLICATION_JSON_VALUE))) @@ -172,9 +187,9 @@ public ResponseEntity getMypage(@PathVariable("userId") Long userId) { }) @PostMapping("/{userId}/upload_profile") @ApiOperation(value = "회원 프로필 이미지 업로드", notes = "회원 프로필 이미지 업로드 API", produces = MediaType.APPLICATION_JSON_VALUE) - public ResponseEntity uploadProfile(@PathVariable("userId") Long userId, @RequestParam(value="image") MultipartFile image) { + public ResponseEntity uploadProfile(@PathVariable("userId") Long userId, @RequestParam(value = "image") MultipartFile image) { try { - System.out.println("param_image : "+image); + System.out.println("param_image : " + image); userService.uploadProfile(userId, image); return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.PROFILE_IMAGE_UPLOAD_SUCCESS, image), HttpStatus.OK); } catch (Exception e) { @@ -188,9 +203,9 @@ public ResponseEntity uploadProfile(@PathVariable("userId") Long userId, @Reques }) @PatchMapping("/{userId}/patch_profile") @ApiOperation(value = "회원 프로필 이미지 수정", notes = "회원 프로필 이미지 수정 API") - public ResponseEntity patchProfile(@PathVariable("userId") Long userId, @RequestParam(value="image") MultipartFile image) { + public ResponseEntity patchProfile(@PathVariable("userId") Long userId, @RequestParam(value = "image") MultipartFile image) { try { - System.out.println("param_image : "+image); + 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) { diff --git a/src/main/java/com/zatch/zatchserver/domain/Address.java b/src/main/java/com/zatch/zatchserver/domain/Address.java new file mode 100644 index 0000000..6b024a7 --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/domain/Address.java @@ -0,0 +1,12 @@ +package com.zatch.zatchserver.domain; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class Address { + private String addr_name; + private String addr_x; + private String addr_y; +} diff --git a/src/main/java/com/zatch/zatchserver/dto/PostUserAddressEditReqDto.java b/src/main/java/com/zatch/zatchserver/dto/PostUserAddressEditReqDto.java new file mode 100644 index 0000000..6200468 --- /dev/null +++ b/src/main/java/com/zatch/zatchserver/dto/PostUserAddressEditReqDto.java @@ -0,0 +1,12 @@ +package com.zatch.zatchserver.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class PostUserAddressEditReqDto { + int address_num; +} diff --git a/src/main/java/com/zatch/zatchserver/repository/JdbcUserRepository.java b/src/main/java/com/zatch/zatchserver/repository/JdbcUserRepository.java index 5974e23..5583a59 100644 --- a/src/main/java/com/zatch/zatchserver/repository/JdbcUserRepository.java +++ b/src/main/java/com/zatch/zatchserver/repository/JdbcUserRepository.java @@ -1,16 +1,20 @@ package com.zatch.zatchserver.repository; +import com.zatch.zatchserver.domain.Address; import com.zatch.zatchserver.domain.User; import com.zatch.zatchserver.service.S3Uploader; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; import org.springframework.stereotype.Repository; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.server.ResponseStatusException; import javax.sql.DataSource; import java.io.IOException; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -140,7 +144,7 @@ public List> profile(Long userId) { } } - // 동네 설정 + // 동네 설정 -> 초기 설정은 addr_name_1 이 대표 동네 @Override public String addressInsert(Long userId, String addr_name, String addr_x, String addr_y) { try { @@ -167,6 +171,72 @@ public String addressInsert(Long userId, String addr_name, String addr_x, String } } + //대표 동네 변경 -> 대표 동네 변경할 때에는 main_addr_name에 덮어쓰기 + @Override + public String editAddress(Long userId, int addressNum) { + try { + List
results = null; + if (addressNum == 1) { + String sql = "SELECT addr_name_1, addr_x_1, addr_y_1 FROM address WHERE user_id = ?"; + Object[] params = new Object[]{userId}; + + results = jdbcTemplate.query(sql, params, new RowMapper
() { + @Override + public Address mapRow(ResultSet rs, int rowNum) throws SQLException { + // Map the result set to your object + Address obj = new Address(); + obj.setAddr_name(rs.getString("addr_name_1")); + obj.setAddr_x(rs.getString("addr_x_1")); + obj.setAddr_y(rs.getString("addr_y_1")); + + return obj; + } + }); + System.out.println(results.get(0)); + } + else if(addressNum == 2){ + String sql = "SELECT addr_name_2, addr_x_2, addr_y_2 FROM address WHERE user_id = ?"; + Object[] params = new Object[]{userId}; + + results = jdbcTemplate.query(sql, params, new RowMapper
() { + @Override + public Address mapRow(ResultSet rs, int rowNum) throws SQLException { + // Map the result set to your object + Address obj = new Address(); + obj.setAddr_name(rs.getString("addr_name_2")); + obj.setAddr_x(rs.getString("addr_x_2")); + obj.setAddr_y(rs.getString("addr_y_2")); + + return obj; + } + }); + System.out.println(results.get(0)); + + } + else if(addressNum == 3){ + String sql = "SELECT addr_name_3, addr_x_3, addr_y_3 FROM address WHERE user_id = ?"; + Object[] params = new Object[]{userId}; + + results = jdbcTemplate.query(sql, params, new RowMapper
() { + @Override + public Address mapRow(ResultSet rs, int rowNum) throws SQLException { + // Map the result set to your object + Address obj = new Address(); + obj.setAddr_name(rs.getString("addr_name_3")); + obj.setAddr_x(rs.getString("addr_x_3")); + obj.setAddr_y(rs.getString("addr_y_3")); + + return obj; + } + }); + } + jdbcTemplate.update("UPDATE user SET main_addr_name = ?, main_addr_x = ?, main_addr_y = ? WHERE user_id = ? ", results.get(0).getAddr_name(), results.get(0).getAddr_x(), results.get(0).getAddr_y(), userId); + return results.get(0).getAddr_name(); + } catch (Exception e) { + throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User Address Edit Error"); + } + } + // 토큰 @Override public String insertToken(Long userId, String token) { diff --git a/src/main/java/com/zatch/zatchserver/repository/UserRepository.java b/src/main/java/com/zatch/zatchserver/repository/UserRepository.java index 830fd8e..bd12f3a 100644 --- a/src/main/java/com/zatch/zatchserver/repository/UserRepository.java +++ b/src/main/java/com/zatch/zatchserver/repository/UserRepository.java @@ -25,6 +25,8 @@ public interface UserRepository { String addressInsert(Long userId, String addr_name, String addr_x, String addr_y); + String editAddress(Long userId, int addressNum); + String insertToken(Long userId, String token); List> getMypage(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 3290da0..0caf5ee 100644 --- a/src/main/java/com/zatch/zatchserver/service/UserService.java +++ b/src/main/java/com/zatch/zatchserver/service/UserService.java @@ -24,6 +24,8 @@ public interface UserService { String address(Long userId, String addr_name, String addr_x, String addr_y); + String modAddress(Long userId, int addressNum); + String token(Long userId, String token); String mypage(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 fb30e38..3379ffc 100644 --- a/src/main/java/com/zatch/zatchserver/service/UserServiceImpl.java +++ b/src/main/java/com/zatch/zatchserver/service/UserServiceImpl.java @@ -7,8 +7,6 @@ import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; -import javax.transaction.Transactional; -import java.io.IOException; import java.util.List; @RequiredArgsConstructor @@ -66,6 +64,11 @@ public String address(Long userId, String addr_name, String addr_x, String addr_ return userRepository.addressInsert(userId, addr_name, addr_x, addr_y); } + @Override + public String modAddress(Long userId, int addressNum){ + return userRepository.editAddress(userId, addressNum); + } + @Override public String token(Long userId, String token) { return userRepository.insertToken(userId, token);