Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One to one jpa assignment #193

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
52 changes: 52 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Java Maven CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-java/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/openjdk:8-jdk

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/postgres:9.4

working_directory: ~/repo

environment:
# Customize the JVM maximum heap limit
MAVEN_OPTS: -Xmx3200m

steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "pom.xml" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run: mvn dependency:go-offline

- save_cache:
paths:
- ~/.m2
key: v1-dependencies-{{ checksum "pom.xml" }}

# run tests! and gen code coverage
- run: mvn integration-test cobertura:cobertura

- store_test_results:
path: target/surefire-reports

- run:
name: Send to CodeCov
command: bash <(curl -s https://codecov.io/bash)




5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# Spring Boot Recipe Application

[![CircleCI](https://circleci.com/gh/springframeworkguru/spring5-recipe-app.svg?style=svg)](https://circleci.com/gh/springframeworkguru/spring5-recipe-app)

This repository is for an example application built in my Spring Framework 5 - Beginner to Guru

You can learn about my Spring Framework 5 Online course [here.](https://go.springframework.guru/spring-framework-5-online-course)
just to check what circleCI would say about this.
57 changes: 57 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<!-- not version b/c projectlombok is supported by the curated dependenciesof the spring boot starter-->
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7-1</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand All @@ -61,6 +77,47 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20</version>
<configuration>
<includes>
<include>**/*IT.java</include>
</includes>
<additionalClasspathElements>
<additionalClasspathElement>${basedir}/target/classes</additionalClasspathElement>
</additionalClasspathElements>
<parallel>none</parallel>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
216 changes: 216 additions & 0 deletions src/main/java/guru/springframework/bootstrap/RecipeBootstrap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
package guru.springframework.bootstrap;


import guru.springframework.domain.*;
import guru.springframework.repositories.CategoryRepository;
import guru.springframework.repositories.RecipeRepository;
import guru.springframework.repositories.UnitOfMeasureRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@Slf4j
@Component
public class RecipeBootstrap implements ApplicationListener<ContextRefreshedEvent> {

private final CategoryRepository categoryRepository;
private final RecipeRepository recipeRepository;
private final UnitOfMeasureRepository unitOfMeasureRepository;

public RecipeBootstrap(CategoryRepository categoryRepository, RecipeRepository recipeRepository, UnitOfMeasureRepository unitOfMeasureRepository) {
this.categoryRepository = categoryRepository;
this.recipeRepository = recipeRepository;
this.unitOfMeasureRepository = unitOfMeasureRepository;
}

@Override
@Transactional
public void onApplicationEvent(ContextRefreshedEvent event) {
recipeRepository.saveAll(getRecipes());
log.debug("Loading Bootstrap Data");
}

private List<Recipe> getRecipes() {

List<Recipe> recipes = new ArrayList<>(2);

//get UOMs
Optional<UnitOfMeasure> eachUomOptional = unitOfMeasureRepository.findByDescription("Each");

if(!eachUomOptional.isPresent()){
throw new RuntimeException("Expected UOM Not Found");
}

Optional<UnitOfMeasure> tableSpoonUomOptional = unitOfMeasureRepository.findByDescription("Tablespoon");

if(!tableSpoonUomOptional.isPresent()){
throw new RuntimeException("Expected UOM Not Found");
}

Optional<UnitOfMeasure> teaSpoonUomOptional = unitOfMeasureRepository.findByDescription("Teaspoon");

if(!teaSpoonUomOptional.isPresent()){
throw new RuntimeException("Expected UOM Not Found");
}

Optional<UnitOfMeasure> dashUomOptional = unitOfMeasureRepository.findByDescription("Dash");

if(!dashUomOptional.isPresent()){
throw new RuntimeException("Expected UOM Not Found");
}

Optional<UnitOfMeasure> pintUomOptional = unitOfMeasureRepository.findByDescription("Pint");

if(!pintUomOptional.isPresent()){
throw new RuntimeException("Expected UOM Not Found");
}

Optional<UnitOfMeasure> cupsUomOptional = unitOfMeasureRepository.findByDescription("Cup");

if(!cupsUomOptional.isPresent()){
throw new RuntimeException("Expected UOM Not Found");
}

//get optionals
UnitOfMeasure eachUom = eachUomOptional.get();
UnitOfMeasure tableSpoonUom = tableSpoonUomOptional.get();
UnitOfMeasure teapoonUom = tableSpoonUomOptional.get();
UnitOfMeasure dashUom = dashUomOptional.get();
UnitOfMeasure pintUom = dashUomOptional.get();
UnitOfMeasure cupsUom = cupsUomOptional.get();

//get Categories
Optional<Category> americanCategoryOptional = categoryRepository.findByDescription("American");

if(!americanCategoryOptional.isPresent()){
throw new RuntimeException("Expected Category Not Found");
}

Optional<Category> mexicanCategoryOptional = categoryRepository.findByDescription("Mexican");

if(!mexicanCategoryOptional.isPresent()){
throw new RuntimeException("Expected Category Not Found");
}

Category americanCategory = americanCategoryOptional.get();
Category mexicanCategory = mexicanCategoryOptional.get();

//Yummy Guac
Recipe guacRecipe = new Recipe();
guacRecipe.setDescription("Perfect Guacamole");
guacRecipe.setPrepTime(10);
guacRecipe.setCookTime(0);
guacRecipe.setDifficulty(Difficulty.EASY);
guacRecipe.setDirections("1 Cut avocado, remove flesh: Cut the avocados in half. Remove seed. Score the inside of the avocado with a blunt knife and scoop out the flesh with a spoon" +
"\n" +
"2 Mash with a fork: Using a fork, roughly mash the avocado. (Don't overdo it! The guacamole should be a little chunky.)" +
"\n" +
"3 Add salt, lime juice, and the rest: Sprinkle with salt and lime (or lemon) juice. The acid in the lime juice will provide some balance to the richness of the avocado and will help delay the avocados from turning brown.\n" +
"Add the chopped onion, cilantro, black pepper, and chiles. Chili peppers vary individually in their hotness. So, start with a half of one chili pepper and add to the guacamole to your desired degree of hotness.\n" +
"Remember that much of this is done to taste because of the variability in the fresh ingredients. Start with this recipe and adjust to your taste.\n" +
"4 Cover with plastic and chill to store: Place plastic wrap on the surface of the guacamole cover it and to prevent air reaching it. (The oxygen in the air causes oxidation which will turn the guacamole brown.) Refrigerate until ready to serve.\n" +
"Chilling tomatoes hurts their flavor, so if you want to add chopped tomato to your guacamole, add it just before serving.\n" +
"\n" +
"\n" +
"Read more: http://www.simplyrecipes.com/recipes/perfect_guacamole/#ixzz4jvpiV9Sd");

Notes guacNotes = new Notes();
guacNotes.setRecipeNotes("For a very quick guacamole just take a 1/4 cup of salsa and mix it in with your mashed avocados.\n" +
"Feel free to experiment! One classic Mexican guacamole has pomegranate seeds and chunks of peaches in it (a Diana Kennedy favorite). Try guacamole with added pineapple, mango, or strawberries.\n" +
"The simplest version of guacamole is just mashed avocados with salt. Don't let the lack of availability of other ingredients stop you from making guacamole.\n" +
"To extend a limited supply of avocados, add either sour cream or cottage cheese to your guacamole dip. Purists may be horrified, but so what? It tastes great.\n" +
"\n" +
"\n" +
"Read more: http://www.simplyrecipes.com/recipes/perfect_guacamole/#ixzz4jvoun5ws");

guacRecipe.setNotes(guacNotes);

//very redundent - could add helper method, and make this simpler
guacRecipe.addIngredient(new Ingredient("ripe avocados", new BigDecimal(2), eachUom));
guacRecipe.addIngredient(new Ingredient("Kosher salt", new BigDecimal(".5"), teapoonUom));
guacRecipe.addIngredient(new Ingredient("fresh lime juice or lemon juice", new BigDecimal(2), tableSpoonUom));
guacRecipe.addIngredient(new Ingredient("minced red onion or thinly sliced green onion", new BigDecimal(2), tableSpoonUom));
guacRecipe.addIngredient(new Ingredient("serrano chiles, stems and seeds removed, minced", new BigDecimal(2), eachUom));
guacRecipe.addIngredient(new Ingredient("Cilantro", new BigDecimal(2), tableSpoonUom));
guacRecipe.addIngredient(new Ingredient("freshly grated black pepper", new BigDecimal(2), dashUom));
guacRecipe.addIngredient(new Ingredient("ripe tomato, seeds and pulp removed, chopped", new BigDecimal(".5"), eachUom));

guacRecipe.getCategories().add(americanCategory);
guacRecipe.getCategories().add(mexicanCategory);

guacRecipe.setUrl("http://www.simplyrecipes.com/recipes/perfect_guacamole/");
guacRecipe.setServings(4);
guacRecipe.setSource("Simply Recipes");

//add to return list
recipes.add(guacRecipe);

//Yummy Tacos
Recipe tacosRecipe = new Recipe();
tacosRecipe.setDescription("Spicy Grilled Chicken Taco");
tacosRecipe.setCookTime(9);
tacosRecipe.setPrepTime(20);
tacosRecipe.setDifficulty(Difficulty.MODERATE);

tacosRecipe.setDirections("1 Prepare a gas or charcoal grill for medium-high, direct heat.\n" +
"2 Make the marinade and coat the chicken: In a large bowl, stir together the chili powder, oregano, cumin, sugar, salt, garlic and orange zest. Stir in the orange juice and olive oil to make a loose paste. Add the chicken to the bowl and toss to coat all over.\n" +
"Set aside to marinate while the grill heats and you prepare the rest of the toppings.\n" +
"\n" +
"\n" +
"3 Grill the chicken: Grill the chicken for 3 to 4 minutes per side, or until a thermometer inserted into the thickest part of the meat registers 165F. Transfer to a plate and rest for 5 minutes.\n" +
"4 Warm the tortillas: Place each tortilla on the grill or on a hot, dry skillet over medium-high heat. As soon as you see pockets of the air start to puff up in the tortilla, turn it with tongs and heat for a few seconds on the other side.\n" +
"Wrap warmed tortillas in a tea towel to keep them warm until serving.\n" +
"5 Assemble the tacos: Slice the chicken into strips. On each tortilla, place a small handful of arugula. Top with chicken slices, sliced avocado, radishes, tomatoes, and onion slices. Drizzle with the thinned sour cream. Serve with lime wedges.\n" +
"\n" +
"\n" +
"Read more: http://www.simplyrecipes.com/recipes/spicy_grilled_chicken_tacos/#ixzz4jvtrAnNm");

Notes tacoNotes = new Notes();
tacoNotes.setRecipeNotes("We have a family motto and it is this: Everything goes better in a tortilla.\n" +
"Any and every kind of leftover can go inside a warm tortilla, usually with a healthy dose of pickled jalapenos. I can always sniff out a late-night snacker when the aroma of tortillas heating in a hot pan on the stove comes wafting through the house.\n" +
"Today’s tacos are more purposeful – a deliberate meal instead of a secretive midnight snack!\n" +
"First, I marinate the chicken briefly in a spicy paste of ancho chile powder, oregano, cumin, and sweet orange juice while the grill is heating. You can also use this time to prepare the taco toppings.\n" +
"Grill the chicken, then let it rest while you warm the tortillas. Now you are ready to assemble the tacos and dig in. The whole meal comes together in about 30 minutes!\n" +
"\n" +
"\n" +
"Read more: http://www.simplyrecipes.com/recipes/spicy_grilled_chicken_tacos/#ixzz4jvu7Q0MJ");

tacosRecipe.setNotes(tacoNotes);

tacosRecipe.addIngredient(new Ingredient("Ancho Chili Powder", new BigDecimal(2), tableSpoonUom));
tacosRecipe.addIngredient(new Ingredient("Dried Oregano", new BigDecimal(1), teapoonUom));
tacosRecipe.addIngredient(new Ingredient("Dried Cumin", new BigDecimal(1), teapoonUom));
tacosRecipe.addIngredient(new Ingredient("Sugar", new BigDecimal(1), teapoonUom));
tacosRecipe.addIngredient(new Ingredient("Salt", new BigDecimal(".5"), teapoonUom));
tacosRecipe.addIngredient(new Ingredient("Clove of Garlic, Choppedr", new BigDecimal(1), eachUom));
tacosRecipe.addIngredient(new Ingredient("finely grated orange zestr", new BigDecimal(1), tableSpoonUom));
tacosRecipe.addIngredient(new Ingredient("fresh-squeezed orange juice", new BigDecimal(3), tableSpoonUom));
tacosRecipe.addIngredient(new Ingredient("Olive Oil", new BigDecimal(2), tableSpoonUom));
tacosRecipe.addIngredient(new Ingredient("boneless chicken thighs", new BigDecimal(4), tableSpoonUom));
tacosRecipe.addIngredient(new Ingredient("small corn tortillasr", new BigDecimal(8), eachUom));
tacosRecipe.addIngredient(new Ingredient("packed baby arugula", new BigDecimal(3), cupsUom));
tacosRecipe.addIngredient(new Ingredient("medium ripe avocados, slic", new BigDecimal(2), eachUom));
tacosRecipe.addIngredient(new Ingredient("radishes, thinly sliced", new BigDecimal(4), eachUom));
tacosRecipe.addIngredient(new Ingredient("cherry tomatoes, halved", new BigDecimal(".5"), pintUom));
tacosRecipe.addIngredient(new Ingredient("red onion, thinly sliced", new BigDecimal(".25"), eachUom));
tacosRecipe.addIngredient(new Ingredient("Roughly chopped cilantro", new BigDecimal(4), eachUom));
tacosRecipe.addIngredient(new Ingredient("cup sour cream thinned with 1/4 cup milk", new BigDecimal(4), cupsUom));
tacosRecipe.addIngredient(new Ingredient("lime, cut into wedges", new BigDecimal(4), eachUom));

tacosRecipe.getCategories().add(americanCategory);
tacosRecipe.getCategories().add(mexicanCategory);

tacosRecipe.setUrl("http://www.simplyrecipes.com/recipes/spicy_grilled_chicken_tacos/");
tacosRecipe.setServings(4);
tacosRecipe.setSource("Simply Recipes");

recipes.add(tacosRecipe);
return recipes;
}
}
13 changes: 13 additions & 0 deletions src/main/java/guru/springframework/commands/CategoryCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package guru.springframework.commands;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Setter
@Getter
@NoArgsConstructor
public class CategoryCommand {
private Long id;
private String description;
}
18 changes: 18 additions & 0 deletions src/main/java/guru/springframework/commands/IngredientCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package guru.springframework.commands;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.math.BigDecimal;

@Setter
@Getter
@NoArgsConstructor
public class IngredientCommand {
private Long id;
private Long recipeId;
private String description;
private BigDecimal amount;
private UnitOfMeasureCommand uom;
}
13 changes: 13 additions & 0 deletions src/main/java/guru/springframework/commands/NotesCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package guru.springframework.commands;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Setter
@Getter
@NoArgsConstructor
public class NotesCommand {
private Long id;
private String recipeNotes;
}
Loading