Skip to content

Commit

Permalink
โ™ป๏ธ generate image URL
Browse files Browse the repository at this point in the history
  • Loading branch information
oshyun00 committed Aug 3, 2024
1 parent 6cd508f commit deec182
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
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)
@Sql(value = "/data/recipe.sql")
class RecipeServiceTest {

Expand Down

0 comments on commit deec182

Please sign in to comment.