가게 상세 페이지
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.example.eatgo.domain;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RestaurantRepository {
|
||||
|
||||
private List<Restaurant> restaurantList = new ArrayList<>();
|
||||
|
||||
public RestaurantRepository() {
|
||||
restaurantList.add(new Restaurant(1004L, "Bob zip", "Seoul"));
|
||||
restaurantList.add(new Restaurant(2020L, "Cyber Food", "Seoul"));
|
||||
}
|
||||
|
||||
public List<Restaurant> findAll() {
|
||||
return restaurantList;
|
||||
}
|
||||
|
||||
public Restaurant findById(Long id) {
|
||||
return restaurantList.stream().filter(v -> v.getId().equals(id)).findFirst().orElse(null) ;
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,26 @@
|
||||
package com.example.eatgo.interfaces;
|
||||
|
||||
import com.example.eatgo.domain.Restaurant;
|
||||
import com.example.eatgo.domain.RestaurantRepository;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
@RestController
|
||||
public class RestaurantController {
|
||||
|
||||
private final RestaurantRepository repository = new RestaurantRepository();
|
||||
|
||||
@GetMapping("/restaurants")
|
||||
public List<Restaurant> list() {
|
||||
List<Restaurant> restaurantList = new ArrayList<>();
|
||||
Restaurant restaurant = new Restaurant(1004L, "Bob zip", "Seoul");
|
||||
restaurantList.add(restaurant);
|
||||
return restaurantList;
|
||||
return repository.findAll();
|
||||
}
|
||||
@GetMapping("restaurants/{id}")
|
||||
public Restaurant detail(@PathVariable Long id) {
|
||||
List<Restaurant> restaurantList = new ArrayList<>();
|
||||
restaurantList.add(new Restaurant(1004L, "Bob zip", "Seoul"));
|
||||
restaurantList.add(new Restaurant(2020L, "Cyber Food", "Seoul"));
|
||||
Restaurant restaurant = restaurantList.stream().filter(v -> v.getId().equals(id)).findFirst().orElse(null) ;
|
||||
|
||||
return restaurant;
|
||||
return repository.findById(id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user