Skip to content

Commit

Permalink
feat: 메인 페이지 대표 동네 조회 #19
Browse files Browse the repository at this point in the history
  • Loading branch information
plum-king committed Jun 24, 2023
1 parent ebecd3d commit 5a2859e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/main/java/com/zatch/zatchserver/ResponseMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "인기있는 재치 조회 성공";
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/com/zatch/zatchserver/controller/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
public interface MainRepository {
List<ViewNearZatch> getNearZatch(Long userId);
List<ViewPopularZatch> getPopularZatch(Long userId);
String getMainTown(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ViewNearZatch> getNearZatch(Long userId) {
List<ViewNearZatch> results = jdbcTemplate.query(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public class MainService {

public List<ViewPopularZatch> getPopularZatch(Long userId){return mainRepository.getPopularZatch(userId);}

public String getMainTown(Long userId){return mainRepository.getMainTown(userId);}
}

0 comments on commit 5a2859e

Please sign in to comment.