Skip to content

phase one of food inc#9

Draft
jphilly11 wants to merge 4 commits into
masterfrom
jordansBranch
Draft

phase one of food inc#9
jphilly11 wants to merge 4 commits into
masterfrom
jordansBranch

Conversation

@jphilly11

Copy link
Copy Markdown
Collaborator

This is my initial attempt at phase one of food-inc

@RestController
public class FoodController {

private static Map<String, Food> foodRepo = new HashMap<>();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import com.excella.foodinc.models.Food;

public class FoodData {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't initialize() anything. Use dependency injection using @Autowired


private HashMap<String, Food> foodRepo;

public void initialize() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to get rid of this method after you start using a constant

@Test
public void contextLoads() {
}
public void foodController_success() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this test into a controller-specific test after adding a mirror test structure to the main code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants