-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bbe2c1e
commit 659029c
Showing
13 changed files
with
113 additions
and
10 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions
24
src/main/kotlin/com/kvsinyuk/elasticsearch/adapter/in/http/DealController.kt
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,24 @@ | ||
package com.kvsinyuk.elasticsearch.adapter.`in`.http | ||
|
||
import com.kvsinyuk.elasticsearch.application.port.SearchDealsUseCase | ||
import com.kvsinyuk.elasticsearch.domain.Deal | ||
import mu.KLogging | ||
import org.springframework.data.domain.Page | ||
import org.springframework.data.domain.Pageable | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestParam | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
class DealController( | ||
private val searchDealsUseCase: SearchDealsUseCase | ||
) { | ||
|
||
@GetMapping("/deals") | ||
fun generateRandomData(@RequestParam search: String, pageable: Pageable): Page<Deal> { | ||
logger.info { "Received request for search deals with $search" } | ||
return searchDealsUseCase.searchDeals(search, pageable) | ||
} | ||
|
||
companion object: KLogging() | ||
} |
14 changes: 14 additions & 0 deletions
14
...main/kotlin/com/kvsinyuk/elasticsearch/adapter/out/elasticsearch/ElasticDealRepository.kt
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,14 @@ | ||
package com.kvsinyuk.elasticsearch.adapter.out.elasticsearch | ||
|
||
import com.kvsinyuk.elasticsearch.domain.Deal | ||
import org.springframework.data.domain.Page | ||
import org.springframework.data.domain.Pageable | ||
import org.springframework.data.elasticsearch.annotations.Query | ||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository | ||
|
||
interface ElasticDealRepository : ElasticsearchRepository<Deal, String> { | ||
|
||
@Query(query = "{ \"multi_match\" : {\"query\" : \"?0\" }}") | ||
//@Query(query = "\"query\": {\"bool\": {\"must\": [{ \"match\": {\"userId\": ?0}}]}}") | ||
fun searchAll(search: String, page: Pageable): Page<Deal> | ||
} |
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
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
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/com/kvsinyuk/elasticsearch/application/impl/SearchDealsUseCaseImpl.kt
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,15 @@ | ||
package com.kvsinyuk.elasticsearch.application.impl | ||
|
||
import com.kvsinyuk.elasticsearch.adapter.out.elasticsearch.ElasticDealRepository | ||
import com.kvsinyuk.elasticsearch.application.port.SearchDealsUseCase | ||
import org.springframework.data.domain.Pageable | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class SearchDealsUseCaseImpl( | ||
private val dealRepository: ElasticDealRepository | ||
): SearchDealsUseCase { | ||
|
||
override fun searchDeals(search: String, page: Pageable) = | ||
dealRepository.searchAll(search, page) | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/com/kvsinyuk/elasticsearch/application/port/SearchDealsUseCase.kt
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,10 @@ | ||
package com.kvsinyuk.elasticsearch.application.port | ||
|
||
import com.kvsinyuk.elasticsearch.domain.Deal | ||
import org.springframework.data.domain.Page | ||
import org.springframework.data.domain.Pageable | ||
|
||
interface SearchDealsUseCase { | ||
|
||
fun searchDeals(search: String, page: Pageable): Page<Deal> | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/com/kvsinyuk/elasticsearch/config/ElasticsearchConfiguration.kt
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,10 @@ | ||
package com.kvsinyuk.elasticsearch.config | ||
|
||
import org.springframework.context.annotation.ComponentScan | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories | ||
|
||
@Configuration | ||
@EnableElasticsearchRepositories(basePackages = ["com.kvsinyuk.elasticsearch.adapter.out.elasticsearch"]) | ||
@ComponentScan(basePackages = [ "com.kvsinyuk.elasticsearch" ]) | ||
class ElasticsearchConfiguration |
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/com/kvsinyuk/elasticsearch/config/MongoConfiguration.kt
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,12 @@ | ||
package com.kvsinyuk.elasticsearch.config | ||
|
||
import org.springframework.context.annotation.ComponentScan | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.data.mongodb.config.EnableMongoAuditing | ||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories | ||
|
||
@Configuration | ||
@EnableMongoAuditing | ||
@EnableMongoRepositories(basePackages = ["com.kvsinyuk.elasticsearch.adapter.out.mongo"]) | ||
@ComponentScan(basePackages = [ "com.kvsinyuk.elasticsearch" ]) | ||
class MongoConfiguration |
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
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
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