mirror of
https://gitlab.com/etc404/software-engineering-project.git
synced 2026-05-10 20:52:58 +00:00
view recipe, not working
This commit is contained in:
@@ -17,14 +17,14 @@ public class CorsConfig {
|
|||||||
CorsConfiguration config = new CorsConfiguration();
|
CorsConfiguration config = new CorsConfiguration();
|
||||||
|
|
||||||
// Allow your frontend origin (adjust if different)
|
// Allow your frontend origin (adjust if different)
|
||||||
config.setAllowedOrigins(List.of("http://localhost:3000",
|
config.setAllowedOrigins(List.of("http://localhost:8080/",
|
||||||
"http://localhost:5173"));
|
"http://localhost:5173"));
|
||||||
|
|
||||||
// Allow common HTTP methods
|
// Allow common HTTP methods
|
||||||
config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS"));
|
config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS"));
|
||||||
|
|
||||||
// Allow headers like Authorization (for JWT later)
|
// Allow headers like Authorization (for JWT later)
|
||||||
config.setAllowedHeaders(List.of("Authorization", "Content-Type"));
|
config.setAllowedHeaders(List.of("*"));
|
||||||
|
|
||||||
// Allow cookies if using sessions
|
// Allow cookies if using sessions
|
||||||
config.setAllowCredentials(true);
|
config.setAllowCredentials(true);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
|||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.security.web.SecurityFilterChain;
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
|
import org.springframework.security.web.csrf.CsrfAuthenticationStrategy;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class SecurityConfig {
|
public class SecurityConfig {
|
||||||
@@ -16,7 +17,7 @@ public class SecurityConfig {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
||||||
http
|
http .csrf(csrf->csrf.disable())
|
||||||
.authorizeHttpRequests(auth -> auth
|
.authorizeHttpRequests(auth -> auth
|
||||||
.requestMatchers("/login", "/register", "/css/**", "/images/**").permitAll()
|
.requestMatchers("/login", "/register", "/css/**", "/images/**").permitAll()
|
||||||
.anyRequest().authenticated()
|
.anyRequest().authenticated()
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import com.example.demo.entity.Recipe;
|
|||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class SiteController {
|
public class SiteController {
|
||||||
@@ -40,4 +41,20 @@ public class SiteController {
|
|||||||
public String viewCreatePage(Model model) {
|
public String viewCreatePage(Model model) {
|
||||||
return "create-recipe";
|
return "create-recipe";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/recipes/{id}")
|
||||||
|
public String viewRecipe(@PathVariable Integer id, Model model) {
|
||||||
|
RecipeDto recipe = recipeService.getRecipeById(id);
|
||||||
|
model.addAttribute("recipe", recipe);
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,275 @@
|
|||||||
|
/* =========================
|
||||||
|
Root Variables
|
||||||
|
========================= */
|
||||||
|
:root {
|
||||||
|
--dusty-red: #D43F3F;
|
||||||
|
--dusty-red-hover: #C73636;
|
||||||
|
--dark-yellow: #FFD27F;
|
||||||
|
--pale-yellow: #FFECB3;
|
||||||
|
--peach: #F5A96E;
|
||||||
|
--dark: #850000;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* =========================
|
||||||
|
Global Styles
|
||||||
|
========================= */
|
||||||
|
.delius {
|
||||||
|
font-family: 'Delius Swash Caps', cursive;
|
||||||
|
font-weight: 400;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
.mali-regular {
|
||||||
|
font-family: 'Mali', cursive;
|
||||||
|
font-weight: 400;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
body, html {
|
||||||
|
height: 100vh;
|
||||||
|
margin: 0;
|
||||||
|
font-family: 'Mali', cursive;
|
||||||
|
background-color: var(--pale-yellow);
|
||||||
|
overflow: clip;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* =========================
|
||||||
|
Layout Structure
|
||||||
|
========================= */
|
||||||
|
.body {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.body-left, .body-right {
|
||||||
|
position: sticky;
|
||||||
|
flex-grow: 0;
|
||||||
|
width: 400px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* =========================
|
||||||
|
Header Styles
|
||||||
|
========================= */
|
||||||
|
.top-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 40px;
|
||||||
|
height: 60px;
|
||||||
|
padding: 10px 20px;
|
||||||
|
background-color: var(--dusty-red);
|
||||||
|
color: var(--dark-yellow);
|
||||||
|
}
|
||||||
|
|
||||||
|
.top-header .swirl {
|
||||||
|
height: 40px;
|
||||||
|
width: auto;
|
||||||
|
margin: 0 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.site-name {
|
||||||
|
font-family: 'Delius Swash Caps', serif;
|
||||||
|
font-size: 2.5em;
|
||||||
|
font-weight: bold;
|
||||||
|
letter-spacing: 4px;
|
||||||
|
color: var(--dark-yellow);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* =========================
|
||||||
|
Left Sidebar
|
||||||
|
========================= */
|
||||||
|
.sidebar-left {
|
||||||
|
overflow: hidden;
|
||||||
|
margin: 25px;
|
||||||
|
border-radius: 20px;
|
||||||
|
z-index: 10;
|
||||||
|
background-color: var(--peach);
|
||||||
|
color: var(--dark);
|
||||||
|
padding: 6px;
|
||||||
|
font-size: 1.75em;
|
||||||
|
font-weight: 900;
|
||||||
|
letter-spacing: 1.5px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-left ul {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-left li {
|
||||||
|
margin-bottom: 7px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-left a {
|
||||||
|
color: var(--dark);
|
||||||
|
text-decoration: none;
|
||||||
|
transition: 0.1s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-left a:hover {
|
||||||
|
color: var(--dusty-red);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-left .nav_icon {
|
||||||
|
background: none;
|
||||||
|
border: none;
|
||||||
|
padding: 0;
|
||||||
|
cursor: pointer;
|
||||||
|
height: 100px;
|
||||||
|
width: auto;
|
||||||
|
border-radius: 8px;
|
||||||
|
transition: transform 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-left .nav_icon:hover {
|
||||||
|
transform: scale(1.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* =========================
|
||||||
|
Floating Create Icon
|
||||||
|
========================= */
|
||||||
|
.create_icon {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 30px;
|
||||||
|
left: 55px;
|
||||||
|
z-index: 1000;
|
||||||
|
transition: transform 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.create_icon:hover {
|
||||||
|
transform: scale(1.02);
|
||||||
|
}
|
||||||
|
|
||||||
|
.create_icon img {
|
||||||
|
width: 150px;
|
||||||
|
height: auto;
|
||||||
|
border-radius: 10%;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* =========================
|
||||||
|
Right Sidebar
|
||||||
|
========================= */
|
||||||
|
.sidebar-right {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
margin: 25px;
|
||||||
|
padding: 5px;
|
||||||
|
height: 75%;
|
||||||
|
border-radius: 20px;
|
||||||
|
z-index: 10;
|
||||||
|
background-color: var(--peach);
|
||||||
|
color: var(--dusty-red);
|
||||||
|
font-size: 1.6em;
|
||||||
|
font-weight: 900;
|
||||||
|
letter-spacing: 1.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-right ul {
|
||||||
|
list-style: none;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-right li {
|
||||||
|
margin-bottom: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-right a {
|
||||||
|
color: var(--dusty-red);
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* =========================
|
||||||
|
Main Content Area
|
||||||
|
========================= */
|
||||||
|
.main-content {
|
||||||
|
width: 100%;
|
||||||
|
flex-grow: 1;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: flex-start;
|
||||||
|
overflow: scroll;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* =========================
|
||||||
|
Recipe Cards Layout
|
||||||
|
========================= */
|
||||||
|
.recipe-card {
|
||||||
|
margin-top: 35px;
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 35px;
|
||||||
|
justify-content: flex-start;
|
||||||
|
flex-direction: row;
|
||||||
|
height: fit-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: var(--dark);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* =========================
|
||||||
|
Individual Card (Folder Style)
|
||||||
|
========================= */
|
||||||
|
.card {
|
||||||
|
position: relative; /* needed for tab */
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 10px;
|
||||||
|
flex: 1 1 260px;
|
||||||
|
max-width: 400px;
|
||||||
|
max-height: 200px;
|
||||||
|
padding: 25px 20px 20px; /* extra space for tab */
|
||||||
|
border-radius: 12px;
|
||||||
|
background: var(--peach);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Folder Tab */
|
||||||
|
.card::before {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
top: -16px;
|
||||||
|
left: 0px;
|
||||||
|
width: 100px;
|
||||||
|
height: 28px;
|
||||||
|
background: var(--peach);
|
||||||
|
border-radius: 6px 6px 0 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* =========================
|
||||||
|
Card Content
|
||||||
|
========================= */
|
||||||
|
.card .card-text {
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden; /* the scroll bars were difficult to look at, the user can just view the recipe*/
|
||||||
|
font-family: 'Roboto', sans-serif;
|
||||||
|
color: var(--dark);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* =========================
|
||||||
|
Card Image
|
||||||
|
========================= */
|
||||||
|
.card img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100px;
|
||||||
|
object-fit: cover;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* =========================
|
||||||
|
Card Columns
|
||||||
|
========================= */
|
||||||
|
.card-left,
|
||||||
|
.card-right {
|
||||||
|
flex-shrink: 0;
|
||||||
|
width: 50%;
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Thyme Crunch View Recipe</title>
|
||||||
|
<link rel="stylesheet" th:href="@{/css/view-recipe.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">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<header class="top-header">
|
||||||
|
<img th:src="@{images/header_left.png}" alt="Violin f-hole shape to the left of header." class="swirl">
|
||||||
|
<h1 class="site-name">Thyme Crunch</h1>
|
||||||
|
<img th:src="@{images/header_right.png}" alt="Violin f-hole shape to the right of header." class="swirl">
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="body">
|
||||||
|
<!--Navigation Bar -->
|
||||||
|
<div class="body-left">
|
||||||
|
<nav class="sidebar-left">
|
||||||
|
<ul>
|
||||||
|
<li><a href="#">Home</a></li>
|
||||||
|
<li><a href="#">Explore</a></li>
|
||||||
|
<li><a href="#">Profile</a></li>
|
||||||
|
<li><a href="#">Saved</a></li>
|
||||||
|
<li>
|
||||||
|
<form th:action="@{/logout}" method="post">
|
||||||
|
<input type="image" th:src="@{images/logout_icon.png}" alt="Logout button" class="nav_icon"/>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
<a th:href="@{/create}" target="_blank" class="create_icon">
|
||||||
|
<img th:src="@{images/create_icon.png}" alt="Description of the icon">
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Main Content -->
|
||||||
|
<main class="main-content">
|
||||||
|
<div class="form-wrap">
|
||||||
|
<h1 th:text="${recipe.title}"></h1>
|
||||||
|
<p th:text="${recipe.description}"></p>
|
||||||
|
|
||||||
|
<div class="form-section">
|
||||||
|
<div class="section-title">Ingredients</div>
|
||||||
|
<ul>
|
||||||
|
<li th:each="ingredient : ${recipe.ingredients}"
|
||||||
|
th:text="${ingredient.name}"></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-section">
|
||||||
|
<div class="section-title">Instructions</div>
|
||||||
|
<ol class="step-list">
|
||||||
|
<li th:each="step : ${#lists.sort(recipe.steps, comparingInt(step -> step.stepNumber))}">
|
||||||
|
</ol
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user