Skip to content

Commit

Permalink
Merge pull request #28 from kirillsinyuk/feature/26 #minor
Browse files Browse the repository at this point in the history
#26 add mongosearch
  • Loading branch information
kirillsinyuk authored Mar 24, 2024
2 parents d82aeb0 + 00b8dab commit 2215ce2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
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,
)
}

0 comments on commit 2215ce2

Please sign in to comment.