phase one of food inc#9
Conversation
| @RestController | ||
| public class FoodController { | ||
|
|
||
| private static Map<String, Food> foodRepo = new HashMap<>(); |
There was a problem hiding this comment.
I would move all references to food (either real data or fake data) out of the Resource layer. The controller should not be concerned with the underlying implementation. Remember R-S-D.
|
|
||
| @RequestMapping(value="/nutrition") | ||
| public Mono<Food> getFood(@RequestParam(value="food", defaultValue="apple") String name) { | ||
| return Mono.just(foodRepo.get(name)); |
There was a problem hiding this comment.
This is great, though you are directly talking to the data layer from the controller which should be modified so that the controller simply calls a service which then talks to the data layer
| this.protein = protein; | ||
| this.carbs = carbs; | ||
| } | ||
| public void setName(String name) { |
There was a problem hiding this comment.
You shouldn't even need set methods if you just create the foods with the constructor.
| @RestController | ||
| public class FoodController { | ||
|
|
||
| private FoodService foodService = new FoodService(); |
| import com.excella.foodinc.models.Food; | ||
|
|
||
| public class FoodData { | ||
|
|
There was a problem hiding this comment.
You might not need this class, you could put all this in a constants file somewhere and then just reference that constant in your service.
|
|
||
| @RequestMapping(value="/nutrition") | ||
| public Mono<Food> getFood(@RequestParam(value="food", defaultValue="apple") String name) { | ||
| foodService.initialize(); |
There was a problem hiding this comment.
don't initialize() anything. Use dependency injection using @Autowired
|
|
||
| private HashMap<String, Food> foodRepo; | ||
|
|
||
| public void initialize() { |
There was a problem hiding this comment.
You should be able to get rid of this method after you start using a constant
| @Test | ||
| public void contextLoads() { | ||
| } | ||
| public void foodController_success() { |
There was a problem hiding this comment.
Move this test into a controller-specific test after adding a mirror test structure to the main code
This is my initial attempt at phase one of food-inc