Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 54 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,82 @@
<properties>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>

<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.11.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>2.4.15</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/tacos/HomeController.java

This file was deleted.

21 changes: 21 additions & 0 deletions src/main/java/tacos/Ingredient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package tacos;

import lombok.Data;
import lombok.RequiredArgsConstructor;

@Data
@RequiredArgsConstructor
public class Ingredient {

private final String id;
private final String name;
private final Type type;

public enum Type {
WRAP,
PROTEIN,
VEGGIES,
CHEESE,
SAUCE
}
}
37 changes: 37 additions & 0 deletions src/main/java/tacos/Order.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package tacos;

import javax.validation.constraints.Digits;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;

import org.hibernate.validator.constraints.CreditCardNumber;

import lombok.Data;

@Data
public class Order {

@NotBlank(message = "Name is required")
private String name;

@NotBlank(message = "Street is required")
private String street;

@NotBlank(message = "City is required")
private String city;

@NotBlank(message = "State is required")
private String state;

@NotBlank(message = "Zip code is required")
private String zip;

@CreditCardNumber(message = "Not a valid credit card number")
private String ccNumber;

@Pattern(regexp = "^(0[1-9]|1[0-2])([/])([1-9][0-9])$", message = "Must be formatted MM/YY")
private String ccExpiration;

@Digits(integer = 3, fraction = 0, message = "Invalid CVV")
private String ccCVV;
}
19 changes: 19 additions & 0 deletions src/main/java/tacos/Taco.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package tacos;

import java.util.List;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import lombok.Data;

@Data
public class Taco {

@NotNull
@Size(min = 5, message = "Name must be at least 5 characters long")
private String name;

@Size(min = 1, message = "You must choose at least 1 ingredient")
private List<String> ingredients;
}
65 changes: 65 additions & 0 deletions src/main/java/tacos/web/DesignTacoController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package tacos.web;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import lombok.extern.slf4j.Slf4j;
import tacos.Ingredient;
import tacos.Ingredient.Type;
import tacos.Taco;

@Slf4j
@Controller
@RequestMapping("/design")
public class DesignTacoController {

@ModelAttribute
public void addIngredientsToModel(Model model) {
List<Ingredient> ingredients = Arrays.asList(new Ingredient("FLTO", "Flour Tortilla", Type.WRAP),
new Ingredient("COTO", "Corn Tortilla", Type.WRAP), new Ingredient("GRBF", "Ground Beef", Type.PROTEIN),
new Ingredient("CARN", "Carnitas", Type.PROTEIN), new Ingredient("TMTO", "Diced Tomatoes", Type.VEGGIES),
new Ingredient("LETC", "Lettuce", Type.VEGGIES), new Ingredient("CHED", "Cheddar", Type.CHEESE),
new Ingredient("JACK", "Monterrey Jack", Type.CHEESE), new Ingredient("SLSA", "Salsa", Type.SAUCE),
new Ingredient("SRCR", "Sour Cream", Type.SAUCE));

Type[] types = Ingredient.Type.values();
for (Type type : types) {
model.addAttribute(type.toString()
.toLowerCase(), filterByType(ingredients, type));
}
}

@GetMapping
public String showDesignForm(Model model) {
model.addAttribute("design", new Taco());
return "design";
}

@PostMapping
public String processDesign(@Valid @ModelAttribute("design") Taco design, Errors errors) {
if (errors.hasErrors()) {
return "design";
}
log.info("Processing design: " + design);

return "redirect:/orders/current";
}

private List<Ingredient> filterByType(List<Ingredient> ingredients, Type type) {
return ingredients.stream()
.filter(x -> x.getType()
.equals(type))
.collect(Collectors.toList());
}
}
35 changes: 35 additions & 0 deletions src/main/java/tacos/web/OrderController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package tacos.web;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import lombok.extern.slf4j.Slf4j;
import tacos.Order;

@Slf4j
@Controller
@RequestMapping("/orders")
public class OrderController {

@GetMapping("/current")
public String orderForm(Model model) {
model.addAttribute("order", new Order());
return "orderForm";
}

@PostMapping
public String processOrder(@Valid Order order, Errors errors) {
if (errors.hasErrors()) {
return "orderForm";
}

log.info("Order submitted: " + order);
return "redirect:/";
}
}
15 changes: 15 additions & 0 deletions src/main/java/tacos/web/WebConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package tacos.web;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/")
.setViewName("home");
}
}
1 change: 0 additions & 1 deletion src/main/resources/application.properties

This file was deleted.

Empty file.
Binary file modified src/main/resources/static/images/TacoCloud.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions src/main/resources/static/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
div.ingredient-group:nth-child(odd) {
float: left;
padding-right: 20px;
}

div.ingredient-group:nth-child(even) {
float: left;
padding-right: 0;
}

div.ingredient-group {
width: 50%;
}

.grid:after {
content: "";
display: table;
clear: both;
}

*, *:after, *:before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}

span.validationError {
color: red;
}
Loading