diff --git a/src/main/java/com/zatch/zatchserver/ResponseMessage.java b/src/main/java/com/zatch/zatchserver/ResponseMessage.java index 8727f0e..cda1992 100644 --- a/src/main/java/com/zatch/zatchserver/ResponseMessage.java +++ b/src/main/java/com/zatch/zatchserver/ResponseMessage.java @@ -18,7 +18,9 @@ public class ResponseMessage { public static final String USER_NICKNAME_EDIT_SUCCESS ="회원 닉네임 수정 성공"; public static final String INTERNAL_SERVER_ERROR = "서버 내부 에러"; public static final String DB_ERROR = "데이터베이스 에러"; - + + public static final String GET_MY_TOWN_SUCCESS = "내 동네 조회 성공"; + public static final String GET_MY_TOWN_FAIL = "내 동네 조회 실패"; public static final String GET_NEAR_ZATCH_SUCCESS = "내 주변 재치 조회 성공"; public static final String GET_NEAR_ZATCH_FAIL = "내 주변 재치 조회 실패"; public static final String GET_POPULAR_ZATCH_SUCCESS = "인기있는 재치 조회 성공"; diff --git a/src/main/java/com/zatch/zatchserver/controller/MainController.java b/src/main/java/com/zatch/zatchserver/controller/MainController.java index ca82ba6..e47093c 100644 --- a/src/main/java/com/zatch/zatchserver/controller/MainController.java +++ b/src/main/java/com/zatch/zatchserver/controller/MainController.java @@ -19,12 +19,16 @@ public class MainController { private final MainService mainService; -// //메인페이지에 선택한 동네 띄우기 -// @GetMapping("/myTown") -// public List getMyTown(Long userId){ -// return mainService.getNearZatch(userId); -// -// } + //메인페이지에 선택한 동네 띄우기 + @GetMapping("/{userId}/myTown") + public ResponseEntity getMyTown(@PathVariable("userId") Long userId){ + try { + String main_town = mainService.getMainTown(userId); + return new ResponseEntity(DefaultRes.res(StatusCode.OK, ResponseMessage.GET_MY_TOWN_SUCCESS, main_town), HttpStatus.OK); + } catch (Exception e) { + return new ResponseEntity(DefaultRes.res(StatusCode.INTERNAL_SERVER_ERROR, ResponseMessage.GET_MY_TOWN_FAIL, "Error Get Town"), HttpStatus.INTERNAL_SERVER_ERROR); + } + } //메인페이지 내 주변 재치 조회 리스트 @GetMapping("/{userId}/viewNearZatch") diff --git a/src/main/java/com/zatch/zatchserver/repository/MainRepository.java b/src/main/java/com/zatch/zatchserver/repository/MainRepository.java index e9cf02d..4c71c8a 100644 --- a/src/main/java/com/zatch/zatchserver/repository/MainRepository.java +++ b/src/main/java/com/zatch/zatchserver/repository/MainRepository.java @@ -8,4 +8,5 @@ public interface MainRepository { List getNearZatch(Long userId); List getPopularZatch(Long userId); + String getMainTown(Long userId); } diff --git a/src/main/java/com/zatch/zatchserver/repository/MainRepositoryImpl.java b/src/main/java/com/zatch/zatchserver/repository/MainRepositoryImpl.java index caa7f45..6e9742f 100644 --- a/src/main/java/com/zatch/zatchserver/repository/MainRepositoryImpl.java +++ b/src/main/java/com/zatch/zatchserver/repository/MainRepositoryImpl.java @@ -19,6 +19,14 @@ public MainRepositoryImpl(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); } + @Override + public String getMainTown(Long userId){ + String sql = "SELECT main_addr_name FROM user WHERE user_id = ?;"; + Object[] params = {userId}; + String main_addr_name = String.valueOf(jdbcTemplate.queryForList(sql, params).get(0).get("main_addr_name")); + return main_addr_name; + } + @Override public List getNearZatch(Long userId) { List results = jdbcTemplate.query( diff --git a/src/main/java/com/zatch/zatchserver/service/MainService.java b/src/main/java/com/zatch/zatchserver/service/MainService.java index fbd4899..025284a 100644 --- a/src/main/java/com/zatch/zatchserver/service/MainService.java +++ b/src/main/java/com/zatch/zatchserver/service/MainService.java @@ -17,4 +17,5 @@ public class MainService { public List getPopularZatch(Long userId){return mainRepository.getPopularZatch(userId);} + public String getMainTown(Long userId){return mainRepository.getMainTown(userId);} }