Skip to content

Commit

Permalink
#3 feat : 동네설정 경도 위도, Error 메세지 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Suanna01 committed Apr 14, 2023
1 parent 779b0a1 commit b49bd57
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,15 @@ public ResponseEntity getProfile(@PathVariable("userId") Long userId) {
}
}

@PostMapping("/{userId}/town")
@PostMapping("/{userId}/address")
@ApiOperation(value = "회원 동네", notes = "회원 동네 API")
public ResponseEntity postTown(@PathVariable("userId") Long userId, @RequestBody PostUserTownReqDto postUserTownReqDTO) {
public ResponseEntity postAddress(@PathVariable("userId") Long userId, @RequestBody PostUserAddressReqDto postUserAddressReqDTO) {
try {
String town = postUserTownReqDTO.getTown();
String userTown = userService.town(userId, town);
return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.USER_TOWN_SUCCESS, new PostUserTownReqDto(userTown)), HttpStatus.OK);
String addr_name = postUserAddressReqDTO.getAddr_name();
String addr_x = postUserAddressReqDTO.getAddr_x();
String addr_y = postUserAddressReqDTO.getAddr_y();
userService.address(userId, addr_name, addr_x, addr_y);
return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.USER_TOWN_SUCCESS, new PostUserAddressReqDto(addr_name, addr_x, addr_y)), HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity(DefaultRes.res(StatusCode.INTERNAL_SERVER_ERROR, ResponseMessage.INTERNAL_SERVER_ERROR, "Error User Town"), HttpStatus.INTERNAL_SERVER_ERROR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class PostUserTownReqDto {
String town;
public class PostUserAddressReqDto {
String addr_name;
String addr_x;
String addr_y;
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public String isSignup(String email) {
}
return "login";
} catch (Exception e){
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User Email Not Found");
}
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User Login or Signup Error"); }
}

@Override
Expand All @@ -68,9 +67,19 @@ public Long insert(User user) {
Object[] params = {user.getName(), user.getNickname(), user.getEmail()};
jdbcTemplate.update(sql, params);
System.out.println("Signup sql insert");
// user_id 가져오기
String sql2 = "SELECT user_id from user WHERE email = ?";
Object[] params2 = {user.getEmail()};
String user_id = String.valueOf(jdbcTemplate.queryForList(sql2, params2).get(0).get("user_id"));
System.out.println("User ID = " + user_id);
// address table에도 user_id 추가
String sql3 = "INSERT INTO address(user_id) VALUES(?)";
Object[] params3 = {user_id};
jdbcTemplate.update(sql3, params3);
System.out.println("Signup insert address sql insert");
return user.getId();
} catch (Exception e){
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User Email Not Found");
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User Info Insert Error");
}
}

Expand All @@ -83,7 +92,7 @@ public Long modifyNickname(Long userId, String newNickname) {
System.out.println("Modify nickname sql update");
return userId;
} catch (Exception e){
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User Email Not Found");
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User Nickname Modify Error");
}
}

Expand All @@ -102,29 +111,30 @@ public List<Map<String, Object>> profile(Long userId) {
}

@Override
public String townInsert(Long userId, String town){
public String addressInsert(Long userId, String addr_name, String addr_x, String addr_y){
try {
String town1 = jdbcTemplate.queryForObject("SELECT town1 from user WHERE user_id = ?", new Object[]{userId}, String.class);
String town2 = jdbcTemplate.queryForObject("SELECT town2 from user WHERE user_id = ?", new Object[]{userId}, String.class);
String town3 = jdbcTemplate.queryForObject("SELECT town3 from user WHERE user_id = ?", new Object[]{userId}, String.class);
if (town1 == null){
jdbcTemplate.update("UPDATE user SET town1 = ? WHERE user_id = ?", town, userId);
System.out.println("User's town1 sql update");
System.out.println("사용자 위치 정보 : " + addr_name + " " + addr_x + " " + addr_y);
String addr_name_1 = jdbcTemplate.queryForObject("SELECT addr_name_1 from address WHERE user_id = ?", new Object[]{userId}, String.class);
String addr_name_2 = jdbcTemplate.queryForObject("SELECT addr_name_2 from address WHERE user_id = ?", new Object[]{userId}, String.class);
String addr_name_3 = jdbcTemplate.queryForObject("SELECT addr_name_3 from address WHERE user_id = ?", new Object[]{userId}, String.class);
if (addr_name_1 == null){
jdbcTemplate.update("UPDATE address SET addr_name_1 = ?, addr_x_1 = ?, addr_y_1 = ? WHERE user_id = ?", addr_name, addr_x, addr_y, userId);
System.out.println("User's address 1 sql update");
}
else if (town2 == null){
jdbcTemplate.update("UPDATE user SET town2 = ? WHERE user_id = ?", town, userId);
System.out.println("User's town2 sql update");
else if (addr_name_2 == null){
jdbcTemplate.update("UPDATE address SET addr_name_2 = ?, addr_x_2 = ?, addr_y_2 = ? WHERE user_id = ?", addr_name, addr_x, addr_y, userId);
System.out.println("User's address 2 sql update");
}
else if (town3 == null){
jdbcTemplate.update("UPDATE user SET town3 = ? WHERE user_id = ?", town, userId);
System.out.println("User's town3 sql update");
else if (addr_name_3 == null){
jdbcTemplate.update("UPDATE address SET addr_name_3 = ?, addr_x_3 = ?, addr_y_3 = ? WHERE user_id = ?", addr_name, addr_x, addr_y, userId);
System.out.println("User's address 3 sql update");
}
else {
System.out.println("User's town over 3");
System.out.println("User's address over 3");
}
return town;
return addr_name;
} catch (Exception e){
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User Email Not Found");
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "User Address Insert Error");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public interface UserRepository {

List<Map<String, Object>> profile(Long userId);

String townInsert(Long userId, String town);
String addressInsert(Long userId, String addr_name, String addr_x, String addr_y);

String insertToken(Long userId, String token);

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/zatch/zatchserver/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public interface UserService {

String profile(Long userId);

String town(Long userId, String town);
String address(Long userId, String addr_name, String addr_x, String addr_y);

String token(Long userId, String token);

String mypage(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public String profile(Long userId) {
}

@Override
public String town(Long userId, String town) {
return userRepository.townInsert(userId, town);
public String address(Long userId, String addr_name, String addr_x, String addr_y) {
return userRepository.addressInsert(userId, addr_name, addr_x, addr_y);
}

@Override
Expand Down

0 comments on commit b49bd57

Please sign in to comment.