Skip to content

Commit

Permalink
✨ Issue/282 테스트용 uri 추가
Browse files Browse the repository at this point in the history
controller, service, converter, repository까지 작업 완
  • Loading branch information
Hanvp committed Jan 10, 2024
1 parent 61c1fde commit f0b269e
Show file tree
Hide file tree
Showing 20 changed files with 900 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/main/java/zipdabang/server/aws/s3/AmazonS3Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ public String generateStepKeyName(Uuid uuid) {
return amazonConfig.getRecipeStep() + '/' + uuid.getUuid();
}

public String generateTestThumbnailKeyName(Uuid uuid) {
return amazonConfig.getTestThumbnail() + '/' + uuid.getUuid();
}

public String generateTestStepKeyName(Uuid uuid) {
return amazonConfig.getTestStep() + '/' + uuid.getUuid();
}

public String generateInqueryKeyName(Uuid uuid) {return amazonConfig.getInquery() + '/' + uuid.getUuid();}

// 중복된 UUID가 있다면 중복이 없을때까지 재귀적으로 동작
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/zipdabang/server/config/AmazonConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public class AmazonConfig {
@Value("${cloud.aws.s3.folder.zipdabang-recipe-steps}")
private String recipeStep;

@Value("${cloud.aws.s3.folder.zipdabang-test-thumbnail}")
private String testThumbnail;

@Value("${cloud.aws.s3.folder.zipdabang-test-steps}")
private String testStep;

@Value("${cloud.aws.s3.folder.zipdabang-proifile}")
private String userProfile;

Expand Down
209 changes: 209 additions & 0 deletions src/main/java/zipdabang/server/converter/RecipeConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
Expand All @@ -12,6 +13,10 @@
import zipdabang.server.domain.etc.Uuid;
import zipdabang.server.domain.member.Member;
import zipdabang.server.domain.recipe.*;
import zipdabang.server.domain.test.TestIngredient;
import zipdabang.server.domain.test.TestRecipe;
import zipdabang.server.domain.test.TestRecipeCategoryMapping;
import zipdabang.server.domain.test.TestStep;
import zipdabang.server.service.RecipeService;
import zipdabang.server.utils.converter.TimeConverter;
import zipdabang.server.web.dto.requestDto.RecipeRequestDto;
Expand Down Expand Up @@ -693,4 +698,208 @@ public static ReportedComment toCommentReport(Report report, Comment comment, Me
.build();
}

/**
* 부하 테스트용
*/
// @Value("${cloud.aws.s3.user-default-image}")
// String userDefaultImage;

public static RecipeResponseDto.RecipeStatusDto toTestRecipeStatusDto(TestRecipe recipe) {
return RecipeResponseDto.RecipeStatusDto.builder()
.recipeId(recipe.getId())
.calledAt(staticTimeConverter.ConvertTime(recipe.getCreatedAt()))
.build();
}

public static String uploadTestThumbnail(MultipartFile thumbnail) throws IOException {
Uuid uuid = staticAmazonS3Manager.createUUID();
String keyName = staticAmazonS3Manager.generateTestThumbnailKeyName(uuid);
String fileUrl = staticAmazonS3Manager.uploadFile(keyName, thumbnail);
log.info("S3에 업로드 한 test thumbnail 파일의 url : {}", fileUrl);
return fileUrl;
}

public static String uploadTestStep(MultipartFile thumbnail) throws IOException {
Uuid uuid = staticAmazonS3Manager.createUUID();
String keyName = staticAmazonS3Manager.generateTestStepKeyName(uuid);
String fileUrl = staticAmazonS3Manager.uploadFile(keyName, thumbnail);
log.info("S3에 업로드 한 test thumbnail 파일의 url : {}", fileUrl);
return fileUrl;
}

public static TestRecipe toTestRecipe(RecipeRequestDto.CreateRecipeDto request, MultipartFile thumbnail) throws IOException {

TestRecipe recipe = TestRecipe.builder()
.isBarista(false)
.name(request.getName())
.intro(request.getIntro())
.recipeTip(request.getRecipeTip())
.time(request.getTime())
.build();

String imageUrl = null;
if(thumbnail != null)
imageUrl = uploadTestThumbnail(thumbnail);
else
throw new RecipeException(CommonStatus.NULL_RECIPE_ERROR);
recipe.setThumbnail(imageUrl);

return recipe;
}

public static List<TestRecipeCategoryMapping> toTestRecipeCategory(List<Long> categoryIds, TestRecipe recipe) {
return categoryIds.stream()
.map(recipeCategoryId -> toTestRecipeCategoryMappingDto(recipeCategoryId, recipe))
.collect(Collectors.toList());
}

private static TestRecipeCategoryMapping toTestRecipeCategoryMappingDto(Long categoryId, TestRecipe recipe) {
return TestRecipeCategoryMapping.builder()
.category(staticRecipeService.getRecipeCategory(categoryId))
.recipe(recipe)
.build();
}

public static List<TestStep> toTestStep(RecipeRequestDto.CreateRecipeDto request, TestRecipe recipe, List<MultipartFile> stepImages) {
return request.getSteps().stream()
.map(step-> {
if (step.getDescription() == null)
throw new RecipeException(CommonStatus.NULL_RECIPE_ERROR);
try {
return toTestStepDto(step, recipe, stepImages);
} catch (IOException e) {
throw new RuntimeException(e);
}
})
.collect(Collectors.toList());
}

private static TestStep toTestStepDto(RecipeRequestDto.StepDto step, TestRecipe recipe, List<MultipartFile> stepImages) throws IOException {
TestStep createdStep = TestStep.builder()
.stepNum(step.getStepNum())
.description(step.getDescription())
.recipe(recipe)
.build();

MultipartFile stepImage = null;

for (int i = 0; i < stepImages.size(); i++) {
Integer imageNum = Integer.parseInt(stepImages.get(i).getOriginalFilename().substring(0,1)) + 1;
if (imageNum == step.getStepNum()){
stepImage = stepImages.get(i);
break;
}
}

String imageUrl = null;
if(stepImages != null)
imageUrl = uploadTestStep(stepImage);
else
throw new RecipeException(CommonStatus.NULL_RECIPE_ERROR);
createdStep.setImage(imageUrl);

return createdStep;
}

public static List<TestIngredient> toTestIngredient(RecipeRequestDto.CreateRecipeDto request, TestRecipe recipe) {
return request.getIngredients().stream()
.map(ingredient -> toTestIngredientDto(ingredient, recipe))
.collect(Collectors.toList());
}

private static TestIngredient toTestIngredientDto(RecipeRequestDto.NewIngredientDto ingredient, TestRecipe recipe) {
return TestIngredient.builder()
.name(ingredient.getIngredientName())
.quantity(ingredient.getQuantity())
.recipe(recipe)
.build();
}

public static RecipeResponseDto.RecipeInfoDto toTestRecipeInfoDto(TestRecipe recipe) {
return RecipeResponseDto.RecipeInfoDto.builder()
.recipeInfo(toResponseTestRecipeDto(recipe))
.ownerId(0L)
.isOwner(false)
.steps(toResponseTestStepDto(recipe))
.ingredients(toResponseTestIngredientDto(recipe))
.build();
}

public static RecipeResponseDto.RecipeDto toResponseTestRecipeDto(TestRecipe recipe){

return RecipeResponseDto.RecipeDto.builder()
.recipeId(recipe.getId())
.categoryId(getTestCategoryIds(recipe))
.recipeName(recipe.getName())
.ownerImage("")
.nickname("test")
.thumbnailUrl(recipe.getThumbnailUrl())
.time(recipe.getTime())
.intro(recipe.getIntro())
.recipeTip(recipe.getRecipeTip())
.createdAt(staticTimeConverter.ConvertTime(recipe.getCreatedAt()))
.updatedAt(staticTimeConverter.ConvertTime(recipe.getUpdatedAt()))
.likes(recipe.getTotalLike())
.comments(0L)
.scraps(recipe.getTotalScrap())
.isLiked(false)
.isScrapped(false)
.build();
}

public static List<Long> getTestCategoryIds(TestRecipe recipe){
return recipe.getCategoryMappingList().stream()
.map(categoryMapping -> categoryMapping.getCategory().getId())
.collect(Collectors.toList());
}

public static List<RecipeResponseDto.StepDto> toResponseTestStepDto(TestRecipe recipe) {

return recipe.getStepList().stream()
.map(step-> RecipeResponseDto.StepDto.builder()
.stepNum(step.getStepNum())
.description(step.getDescription())
.image(step.getImageUrl())
.build())
.collect(Collectors.toList());
}

public static List<RecipeResponseDto.IngredientDto> toResponseTestIngredientDto(TestRecipe recipe) {
return recipe.getIngredientList().stream()
.map(ingredient -> RecipeResponseDto.IngredientDto.builder()
.IngredientName(ingredient.getName())
.quantity(ingredient.getQuantity())
.build())
.collect(Collectors.toList());
}

public static RecipeResponseDto.RecipePageListDto toPagingTestRecipeDtoList(Page<TestRecipe> recipes) {
return RecipeResponseDto.RecipePageListDto.builder()
.recipeList(recipes.toList().stream()
.map(recipe -> toResponseTestRecipeSimpleDto(recipe))
.collect(Collectors.toList()))
.totalElements(recipes.getTotalElements())
.currentPageElements(recipes.getNumberOfElements())
.totalPage(recipes.getTotalPages())
.isFirst(recipes.isFirst())
.isLast(recipes.isLast())
.build();
}

private static RecipeResponseDto.RecipeSimpleDto toResponseTestRecipeSimpleDto(TestRecipe recipe) {
return RecipeResponseDto.RecipeSimpleDto.builder()
.recipeId(recipe.getId())
.categoryId(getTestCategoryIds(recipe))
.recipeName(recipe.getName())
.nickname("test")
.thumbnailUrl(recipe.getThumbnailUrl())
.createdAt(staticTimeConverter.ConvertTime(recipe.getCreatedAt()))
.updatedAt(staticTimeConverter.ConvertTime(recipe.getUpdatedAt()))
.comments(0L)
.likes(recipe.getTotalLike())
.scraps(recipe.getTotalScrap())
.isLiked(false)
.isScrapped(false)
.build();
}
}
39 changes: 39 additions & 0 deletions src/main/java/zipdabang/server/domain/test/TestComment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package zipdabang.server.domain.test;

import lombok.*;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import zipdabang.server.domain.common.BaseEntity;
import zipdabang.server.domain.member.Member;

import javax.persistence.*;

@Entity
@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@DynamicInsert
@DynamicUpdate
public class TestComment extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long id;

@Column(columnDefinition = "TEXT", nullable = false)
private String content;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id", nullable = false)
private Member member;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "recipe_id", nullable = false)
private TestRecipe recipe;

public TestComment updateContent(String content) {
this.content = content;
return this;
}
}
42 changes: 42 additions & 0 deletions src/main/java/zipdabang/server/domain/test/TestIngredient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package zipdabang.server.domain.test;

import lombok.*;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import zipdabang.server.domain.common.BaseEntity;
import zipdabang.server.domain.recipe.Recipe;

import javax.persistence.*;

@Entity
@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@DynamicInsert
@DynamicUpdate
public class TestIngredient extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long id;

@Column(nullable = false)
private String name;

@Column(length = 100, nullable = false)
private String quantity;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "recipe_id", nullable = false)
private TestRecipe recipe;

public TestIngredient setRecipe(TestRecipe recipe){
if(this.recipe != null)
recipe.getIngredientList().remove(this);
this.recipe = recipe;
recipe.getIngredientList().add(this);

return this;
}
}
50 changes: 50 additions & 0 deletions src/main/java/zipdabang/server/domain/test/TestLikes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package zipdabang.server.domain.test;

import lombok.*;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import zipdabang.server.domain.common.BaseEntity;
import zipdabang.server.domain.member.Member;

import javax.persistence.*;

@Entity
@Getter
@Builder
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@DynamicInsert
@DynamicUpdate
public class TestLikes extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(nullable = false)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id", nullable = false)
private Member member;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "recipe_id", nullable = false)
private TestRecipe recipe;

public TestLikes deleteLikes(TestRecipe recipe){
if(this.recipe != null)
recipe.getLikesList().remove(this);
recipe.updateLike(-1);
return this;
}

public TestLikes setRecipe(TestRecipe recipe){

recipe.updateLike(1);

if(this.recipe != null)
recipe.getLikesList().remove(this);
this.recipe = recipe;
recipe.getLikesList().add(this);

return this;
}
}
Loading

0 comments on commit f0b269e

Please sign in to comment.