레스토랑 예약 사이트 1 - 레스토랑 관리(사용자) 레스토랑 정보 가져오기
사용자 페이지사용자의 경우 레스토랑을 관리하지 않으므로 레스토랑 정보를 추가하거나 수정할필요는 없고 조회하는 기능만 있으면 된다. 모든 Restaurant정보 가져오기 특정 Restaurant정보 가져오기 Request Parameter를 통한 레스토랑 조회 control요청시 RequestParameter를 통해 원하는 지역, 카테고리를 통해 해당 조건을 만족하는 레스토랑 정보를 모두 가져올 수 있도록 한다. 특정 Restaurant 정보를 가져오는 함수들은 관리자에서 만들었던 내용과 같으므로 생각한다. @CrossOrigin@RestController@RequiredArgsConstructorpublic class RestaurantController { private final RestaurantService restaurantService; @GetMapping("/restaurants") public List<Restaurant> list(@RequestParam("region") String region, @RequestParam("category") Long category) { List<Restaurant> restaurants = restaurantService.getRestaurants(region, category); return restaurants; } @GetMapping("/restaurants/{id}") public Restaurant detail(@PathVariable Long id) throws Exception { Restaurant restaurant = restaurantService.getRestaurant(id); return restaurant; }} Request Parameter를 통한 레스토랑 조회 테스트 코드 작성@Testpublic void RequestParameter를_이용한_list를_확인한다() throws Exception { List<Restaurant> restaurants = new ArrayList<>(); restaurants.add(Restaurant.builder() .id(1004L) .categoryId(1L) .name("JOKER House") .address("Seoul") .build()); given(restaurantService.getRestaurants("Seoul", 1L)).willReturn(restaurants); ResultActions resultActions = mockMvc.perform(get("/restaurants?region=Seoul&category=1")); resultActions .andExpect(status().isOk()) .andExpect(content().string(containsString("\"id\":1004"))) .andExpect(content().string(containsString("\"name\":\"JOKER House\""))) .andDo(print());}