diff --git a/src/main/java/com/recipe/app/src/recipe/application/blog/BlogRecipeService.java b/src/main/java/com/recipe/app/src/recipe/application/blog/BlogRecipeService.java index 4789375f..2d74eb6e 100644 --- a/src/main/java/com/recipe/app/src/recipe/application/blog/BlogRecipeService.java +++ b/src/main/java/com/recipe/app/src/recipe/application/blog/BlogRecipeService.java @@ -1,6 +1,7 @@ package com.recipe.app.src.recipe.application.blog; import com.recipe.app.src.common.utils.BadWordFiltering; +import com.recipe.app.src.recipe.application.keyword.SearchKeywordService; import com.recipe.app.src.common.utils.SearchKeywordNormalizer; import com.recipe.app.src.common.utils.SearchKeywordNormalizer.SearchQuery; import com.recipe.app.src.recipe.application.dto.RecipesResponse; @@ -22,17 +23,20 @@ public class BlogRecipeService { private final BlogViewService blogViewService; private final BadWordFiltering badWordFiltering; private final BlogRecipeClientSearchService blogRecipeClientSearchService; + private final SearchKeywordService searchKeywordService; private static final int MIN_RECIPE_CNT = 10; public BlogRecipeService(BlogRecipeRepository blogRecipeRepository, BlogScrapService blogScrapService, BlogViewService blogViewService, - BadWordFiltering badWordFiltering, BlogRecipeClientSearchService blogRecipeClientSearchService) { + BadWordFiltering badWordFiltering, BlogRecipeClientSearchService blogRecipeClientSearchService, + SearchKeywordService searchKeywordService) { this.blogRecipeRepository = blogRecipeRepository; this.blogScrapService = blogScrapService; this.blogViewService = blogViewService; this.badWordFiltering = badWordFiltering; this.blogRecipeClientSearchService = blogRecipeClientSearchService; + this.searchKeywordService = searchKeywordService; } @Transactional @@ -54,6 +58,9 @@ public RecipesResponse findBlogRecipesByKeyword(User user, String keyword, long List blogRecipes = findByKeywordOrderBy(query, lastBlogRecipeId, size, sort); totalCnt = blogRecipeRepository.countByKeyword(query); + // 검색 로그 적재 (비동기·fire-and-forget). 욕설/빈 검색어는 위에서 이미 걸러진 상태. + searchKeywordService.record(keyword, user != null ? user.getUserId() : null); + return getRecipes(user, totalCnt, new BlogRecipes(blogRecipes)); } diff --git a/src/main/java/com/recipe/app/src/recipe/application/youtube/YoutubeRecipeService.java b/src/main/java/com/recipe/app/src/recipe/application/youtube/YoutubeRecipeService.java index 80fc7ddf..8a848e54 100644 --- a/src/main/java/com/recipe/app/src/recipe/application/youtube/YoutubeRecipeService.java +++ b/src/main/java/com/recipe/app/src/recipe/application/youtube/YoutubeRecipeService.java @@ -1,6 +1,7 @@ package com.recipe.app.src.recipe.application.youtube; import com.recipe.app.src.common.utils.BadWordFiltering; +import com.recipe.app.src.recipe.application.keyword.SearchKeywordService; import com.recipe.app.src.common.utils.SearchKeywordNormalizer; import com.recipe.app.src.common.utils.SearchKeywordNormalizer.SearchQuery; import com.recipe.app.src.recipe.application.dto.RecipesResponse; @@ -23,14 +24,17 @@ public class YoutubeRecipeService { private final YoutubeViewService youtubeViewService; private final BadWordFiltering badWordFiltering; private final YoutubeRecipeClientSearchService youtubeRecipeClientSearchService; + private final SearchKeywordService searchKeywordService; public YoutubeRecipeService(YoutubeRecipeRepository youtubeRecipeRepository, YoutubeScrapService youtubeScrapService, YoutubeViewService youtubeViewService, - BadWordFiltering badWordFiltering, YoutubeRecipeClientSearchService youtubeRecipeClientSearchService) { + BadWordFiltering badWordFiltering, YoutubeRecipeClientSearchService youtubeRecipeClientSearchService, + SearchKeywordService searchKeywordService) { this.youtubeRecipeRepository = youtubeRecipeRepository; this.youtubeScrapService = youtubeScrapService; this.youtubeViewService = youtubeViewService; this.badWordFiltering = badWordFiltering; this.youtubeRecipeClientSearchService = youtubeRecipeClientSearchService; + this.searchKeywordService = searchKeywordService; } @Transactional @@ -52,6 +56,9 @@ public RecipesResponse findYoutubeRecipesByKeyword(User user, String keyword, lo List youtubeRecipes = findByKeywordOrderBy(query, lastYoutubeRecipeId, size, sort); totalCnt = youtubeRecipeRepository.countByKeyword(query); + // 검색 로그 적재 (비동기·fire-and-forget). 욕설/빈 검색어는 위에서 이미 걸러진 상태. + searchKeywordService.record(keyword, user != null ? user.getUserId() : null); + return getRecipes(user, totalCnt, new YoutubeRecipes(youtubeRecipes)); } diff --git a/src/main/java/com/recipe/app/src/recipe/domain/blog/BlogRecipe.java b/src/main/java/com/recipe/app/src/recipe/domain/blog/BlogRecipe.java index fd6a46b3..31b13c89 100644 --- a/src/main/java/com/recipe/app/src/recipe/domain/blog/BlogRecipe.java +++ b/src/main/java/com/recipe/app/src/recipe/domain/blog/BlogRecipe.java @@ -37,16 +37,16 @@ public class BlogRecipe extends BaseEntity { @Column(name = "blogThumbnailImgUrl") private String blogThumbnailImgUrl; - @Column(name = "title", nullable = false, length = 128) + @Column(name = "title", nullable = false) private String title; - @Column(name = "description", nullable = false, length = 200) + @Column(name = "description", nullable = false) private String description; @Column(name = "publishedAt", nullable = false) private LocalDate publishedAt; - @Column(name = "blogName", nullable = false, length = 45) + @Column(name = "blogName", nullable = false) private String blogName; @Column(name = "scrapCnt", nullable = false) diff --git a/src/main/java/com/recipe/app/src/recipe/domain/youtube/YoutubeRecipe.java b/src/main/java/com/recipe/app/src/recipe/domain/youtube/YoutubeRecipe.java index bece1f8e..3a5a7078 100644 --- a/src/main/java/com/recipe/app/src/recipe/domain/youtube/YoutubeRecipe.java +++ b/src/main/java/com/recipe/app/src/recipe/domain/youtube/YoutubeRecipe.java @@ -31,10 +31,10 @@ public class YoutubeRecipe extends BaseEntity { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long youtubeRecipeId; - @Column(name = "title", nullable = false, length = 128) + @Column(name = "title", nullable = false) private String title; - @Column(name = "description", length = 200) + @Column(name = "description") private String description; @Column(name = "thumbnailImgUrl", nullable = false) diff --git a/src/test/groovy/com/recipe/app/src/recipe/application/blog/BlogRecipeServiceTest.groovy b/src/test/groovy/com/recipe/app/src/recipe/application/blog/BlogRecipeServiceTest.groovy index 89b1d161..ca55d790 100644 --- a/src/test/groovy/com/recipe/app/src/recipe/application/blog/BlogRecipeServiceTest.groovy +++ b/src/test/groovy/com/recipe/app/src/recipe/application/blog/BlogRecipeServiceTest.groovy @@ -2,6 +2,7 @@ package com.recipe.app.src.recipe.application.blog import com.recipe.app.src.common.utils.BadWordFiltering import com.recipe.app.src.recipe.application.dto.RecipesResponse +import com.recipe.app.src.recipe.application.keyword.SearchKeywordService import com.recipe.app.src.recipe.domain.blog.BlogRecipe import com.recipe.app.src.recipe.domain.blog.BlogScrap import com.recipe.app.src.recipe.infra.blog.BlogRecipeRepository @@ -18,7 +19,8 @@ class BlogRecipeServiceTest extends Specification { private BlogViewService blogViewService = Mock() private BadWordFiltering badWordService = Mock() private BlogRecipeClientSearchService blogRecipeClientSearchService = Mock() - private BlogRecipeService blogRecipeService = new BlogRecipeService(blogRecipeRepository, blogScrapService, blogViewService, badWordService, blogRecipeClientSearchService) + private SearchKeywordService searchKeywordService = Mock() + private BlogRecipeService blogRecipeService = new BlogRecipeService(blogRecipeRepository, blogScrapService, blogViewService, badWordService, blogRecipeClientSearchService, searchKeywordService) def "블로그 레시피 검색 - 스크랩순"() { diff --git a/src/test/groovy/com/recipe/app/src/recipe/application/youtube/YoutubeRecipeServiceTest.groovy b/src/test/groovy/com/recipe/app/src/recipe/application/youtube/YoutubeRecipeServiceTest.groovy index c4f397d0..bccbcb4c 100644 --- a/src/test/groovy/com/recipe/app/src/recipe/application/youtube/YoutubeRecipeServiceTest.groovy +++ b/src/test/groovy/com/recipe/app/src/recipe/application/youtube/YoutubeRecipeServiceTest.groovy @@ -2,6 +2,7 @@ package com.recipe.app.src.recipe.application.youtube import com.recipe.app.src.common.utils.BadWordFiltering import com.recipe.app.src.recipe.application.dto.RecipesResponse +import com.recipe.app.src.recipe.application.keyword.SearchKeywordService import com.recipe.app.src.recipe.domain.youtube.YoutubeRecipe import com.recipe.app.src.recipe.domain.youtube.YoutubeScrap import com.recipe.app.src.recipe.infra.youtube.YoutubeRecipeRepository @@ -18,8 +19,9 @@ class YoutubeRecipeServiceTest extends Specification { private YoutubeViewService youtubeViewService = Mock() private BadWordFiltering badWordService = Mock() private YoutubeRecipeClientSearchService youtubeRecipeClientSearchService = Mock() + private SearchKeywordService searchKeywordService = Mock() private YoutubeRecipeService youtubeRecipeService = new YoutubeRecipeService(youtubeRecipeRepository, youtubeScrapService, - youtubeViewService, badWordService, youtubeRecipeClientSearchService) + youtubeViewService, badWordService, youtubeRecipeClientSearchService, searchKeywordService) def "유튜브 레시피 검색 - 스크랩순"() {