-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feature: 글 검색 api 구현 * feature: 글 검색 api 피드백 반영 * feature: 글 검색 api 피드백 2번째 반영
- Loading branch information
1 parent
3932a3c
commit e9bba3c
Showing
6 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
21 changes: 20 additions & 1 deletion
21
src/main/java/com/goldbalance/dive/domain/article/controller/ArticleController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,22 @@ | ||
package com.goldbalance.dive.domain.article.controller; | ||
|
||
public class ArticleController {} | ||
import com.goldbalance.dive.domain.article.domain.Article; | ||
import com.goldbalance.dive.domain.article.domain.ArticleQueryOption; | ||
import com.goldbalance.dive.domain.article.service.ArticleService; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/articles") | ||
@RequiredArgsConstructor | ||
public class ArticleController { | ||
private final ArticleService articleService; | ||
|
||
@GetMapping | ||
public ResponseEntity<List<Article>> findArticles(@RequestParam ArticleQueryOption queryOption) { | ||
List<Article> response = articleService.findArticles(queryOption); | ||
return ResponseEntity.ok(response); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/java/com/goldbalance/dive/domain/article/domain/ArticleQueryOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.goldbalance.dive.domain.article.domain; | ||
|
||
public record ArticleQueryOption(String keyword, Category category, Duration duration) {} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/goldbalance/dive/domain/article/repository/ArticleCustomRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.goldbalance.dive.domain.article.repository; | ||
|
||
import com.goldbalance.dive.domain.article.domain.Article; | ||
import com.goldbalance.dive.domain.article.domain.ArticleQueryOption; | ||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import java.util.List; | ||
|
||
public interface ArticleCustomRepository { | ||
|
||
List<Article> searchArticle(ArticleQueryOption queryOption); | ||
} |
28 changes: 28 additions & 0 deletions
28
...main/java/com/goldbalance/dive/domain/article/repository/ArticleCustomRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.goldbalance.dive.domain.article.repository; | ||
|
||
import static com.goldbalance.dive.domain.article.domain.QArticle.*; | ||
|
||
import com.goldbalance.dive.domain.article.domain.Article; | ||
import com.goldbalance.dive.domain.article.domain.ArticleQueryOption; | ||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class ArticleCustomRepositoryImpl implements ArticleCustomRepository { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public List<Article> searchArticle(ArticleQueryOption queryOption) { | ||
return queryFactory | ||
.selectFrom(article) | ||
.where(containsKeyword(queryOption)) | ||
.fetch(); | ||
} | ||
|
||
private BooleanExpression containsKeyword(ArticleQueryOption queryOption) { | ||
return queryOption.keyword() != null ? article.title.containsIgnoreCase(queryOption.keyword()) : null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 19 additions & 1 deletion
20
src/main/java/com/goldbalance/dive/domain/article/service/ArticleService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,21 @@ | ||
package com.goldbalance.dive.domain.article.service; | ||
|
||
public class ArticleService {} | ||
import com.goldbalance.dive.domain.article.domain.Article; | ||
import com.goldbalance.dive.domain.article.domain.ArticleQueryOption; | ||
import com.goldbalance.dive.domain.article.repository.ArticleRepository; | ||
import jakarta.transaction.Transactional; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class ArticleService { | ||
|
||
private final ArticleRepository articleRepository; | ||
|
||
public List<Article> findArticles(ArticleQueryOption queryOption) { | ||
return articleRepository.searchArticle(queryOption); | ||
} | ||
} |