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

✨ implement recipe and recipe steps creation #143

Merged
merged 16 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.pengcook.category.dto.RecipeOfCategoryRequest;
import net.pengcook.category.repository.CategoryRecipeRepository;
import net.pengcook.category.service.CategoryService;
import net.pengcook.image.service.S3ClientService;
import net.pengcook.ingredient.service.IngredientService;
import net.pengcook.recipe.domain.Recipe;
import net.pengcook.recipe.domain.RecipeStep;
Expand Down Expand Up @@ -44,6 +45,7 @@ public class RecipeService {

private final CategoryService categoryService;
private final IngredientService ingredientService;
private final S3ClientService s3ClientService;

public List<MainRecipeResponse> readRecipes(int pageNumber, int pageSize) {
Pageable pageable = PageRequest.of(pageNumber, pageSize);
Expand All @@ -55,11 +57,12 @@ public List<MainRecipeResponse> readRecipes(int pageNumber, int pageSize) {

public RecipeResponse createRecipe(UserInfo userInfo, RecipeRequest recipeRequest) {
User author = userRepository.findById(userInfo.getId()).orElseThrow();
String thumbnailUrl = s3ClientService.getImageUrl(recipeRequest.thumbnail()).url();
Recipe recipe = new Recipe(
recipeRequest.title(),
author,
LocalTime.parse(recipeRequest.cookingTime()),
recipeRequest.thumbnail(),
thumbnailUrl,
recipeRequest.difficulty(),
recipeRequest.description()
);
Expand All @@ -86,10 +89,10 @@ public RecipeStepResponse readRecipeStep(long recipeId, long sequence) {
public RecipeStepResponse createRecipeStep(long recipeId, RecipeStepRequest recipeStepRequest) {
Recipe recipe = recipeRepository.findById(recipeId)
.orElseThrow(() -> new NotFoundException("해당되는 레시피가 없습니다."));

String imageUrl = s3ClientService.getImageUrl(recipeStepRequest.image()).url();
RecipeStep recipeStep = new RecipeStep(
recipe,
recipeStepRequest.image(),
imageUrl,
recipeStepRequest.description(),
recipeStepRequest.sequence(),
LocalTime.parse(recipeStepRequest.cookingTime())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
import java.util.stream.Stream;
import net.pengcook.authentication.domain.UserInfo;
import net.pengcook.category.dto.RecipeOfCategoryRequest;
import net.pengcook.category.service.CategoryService;
import net.pengcook.ingredient.domain.Requirement;
import net.pengcook.ingredient.dto.IngredientCreateRequest;
import net.pengcook.ingredient.service.IngredientRecipeService;
import net.pengcook.ingredient.service.IngredientService;
import net.pengcook.ingredient.service.IngredientSubstitutionService;
import net.pengcook.recipe.dto.MainRecipeResponse;
import net.pengcook.recipe.dto.RecipeRequest;
import net.pengcook.recipe.dto.RecipeResponse;
Expand All @@ -26,13 +22,10 @@
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.MethodSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.context.annotation.Import;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.jdbc.Sql;

@DataJpaTest
@Import({RecipeService.class, CategoryService.class, IngredientService.class, IngredientRecipeService.class,
IngredientSubstitutionService.class})
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍👍

@Sql(value = "/data/recipe.sql")
class RecipeServiceTest {

Expand Down
Loading