|
|
|
@ -8,6 +8,7 @@ import java.util.stream.Collectors; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
|
import org.springframework.security.core.Authentication; |
|
|
|
|
import org.springframework.security.core.userdetails.UsernameNotFoundException; |
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
|
|
import org.springframework.web.bind.annotation.PutMapping; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
@ -18,6 +19,8 @@ import com.example.todoapp.dto.RecipeDetailDTO; |
|
|
|
|
import com.example.todoapp.dto.RecipeRequestDTO; |
|
|
|
|
import com.example.todoapp.dto.RecipeResponseDTO; |
|
|
|
|
import com.example.todoapp.model.Recipes; |
|
|
|
|
import com.example.todoapp.model.User; |
|
|
|
|
import com.example.todoapp.repository.UserRepository; |
|
|
|
|
import com.example.todoapp.service.RecipeService; |
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
@ -36,6 +39,9 @@ public class RecipesController { |
|
|
|
|
@Autowired |
|
|
|
|
private RecipeService recipeService; |
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
private UserRepository userRepository; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 新しいレシピを作成する |
|
|
|
|
* |
|
|
|
@ -62,7 +68,12 @@ public class RecipesController { |
|
|
|
|
*/ |
|
|
|
|
@GetMapping("/getAll") |
|
|
|
|
public ResponseEntity<List<RecipeResponseDTO>> getRecipe(Authentication authentication) { |
|
|
|
|
|
|
|
|
|
User user = userRepository.findByUsername(authentication.getName()) |
|
|
|
|
.orElseThrow(() -> new UsernameNotFoundException("User not found")); |
|
|
|
|
|
|
|
|
|
List<Recipes> recipes = recipeService.getAllRecipes(); |
|
|
|
|
|
|
|
|
|
// エンティティからDTOへの変換
|
|
|
|
|
List<RecipeResponseDTO> responseList = recipes.stream() |
|
|
|
|
.map(recipe -> { |
|
|
|
@ -70,6 +81,7 @@ public class RecipesController { |
|
|
|
|
dto.setRecipeId(recipe.getRecipeId()); |
|
|
|
|
dto.setRecipeName(recipe.getRecipeName()); |
|
|
|
|
dto.setSummary(recipe.getSummary()); |
|
|
|
|
dto.setMaxServings(recipeService.getRecipeMaxServings(user.getId(), recipe)); |
|
|
|
|
return dto; |
|
|
|
|
}) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|