modified site controller and home.html so recipeDto's work and appear

This commit is contained in:
durn
2026-03-11 14:58:14 -06:00
parent 56f91e1e06
commit 0a593c0491
3 changed files with 17 additions and 2 deletions
@@ -1,15 +1,28 @@
package com.example.demo.controller; package com.example.demo.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import com.example.demo.service.RecipeService;
import com.example.demo.dto.RecipeDto;
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;
@Controller @Controller
public class SiteController { public class SiteController {
private final RecipeService recipeService;
public SiteController(RecipeService recipeService) {
this.recipeService = recipeService;
}
@GetMapping("/") @GetMapping("/")
public String viewHomePage(Model model) { public String viewHomePage(Model model) {
//model.addAttribute("allemplist", employeeServiceImpl.getAllEmployee()); //model.addAttribute("allemplist", employeeServiceImpl.getAllEmployee());
List<RecipeDto> recipes = recipeService.getAllRecipes();
model.addAttribute("recipes", recipes);
return "home"; return "home";
} }
@@ -76,6 +76,7 @@ public class RecipeServiceImpl implements RecipeService {
} }
@Override @Override
@Transactional
public RecipeDto saveRecipe(RecipeDto dto) { public RecipeDto saveRecipe(RecipeDto dto) {
User user = userRepository.findById(dto.getUserDto().getId()) User user = userRepository.findById(dto.getUserDto().getId())
+3 -2
View File
@@ -44,8 +44,9 @@
<p th:text="${recipe.description}"></p> <p th:text="${recipe.description}"></p>
</div> </div>
<div class="card-right"> <div class="card-right">
<img th:src="@{${recipe.imageUrl}}" alt="${recipe.imageAltText}"> <div th:each="img : ${recipe.images}">
<p th:text="${recipe.cost}"></p> <img th:src="${img.imageUrl}" alt="Recipe Image"/>
</div>
</div> </div>
</div> </div>
</div> </div>