Skip to content

Commit

Permalink
Merge pull request #46 from InjeRecipe/#12-amazon-s3
Browse files Browse the repository at this point in the history
#12 amazon s3
  • Loading branch information
Gdm0714 committed Mar 27, 2024
2 parents 51779ca + 58fa6fa commit 800d628
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public String uploadImage(MultipartFile image, String fileName) throws IOExcepti

public String getImageUrlsWithKeyword(String keyword) {
List<String> imageUrls = new ArrayList<>();

String url = "";
ListObjectsV2Request request = new ListObjectsV2Request()
.withBucketName(bucketName)
.withPrefix(""); // 모든 객체를 검색하려면 prefix를 비워둡니다.
Expand All @@ -61,8 +61,11 @@ public String getImageUrlsWithKeyword(String keyword) {
}
request.setContinuationToken(result.getNextContinuationToken());
} while (result.isTruncated());
String imageUrl = imageUrls.get(0);
return imageUrl;
if(!imageUrls.isEmpty()) url = imageUrls.get(0);
else{
return null;
}
return url;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -111,18 +111,17 @@ public List<RecipeSearchResponse> searchRecipes(RecipeSearchRequest request) {
List<RecipeSearchResponse> searchResponses = new ArrayList<>();

List<String> keywords = request.getKeywords();
String url = amazonS3Service.getImageUrlsWithKeyword("default");
List<String> imageUrl = new ArrayList<>();

for (String keyword : keywords) {
if (keyword != null) {
List<RecipeBoard> recipes = recipeBoardRepository.findByRecipeNmContainingKeyword(keyword);
if (!recipes.isEmpty()) {
searchResponses.add(RecipeSearchResponse.from(recipes.get(0)));
} else {
imageUrl.add(url);

searchResponses.add(RecipeSearchResponse.builder()
.recipeNm(keyword)
.recipeImages(imageUrl)

.errorMessage("해당 레시피를 추가해주세요.")
.build());
}
Expand All @@ -136,18 +135,17 @@ public List<RecipeSearchResponse> searchRecipes(RecipeSearchRequest request) {
public List<RecipeSearchResponse> searchRecipe(RecipeSearchRequest request) {
List<RecipeBoard> recipeList = recipeBoardRepository.findByRecipeNmContainingKeyword(request.getKeywords().get(0));
List<RecipeSearchResponse> searchResponses = new ArrayList<>();
String url = amazonS3Service.getImageUrlsWithKeyword("default");
List<String> imageUrl = new ArrayList<>();

if(!searchResponses.isEmpty()) {
for (RecipeBoard recipe : recipeList) {
searchResponses.add(RecipeSearchResponse.from(recipe));
}
}
else{
imageUrl.add(url);

searchResponses.add(RecipeSearchResponse.builder()
.recipeNm(request.getKeywords().get(0))
.recipeImages(imageUrl)

.errorMessage("해당 레시피를 추가해주세요.")
.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,17 @@ public class RecipeService {
public List<RecipeSearchResponse> searchRecipes(RecipeSearchRequest request) {
List<RecipeSearchResponse> searchResponses = new ArrayList<>();
List<String> keywords = request.getKeywords();
String url = amazonS3Service.getImageUrlsWithKeyword("default");
List<String> imageUrl = new ArrayList<>();

for (String keyword : keywords) {
if (keyword != null) {
List<Recipe> recipes = recipeRepository.findByRecipeNmContainingKeyword(keyword);
System.out.println(recipes);
if (!recipes.isEmpty()) {
searchResponses.add(RecipeSearchResponse.from(recipes.get(0)));
} else {
imageUrl.add(url);

searchResponses.add(RecipeSearchResponse.builder()
.recipeNm(keyword)
.recipeImages(imageUrl)
.errorMessage("해당 레시피를 추가해주세요.")
.build());
}
Expand All @@ -73,17 +71,15 @@ public List<RecipeSearchResponse> searchRecipes(RecipeSearchRequest request) {
public List<RecipeSearchResponse> searchRecipe(RecipeSearchRequest request) {
List<Recipe> recipeList = recipeRepository.findByRecipeNmContainingKeyword(request.getKeywords().get(0));
List<RecipeSearchResponse> searchResponses = new ArrayList<>();
String url = amazonS3Service.getImageUrlsWithKeyword("default");
List<String> imageUrl = new ArrayList<>();

if(!searchResponses.isEmpty()) {
for (Recipe recipe : recipeList) {
searchResponses.add(RecipeSearchResponse.from(recipe));
}
}else{
imageUrl.add(url);

searchResponses.add(RecipeSearchResponse.builder()
.recipeNm(request.getKeywords().get(0))
.recipeImages(imageUrl)
.errorMessage("해당 레시피를 추가해주세요.")
.build());
}
Expand Down

0 comments on commit 800d628

Please sign in to comment.