From 5e1a3f8c9bb6daece9352c5296e5d77343397de8 Mon Sep 17 00:00:00 2001 From: Carly Langlois Date: Wed, 4 Dec 2019 14:48:55 -0600 Subject: [PATCH 01/12] move service selection form to template --- gradle/wrapper/gradle-wrapper.properties | 2 +- .../spaday/controllers/SpaDayController.java | 24 ++----------- src/main/resources/application.properties | 2 +- .../resources/templates/serviceSelection.html | 34 +++++++++++++++++++ 4 files changed, 39 insertions(+), 23 deletions(-) create mode 100644 src/main/resources/templates/serviceSelection.html diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5028f28f8..6ce793f21 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/org/launchcode/spaday/controllers/SpaDayController.java b/src/main/java/org/launchcode/spaday/controllers/SpaDayController.java index 13fcdf0ed..7c568fac7 100644 --- a/src/main/java/org/launchcode/spaday/controllers/SpaDayController.java +++ b/src/main/java/org/launchcode/spaday/controllers/SpaDayController.java @@ -43,30 +43,12 @@ else if (skinType.equals("dry")) { } } - @GetMapping(value="") - @ResponseBody + @GetMapping public String customerForm () { - String html = "
" + - "Name:
" + - "" + - "
Skin type:
" + - "
" + - "Manicure or Pedicure?
" + - "
" + - "" + - "
"; - return html; + return "serviceSelection"; } - @PostMapping(value="") + @PostMapping() public String spaMenu(@RequestParam String name, @RequestParam String skintype, @RequestParam String manipedi, Model model) { String cap = skintype.substring(0, 1).toUpperCase() + skintype.substring(1); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8b1378917..4d360de14 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1 @@ - +server.port=8081 diff --git a/src/main/resources/templates/serviceSelection.html b/src/main/resources/templates/serviceSelection.html new file mode 100644 index 000000000..e0a783db0 --- /dev/null +++ b/src/main/resources/templates/serviceSelection.html @@ -0,0 +1,34 @@ + + + + + Select Your Spa Services + + + +
+ + + + + +
+ + \ No newline at end of file From 17301ff271e91f2b7a79c285c5a5835fbeb5e9c4 Mon Sep 17 00:00:00 2001 From: Carly Langlois Date: Wed, 4 Dec 2019 16:15:21 -0600 Subject: [PATCH 02/12] refactor to use a client model --- .../spaday/controllers/SpaDayController.java | 57 +---------- .../org/launchcode/spaday/models/Client.java | 98 +++++++++++++++++++ src/main/resources/templates/menu.html | 12 +-- 3 files changed, 109 insertions(+), 58 deletions(-) create mode 100644 src/main/java/org/launchcode/spaday/models/Client.java diff --git a/src/main/java/org/launchcode/spaday/controllers/SpaDayController.java b/src/main/java/org/launchcode/spaday/controllers/SpaDayController.java index 7c568fac7..3f6be8352 100644 --- a/src/main/java/org/launchcode/spaday/controllers/SpaDayController.java +++ b/src/main/java/org/launchcode/spaday/controllers/SpaDayController.java @@ -1,5 +1,6 @@ package org.launchcode.spaday.controllers; +import org.launchcode.spaday.models.Client; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -10,66 +11,18 @@ @Controller public class SpaDayController { - public boolean checkSkinType(String skinType, String facialType) { - if (skinType.equals("oily")) { - if (facialType.equals("Microdermabrasion") || facialType.equals("Rejuvenating")) { - return true; - } - else { - return false; - } - } - else if (skinType.equals("combination")) { - if (facialType.equals("Microdermabrasion") || facialType.equals("Rejuvenating") || facialType.equals("Enzyme Peel")) { - return true; - } - else { - return false; - } - } - else if (skinType.equals("normal")) { - return true; - } - else if (skinType.equals("dry")) { - if (facialType.equals("Rejuvenating") || facialType.equals("Hydrofacial")) { - return true; - } - else { - return false; - } - } - else { - return true; - } - } - @GetMapping public String customerForm () { return "serviceSelection"; } - @PostMapping() + @PostMapping public String spaMenu(@RequestParam String name, @RequestParam String skintype, @RequestParam String manipedi, Model model) { - String cap = skintype.substring(0, 1).toUpperCase() + skintype.substring(1); - - ArrayList facials = new ArrayList(); - facials.add("Microdermabrasion"); - facials.add("Hydrofacial"); - facials.add("Rejuvenating"); - facials.add("Enzyme Peel"); - ArrayList appropriateFacials = new ArrayList(); - for (int i = 0; i < facials.size(); i ++) { - if (checkSkinType(skintype,facials.get(i))) { - appropriateFacials.add(facials.get(i)); - } - } + Client newClient = new Client(skintype, manipedi, name); + newClient.setAppropriateFacials(skintype); + model.addAttribute("client" , newClient); - model.addAttribute("name" , name); - model.addAttribute("skintype", cap); - model.addAttribute("facials", facials); - model.addAttribute("appropriateFacials", appropriateFacials); - model.addAttribute("manipedi", manipedi); return "menu"; } } diff --git a/src/main/java/org/launchcode/spaday/models/Client.java b/src/main/java/org/launchcode/spaday/models/Client.java new file mode 100644 index 000000000..ce2997187 --- /dev/null +++ b/src/main/java/org/launchcode/spaday/models/Client.java @@ -0,0 +1,98 @@ +package org.launchcode.spaday.models; + +import java.util.ArrayList; + +public class Client { + + private String name; + private String skinType; + private String nailService; + private ArrayList appropriateFacials = new ArrayList<>(); + + public Client(String skinType, String nailService) { + this.name = "Wellness Seeker"; + this.skinType = skinType; + this.nailService = nailService; + } + + public Client(String skinType, String nailService, String name) { + this.name = name; + this.skinType = skinType; + this.nailService = nailService; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getSkinType() { + return skinType; + } + + public void setSkinType(String skinType) { + this.skinType = skinType; + } + + public String getNailService() { + return nailService; + } + + public void setNailService(String nailService) { + this.nailService = nailService; + } + + public ArrayList getAppropriateFacials() { + return appropriateFacials; + } + + private boolean checkSkinType(String skinType, String facialType) { + if (skinType.equals("oily")) { + if (facialType.equals("Microdermabrasion") || facialType.equals("Rejuvenating")) { + return true; + } + else { + return false; + } + } + else if (skinType.equals("combination")) { + if (facialType.equals("Microdermabrasion") || facialType.equals("Rejuvenating") || facialType.equals("Enzyme Peel")) { + return true; + } + else { + return false; + } + } + else if (skinType.equals("normal")) { + return true; + } + else if (skinType.equals("dry")) { + if (facialType.equals("Rejuvenating") || facialType.equals("Hydrofacial")) { + return true; + } + else { + return false; + } + } + else { + return true; + } + } + + public void setAppropriateFacials(String skinType) { + ArrayList facials = new ArrayList(); + facials.add("Microdermabrasion"); + facials.add("Hydrofacial"); + facials.add("Rejuvenating"); + facials.add("Enzyme Peel"); + + for (int i = 0; i < facials.size(); i ++) { + if (checkSkinType(skinType,facials.get(i))) { + appropriateFacials.add(facials.get(i)); + } + } + } +} diff --git a/src/main/resources/templates/menu.html b/src/main/resources/templates/menu.html index 414947028..56430146c 100644 --- a/src/main/resources/templates/menu.html +++ b/src/main/resources/templates/menu.html @@ -9,9 +9,9 @@

My Super Fancy Spa

My Profile

-

-

-

+

+

+

Menu of Available Services

@@ -19,18 +19,18 @@

Menu of Available Services

Facial Treatments

The below facial treatments are recommended by our estheticians for your given skin type.

- +
-
+

Manicure

-
+

Pedicure

From a21e5ccb6852e0bc44a04a8c709147d7f12c9c59 Mon Sep 17 00:00:00 2001 From: Carly Langlois Date: Wed, 4 Dec 2019 16:26:09 -0600 Subject: [PATCH 03/12] remove custom port property --- src/main/resources/application.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 4d360de14..8b1378917 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1 @@ -server.port=8081 + From ad545aac596c017f9af8304444c548bc9198f923 Mon Sep 17 00:00:00 2001 From: Carly Langlois Date: Wed, 4 Dec 2019 17:01:26 -0600 Subject: [PATCH 04/12] begin solution from older instructions --- .../spaday/controllers/UserController.java | 21 ++++++++++ .../org/launchcode/spaday/models/User.java | 42 +++++++++++++++++++ src/main/resources/application.properties | 2 +- src/main/resources/templates/user/add.html | 33 +++++++++++++++ src/main/resources/templates/user/index.html | 10 +++++ 5 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/launchcode/spaday/controllers/UserController.java create mode 100644 src/main/java/org/launchcode/spaday/models/User.java create mode 100644 src/main/resources/templates/user/add.html create mode 100644 src/main/resources/templates/user/index.html diff --git a/src/main/java/org/launchcode/spaday/controllers/UserController.java b/src/main/java/org/launchcode/spaday/controllers/UserController.java new file mode 100644 index 000000000..b3c522263 --- /dev/null +++ b/src/main/java/org/launchcode/spaday/controllers/UserController.java @@ -0,0 +1,21 @@ +package org.launchcode.spaday.controllers; + +import org.launchcode.spaday.models.User; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +@RequestMapping("user") +public class UserController { + + @GetMapping + public String displayAddUserForm(Model model) { + return "user/add"; + } + + +} diff --git a/src/main/java/org/launchcode/spaday/models/User.java b/src/main/java/org/launchcode/spaday/models/User.java new file mode 100644 index 000000000..7c8bb028d --- /dev/null +++ b/src/main/java/org/launchcode/spaday/models/User.java @@ -0,0 +1,42 @@ +package org.launchcode.spaday.models; + +public class User { + private String username; + private String email; + private String password; + + public User() { + + } + + public User(String username, String email, String password) { + this(); + this.username = username; + this.email = email; + this.password = password; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8b1378917..4d360de14 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1 @@ - +server.port=8081 diff --git a/src/main/resources/templates/user/add.html b/src/main/resources/templates/user/add.html new file mode 100644 index 000000000..aee222cc6 --- /dev/null +++ b/src/main/resources/templates/user/add.html @@ -0,0 +1,33 @@ + + + + + Sign Up + + +
+ + + + + + + + + +
+ + + \ No newline at end of file diff --git a/src/main/resources/templates/user/index.html b/src/main/resources/templates/user/index.html new file mode 100644 index 000000000..566549bdf --- /dev/null +++ b/src/main/resources/templates/user/index.html @@ -0,0 +1,10 @@ + + + + + Title + + + + + \ No newline at end of file From 5609353c75442cf811da95be14dc34d8d449174b Mon Sep 17 00:00:00 2001 From: Carly Langlois Date: Thu, 5 Dec 2019 11:29:05 -0600 Subject: [PATCH 05/12] add error message to user add page --- .../spaday/controllers/UserController.java | 24 ++++++++++++++----- src/main/resources/templates/user/add.html | 8 ++++--- src/main/resources/templates/user/index.html | 4 ++-- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/launchcode/spaday/controllers/UserController.java b/src/main/java/org/launchcode/spaday/controllers/UserController.java index b3c522263..4616025fc 100644 --- a/src/main/java/org/launchcode/spaday/controllers/UserController.java +++ b/src/main/java/org/launchcode/spaday/controllers/UserController.java @@ -3,19 +3,31 @@ import org.launchcode.spaday.models.User; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.*; @Controller @RequestMapping("user") public class UserController { - @GetMapping - public String displayAddUserForm(Model model) { + @GetMapping("/add") + public String getAddUserForm(Model model) { return "user/add"; } + @PostMapping("/add") + public String postAddUserForm(Model model, @ModelAttribute User user, String verify) { + model.addAttribute("user", user); + model.addAttribute("verify", verify); + model.addAttribute("username", user.getUsername()); + model.addAttribute("email", user.getEmail()); + if (user.getPassword().equals(verify)) { + return "user/index"; + } else { + model.addAttribute("error", "Passwords do not match"); + return "user/add"; + } + + } + } diff --git a/src/main/resources/templates/user/add.html b/src/main/resources/templates/user/add.html index aee222cc6..33f96db8b 100644 --- a/src/main/resources/templates/user/add.html +++ b/src/main/resources/templates/user/add.html @@ -8,12 +8,12 @@