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

Finished work on Thymeleaf Studio #12

Open
wants to merge 4 commits into
base: starter-master
Choose a base branch
from
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
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# spa-day-starter-code

After all of the hard work we have put into learning about Thymeleaf, it is time for a spa day! First, we need to put our knowledge of Thymeleaf to the test. Instead of heading out to our favorite spa, let’s make an application for the owners!

Our application needs to do the following:

Display the user’s name and skin type under their customer profile.
Display the appropriate facial treatments for their skin type.
Display the description of the spa’s manicures or pedicures depending on the user’s interest.
As always, read through the whole page before starting to code.

--------

For this studio you will add functionality to allow users to sign up for your spa-day app.

The starter code has been modified from where you left off last class. Grab the refactored code on the user-signup-starter branch.

You’ll notice in this branch that the name field has been removed from the service selection form. Once we implement user-signup functionality, we can use a given user’s name to identify the spa client. We’ve also moved data into a Client model and out of the SpaDayController class.

In this studio, we’ll ask you to write another model, User. User and Client may at first appear redundant, but in the future as you develop your spa application, you may find a scenario where a user is logging in who is not also Client.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ else if (skinType.equals("dry")) {
else {
return true;
}


}

@GetMapping(value="")
Expand All @@ -41,6 +43,7 @@ public String customerForm () {
"<select name = 'manipedi'>" +
"<option value = 'manicure'>Manicure</option>" +
"<option value = 'pedicure'>Pedicure</option>" +
"<option value = 'both'>Both</option>" +
"</select><br>" +
"<input type = 'submit' value = 'Submit'>" +
"</form>";
Expand All @@ -63,6 +66,11 @@ public String spaMenu(@RequestParam String name, @RequestParam String skintype,
}
}

model.addAttribute("name", name);
model.addAttribute("skintype", skintype);
model.addAttribute("manipedi", manipedi);
model.addAttribute("appropriateFacials", appropriateFacials);

return "menu";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("user")
public class UserController {

@GetMapping("add")
public String displayAddUserForm () {
return "user/add";
}

@PostMapping("add")
public String processAddUserForm(Model model, @ModelAttribute User user, String verify) {
model.addAttribute("user", user);
if (!user.getPassword().equals(verify)) {
model.addAttribute("error", "Passwords do not match!");
return "user/add";
}

return "user/index";
}
}
82 changes: 82 additions & 0 deletions src/main/java/org/launchcode/spaday/models/Client.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package org.launchcode.spaday.models;

import java.util.ArrayList;

public class Client {

private String skinType;
private String nailService;
private ArrayList<String> appropriateFacials = new ArrayList<>();

public Client(String skinType, String nailService) {
this.skinType = skinType;
this.nailService = nailService;
}

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<String> 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<String> facials = new ArrayList<String>();
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));
}
}
}
}
38 changes: 38 additions & 0 deletions src/main/java/org/launchcode/spaday/models/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.launchcode.spaday.models;

public class User {

private String username;
private String email;
private String password;

public User(String username, String email, String password) {
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;
}
}
33 changes: 33 additions & 0 deletions src/main/resources/templates/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,41 @@
<body>
<h1>My Super Fancy Spa</h1>
<div id = "clientProfile">
<h2>My Profile</h2>
<p th:text="${name}"></p>
<p th:text="${skintype}"></p>
<p th:text="${manipedi}"></p>
</div>

<div id = "servicesMenu">
<h3>Facial Treatments</h3>
<p>The facial treatments below are recommended by our estheticians for your given skin type</p>
<table>
<th:block th:each="facial : ${appropriateFacials}">
<tr>
<td th:text="${facial}"></td>
</tr>

</th:block>
</table>
<div>
<th:block th:if="${manipedi.equals('manicure')}">
<h3>Manicure</h3>
<p th:replace="fragments :: manicureDescription"></p>
</th:block>

<th:block th:if="${manipedi.equals('pedicure')}">
<h3>Pedicure</h3>
<p th:replace="fragments :: pedicureDescription"></p>
</th:block>

<th:block th:if="${manipedi.equals('both')}">
<h3>Manicure and Pedicure</h3>
<p th:replace="fragments :: manicureDescription"></p>
<p th:replace="fragments :: pedicureDescription"></p>
</th:block>
</div>

</div>
</body>
</html>
30 changes: 30 additions & 0 deletions src/main/resources/templates/serviceSelection.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en" xmlns:th = "http://www.thymeleaf.org/">
<head>
<meta charset="UTF-8">
<title>Select Your Spa Services</title>
<link href="../static/css/styles.css" th:href="@{/css/styles.css}" rel="stylesheet" />
</head>
<body>
<form method = 'post'>

<label>
Skin type:
<select name = 'skintype'>
<option value = 'oily'>Oily</option>
<option value = 'combination'>Combination</option>
<option value = 'normal'>Normal</option>
<option value = 'dry'>Dry</option>
</select>
</label>
<label>
Manicure or Pedicure?
<select name = 'manipedi'>
<option value = 'manicure'>Manicure</option>
<option value = 'pedicure'>Pedicure</option>
</select>
</label>
<input type = 'submit' value = 'Submit'>
</form>
</body>
</html>
27 changes: 27 additions & 0 deletions src/main/resources/templates/user/add.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en" xmlns:th = "http://www.thymeleaf.org/">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>

<form method="post" th:action="@{/user/add}">
<label>Username:
<input type="text" name="username" th:value="${user}?${user.username}:'username'">
</label>
<label>Email:
<input type="email" name="email" th:value="${user}?${user.email}:'email address'">
</label>
<label>Password:
<input type="password" name="password">
</label>
<label>Verify password:
<input type="password" name="verify">
</label>
<input type="submit" value="Submit">
</form>

<p th:if="${error}" th:text="${error}"></p>
</body>
</html>
11 changes: 11 additions & 0 deletions src/main/resources/templates/user/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en" xmlns:th = "http://www.thymeleaf.org/">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h3 th:text="|Welcome, ${user.username}!|"></h3>
<a th:href="@{/}">Return to Service Selection</a>
</body>
</html>