가게 상세 페이지
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;
|
package com.example.eatgo.interfaces;
|
||||||
|
|
||||||
import com.example.eatgo.domain.Restaurant;
|
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.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class RestaurantController {
|
public class RestaurantController {
|
||||||
|
|
||||||
|
private final RestaurantRepository repository = new RestaurantRepository();
|
||||||
|
|
||||||
@GetMapping("/restaurants")
|
@GetMapping("/restaurants")
|
||||||
public List<Restaurant> list() {
|
public List<Restaurant> list() {
|
||||||
List<Restaurant> restaurantList = new ArrayList<>();
|
return repository.findAll();
|
||||||
Restaurant restaurant = new Restaurant(1004L, "Bob zip", "Seoul");
|
|
||||||
restaurantList.add(restaurant);
|
|
||||||
return restaurantList;
|
|
||||||
}
|
}
|
||||||
@GetMapping("restaurants/{id}")
|
@GetMapping("restaurants/{id}")
|
||||||
public Restaurant detail(@PathVariable Long id) {
|
public Restaurant detail(@PathVariable Long id) {
|
||||||
List<Restaurant> restaurantList = new ArrayList<>();
|
return repository.findById(id);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user