Skip to content

Commit

Permalink
feat: 레피시 리팩토링 - #104
Browse files Browse the repository at this point in the history
  • Loading branch information
jher235 authored Aug 5, 2024
2 parents 97365ee + 2d39a9c commit 2a96cf8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
public class DetailRecipeDto {
private UUID id;
private String name;
private String writer;
private List<IngredientRecipeResponseDto> ingredientRecipes;
private String cookingStep;
private int likeCount;
Expand All @@ -40,7 +41,7 @@ public class DetailRecipeDto {
public static DetailRecipeDto mapping(Recipe recipe, List<IngredientRecipe> ingredientRecipes){
List<IngredientRecipeResponseDto> ingredientDtos = ingredientRecipes.stream().map(
i->IngredientRecipeResponseDto.changeToDto(i)).collect(Collectors.toList());
return new DetailRecipeDto(recipe.getId(), recipe.getName(), ingredientDtos,
return new DetailRecipeDto(recipe.getId(), recipe.getName(), recipe.getUser().getName(), ingredientDtos,
recipe.getCookingStep(), recipe.getLikeCount(), ImageDto.mapping(recipe.getImage()),
recipe.getCreatedAt(), recipe.getUpdatedAt());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public class Recipe extends BaseEntity{
@Column(nullable = false)
private String name;

@Column(nullable = false)
@Lob
@Column(nullable = false, length = 5000)
private String cookingStep;

@ManyToOne(fetch = FetchType.LAZY, optional = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class RecipeServiceImpl implements RecipeService{
private final ImageRepository imageRepository;
private final RecipeLikeRepository recipeLikeRepository;

private static final List<String> IMAGE_EXTENSION = Arrays.asList(".jpg", ".jpeg", ".png", ".gif", ".webp", ".bmp", ".tiff", ".svg", ".heic");

@Override
@Cacheable(value = "recipeListCache",key = "#keyword + '-' + #type + '-' + #page + '-' + #size", cacheManager = "redisCacheManager")
public RecipeListDto getList(String keyword, String type, int page, int size) {
Expand Down Expand Up @@ -95,6 +97,12 @@ public void register(RegisterRecipeDto registerRecipeDto, User user) {
image = findImageByImageId(registerRecipeDto.getImageId());
}

//동일한 재료를 요청할 경우 예외처리
Set<UUID> ingredientIdSet = new HashSet<>(registerRecipeDto.getIngredientIds());
if(ingredientIdSet.size() != registerRecipeDto.getIngredientIds().size()){
throw new BadRequestException(ErrorCode.DUPLICATED_RECIPE_INGREDIENT);
}

Recipe recipe = Recipe.builder()
.name(registerRecipeDto.getName())
.cookingStep(registerRecipeDto.getCookingStep())
Expand All @@ -104,7 +112,7 @@ public void register(RegisterRecipeDto registerRecipeDto, User user) {

recipeRepository.save(recipe);

registerRecipeDto.getIngredientIds().stream().forEach(i -> registerRecipeIngredient(findIngredientByIngredientId(i),recipe));
ingredientIdSet.stream().forEach(i -> registerRecipeIngredient(findIngredientByIngredientId(i),recipe));
}

//상세조회
Expand Down Expand Up @@ -234,11 +242,10 @@ public RecipeListDto getRecommendation(int page, int size, int match, String typ
@Override
public ImageDto registerImage(MultipartFile file) {

if(!file.getContentType().equals(MediaType.IMAGE_GIF_VALUE) &&
!file.getContentType().equals(MediaType.IMAGE_PNG_VALUE) &&
!file.getContentType().equals(MediaType.IMAGE_JPEG_VALUE) ){
String fileName = file.getOriginalFilename();
if(!IMAGE_EXTENSION.stream().anyMatch(i-> fileName.endsWith(i))){
throw new FileStorageException(ErrorCode.FILE_TYPE_ERROR);
}
};

String url;
try {
Expand Down

0 comments on commit 2a96cf8

Please sign in to comment.