Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#26 add mongosearch #28

Merged
merged 1 commit into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kvsinyuk.elasticsearch.adapter.`in`.http

import com.kvsinyuk.elasticsearch.application.port.SearchDealsUseCase
import com.kvsinyuk.elasticsearch.application.port.SearchDealsUseCase.SearchCommand
import com.kvsinyuk.elasticsearch.domain.Deal
import mu.KLogging
import org.springframework.data.domain.Page
Expand All @@ -14,12 +15,14 @@ class DealController(
private val searchDealsUseCase: SearchDealsUseCase,
) {
@GetMapping("/deals")
fun generateRandomData(
fun getDeals(
@RequestParam search: String,
@RequestParam database: String = "elasticsearch",
pageable: Pageable,
): Page<Deal> {
logger.info { "Received request for search deals with $search" }
return searchDealsUseCase.searchDeals(search, pageable)
val command = SearchCommand(search, database, pageable)
return searchDealsUseCase.searchDeals(command)
}

companion object : KLogging()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package com.kvsinyuk.elasticsearch.application.impl

import com.kvsinyuk.elasticsearch.adapter.out.elasticsearch.ElasticDealRepository
import com.kvsinyuk.elasticsearch.adapter.out.mongo.MongoDealRepository
import com.kvsinyuk.elasticsearch.application.port.SearchDealsUseCase
import org.springframework.data.domain.Pageable
import com.kvsinyuk.elasticsearch.application.port.SearchDealsUseCase.SearchCommand
import org.springframework.stereotype.Component

@Component
class SearchDealsUseCaseImpl(
private val dealRepository: ElasticDealRepository,
private val elasticDealRepository: ElasticDealRepository,
private val mongoDealRepository: MongoDealRepository,
) : SearchDealsUseCase {
override fun searchDeals(
search: String,
page: Pageable,
) = dealRepository.searchAll(search, page)
override fun searchDeals(command: SearchCommand) =
when (command.databaseType) {
"elasticsearch" -> elasticDealRepository.searchAll(command.search, command.page)
else -> mongoDealRepository.findAll(command.page)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable

interface SearchDealsUseCase {
fun searchDeals(
search: String,
page: Pageable,
): Page<Deal>
fun searchDeals(command: SearchCommand): Page<Deal>

data class SearchCommand(
val search: String,
val databaseType: String,
val page: Pageable,
)
}
Loading