mirror of
https://gitlab.com/etc404/software-engineering-project.git
synced 2026-05-10 20:52:58 +00:00
create account and recipe working. Explore kind of works
This commit is contained in:
@@ -36,7 +36,8 @@ public class RecipeController {
|
||||
|
||||
// build create recipe REST API
|
||||
@PostMapping
|
||||
public ResponseEntity<RecipeDto> saveRecipe(@RequestBody RecipeDto recipeDto, Authentication authentication) {
|
||||
public ResponseEntity<RecipeDto> saveRecipe(@Valid @RequestBody Recipe recipe, Authentication authentication) {
|
||||
RecipeDto recipeDto = recipeService.convertToDto(recipe);
|
||||
String currentUsername = authentication.getName();
|
||||
return new ResponseEntity<>(recipeService.saveRecipe(recipeDto, currentUsername), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
@Controller
|
||||
public class SiteController {
|
||||
@@ -49,12 +50,25 @@ public class SiteController {
|
||||
return "view-recipe";
|
||||
}
|
||||
|
||||
// @GetMapping("/explore")
|
||||
// public String viewExplorePage(Model model) {
|
||||
// //model.addAttribute("allemplist", employeeServiceImpl.getAllEmployee());
|
||||
// List<RecipeDto> recipes = recipeService.getAllRecipes();
|
||||
// model.addAttribute("recipes", recipes);
|
||||
// return "explore";
|
||||
// }
|
||||
|
||||
@GetMapping("/explore")
|
||||
public String viewExplorePage(Model model) {
|
||||
//model.addAttribute("allemplist", employeeServiceImpl.getAllEmployee());
|
||||
List<RecipeDto> recipes = recipeService.getAllRecipes();
|
||||
model.addAttribute("recipes", recipes);
|
||||
public String explore(
|
||||
@RequestParam(required = false) String q,
|
||||
@RequestParam(required = false) List<String> tags,
|
||||
Model model
|
||||
) {
|
||||
List<RecipeDto> recipes = recipeService.getRecipes(q, tags);
|
||||
model.addAttribute("recipes", recipes);
|
||||
model.addAttribute("q", q);
|
||||
return "explore";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -4,8 +4,11 @@ import java.security.Principal;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -34,10 +37,10 @@ public class UserController {
|
||||
this.userRepo = userRepo;
|
||||
}
|
||||
|
||||
|
||||
// build create user REST API
|
||||
@PostMapping
|
||||
public ResponseEntity<User> saveUser(@RequestBody User user) {
|
||||
|
||||
return new ResponseEntity<User>(userService.saveUser(user), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
|
||||
@@ -129,6 +129,7 @@ public class RecipeServiceImpl implements RecipeService {
|
||||
ensureUserNotBanned(currentUser);
|
||||
enforceUploadLimit(currentUser);
|
||||
|
||||
|
||||
Recipe recipe = new Recipe(dto.getTitle(), dto.getDescription(), dto.getPrepTimeMinutes(),
|
||||
dto.getCookTimeMinutes(), dto.getServings(), currentUser, dto.getStatus());
|
||||
|
||||
@@ -146,6 +147,7 @@ public class RecipeServiceImpl implements RecipeService {
|
||||
riDto.getNotes());
|
||||
|
||||
recipe.getRecipeIngredients().add(ri);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -373,7 +375,7 @@ public class RecipeServiceImpl implements RecipeService {
|
||||
|
||||
List<Recipe> recipes;
|
||||
|
||||
if (!name.isBlank()) {
|
||||
if ((name != null) && (!name.isBlank())) {
|
||||
recipes = recipeRepository.findByTitleContainingIgnoreCase(name);
|
||||
}
|
||||
|
||||
@@ -381,7 +383,7 @@ public class RecipeServiceImpl implements RecipeService {
|
||||
recipes = recipeRepository.findAll();
|
||||
}
|
||||
|
||||
if (!tags.isEmpty() && !recipes.isEmpty()) {
|
||||
if ((tags != null) && (!tags.isEmpty()) && !recipes.isEmpty()) {
|
||||
recipes = recipes.stream()
|
||||
.filter(recipe -> recipe.getTags().stream().anyMatch(tag -> tags.contains(tag.getName())))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@@ -4,6 +4,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.ImageDto;
|
||||
@@ -26,11 +29,13 @@ public class UserServiceImpl implements UserService {
|
||||
|
||||
private UserRepo userRepository;
|
||||
private RecipeRepo recipeRepository;
|
||||
private PasswordEncoder passwordEncoder;
|
||||
|
||||
public UserServiceImpl(UserRepo userRepository, RecipeRepo recipeRepository) {
|
||||
public UserServiceImpl(UserRepo userRepository, RecipeRepo recipeRepository, PasswordEncoder passwordEncoder) {
|
||||
super();
|
||||
this.userRepository = userRepository;
|
||||
this.recipeRepository = recipeRepository;
|
||||
this.passwordEncoder = passwordEncoder;
|
||||
}
|
||||
|
||||
public UserDto convertToDto(User user) {
|
||||
@@ -43,6 +48,9 @@ public class UserServiceImpl implements UserService {
|
||||
user.setRole("ROLE_USER");
|
||||
}
|
||||
user.setBanned(false);
|
||||
user.setHashedpassword(passwordEncoder.encode(user.getPassword()));
|
||||
|
||||
|
||||
return userRepository.save(user);
|
||||
}
|
||||
|
||||
|
||||
@@ -191,15 +191,18 @@ body, html {
|
||||
.main-content {
|
||||
width: 100%;
|
||||
flex-grow: 1;
|
||||
display: flex;
|
||||
/*display: flex; this line was breaking the searched results. They returned recipes would not load at the top of the page*/
|
||||
flex-direction: column;
|
||||
justify-content: flex-start;
|
||||
align-items: flex-start;
|
||||
overflow: scroll;
|
||||
overflow: auto;
|
||||
scrollbar-color: var(--dusty-red) var(--pale-yellow);
|
||||
height: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* safari and old browsers*/
|
||||
::-webkit-scrollbar-track {
|
||||
background: var(--pale-yellow);
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta charset="UTF-8">
|
||||
<meta name="_csrf_header" th:content="${_csrf.headerName}"/>
|
||||
<meta name="_csrf" th:content="${_csrf.token}"/>
|
||||
<title>Create Thyme Crunch Account</title>
|
||||
<link rel="stylesheet" th:href="@{css/create-account.css}">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Delius+Swash+Caps&family=Mali:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;1,200;1,300;1,400;1,500;1,600;1,700" rel="stylesheet">
|
||||
@@ -85,12 +88,17 @@
|
||||
hashedpassword: password,
|
||||
role: "USER"
|
||||
};
|
||||
const csrfToken = document.querySelector('meta[name="_csrf"]').getAttribute('content');
|
||||
const csrfHeader = document.querySelector('meta[name="_csrf_header"]').getAttribute('content');
|
||||
|
||||
console.log("JSON to submit:", JSON.stringify(userData, null, 2));
|
||||
|
||||
fetch("http://localhost:8080/api/users", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
[csrfHeader]: csrfToken,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(userData)
|
||||
});
|
||||
|
||||
|
||||
@@ -40,10 +40,10 @@
|
||||
<!-- Main Content -->
|
||||
<main class="main-content">
|
||||
<div class="search-bar">
|
||||
<form action="/search" method="get">
|
||||
<form action="/explore" method="get">
|
||||
<label for="site-search">Search:</label>
|
||||
<div class="search-btn">
|
||||
<input type="search" id="site-search" name="q" placeholder="Search for recipes...">
|
||||
<input type="search" id="site-search" name="q" th:value="${q}" placeholder="Search for recipes...">
|
||||
<button type="submit"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
</form>
|
||||
@@ -68,8 +68,29 @@
|
||||
<div class="body-right">
|
||||
<div class="sidebar-right">
|
||||
<h1> FILTER </h1>
|
||||
<form id="filter-form">
|
||||
<h3>Price</h3>
|
||||
|
||||
<label>
|
||||
<input type="checkbox" name="price" value="1"> $
|
||||
</label><br>
|
||||
|
||||
<label>
|
||||
<input type="checkbox" name="price" value="2"> $$
|
||||
</label><br>
|
||||
|
||||
<label>
|
||||
<input type="checkbox" name="price" value="3"> $$$
|
||||
</label><br>
|
||||
|
||||
<label>
|
||||
<input type="checkbox" name="price" value="4"> $$$$
|
||||
</label>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user