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

Feat/exclude merchants from search #89

Merged
merged 3 commits into from
Dec 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
Expand Up @@ -33,6 +33,7 @@ interface SearchManager {
fun searchInstant(
query: String,
locations: String? = null,
excludedMerchants: List<String>? = null,
onSearchInstant: (SearchInstantResponse) -> Unit,
onError: (Int, String?) -> Unit = { _: Int, _: String? -> }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SearchParams : AbstractParams<SearchParams>() {
SORT_BY("sort_by"),
SORT_DIR("sort_dir"),
LOCATIONS("locations"),
EXCLUDED_MERCHANTS("excluded_merchants"),
BRANDS("brands"),
FILTERS("filters"),
PRICE_MIN("price_min"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ import com.personalization.api.responses.search.SearchBlankResponse
import com.personalization.api.responses.search.SearchFullResponse
import com.personalization.api.responses.search.SearchInstantResponse
import com.personalization.sdk.domain.usecases.network.SendNetworkMethodUseCase
import javax.inject.Inject
import org.json.JSONObject
import javax.inject.Inject

private const val SEARCH_REQUEST = "search"
private const val BLANK_SEARCH_REQUEST = "search/blank"
private const val TYPE_PARAMETER = "type"
private const val QUERY_PARAMETER = "search_query"

internal class SearchManagerImpl @Inject constructor(
private val sendNetworkMethodUseCase: SendNetworkMethodUseCase
Expand Down Expand Up @@ -40,12 +45,18 @@ internal class SearchManagerImpl @Inject constructor(
override fun searchInstant(
query: String,
locations: String?,
excludedMerchants: List<String>?,
onSearchInstant: (SearchInstantResponse) -> Unit,
onError: (Int, String?) -> Unit
) {
val searchParams = SearchParams()

if (locations != null) searchParams.put(LOCATIONS_PARAMETER, locations)
locations?.let {
searchParams.put(SearchParams.Parameter.LOCATIONS, locations)
excludedMerchants?.let {
val excludeMerchantsString = excludedMerchants.joinToString(",")
searchParams.put(SearchParams.Parameter.EXCLUDED_MERCHANTS, excludeMerchantsString)
}
}

search(query, TYPE.INSTANT, searchParams, object : OnApiCallbackListener() {
override fun onSuccess(response: JSONObject?) {
Expand Down Expand Up @@ -97,15 +108,6 @@ internal class SearchManagerImpl @Inject constructor(
sendNetworkMethodUseCase.get(SEARCH_REQUEST, params.build(), listener)
}

companion object {
private const val SEARCH_REQUEST = "search"
private const val BLANK_SEARCH_REQUEST = "search/blank"

private const val TYPE_PARAMETER = "type"
private const val QUERY_PARAMETER = "search_query"
private const val LOCATIONS_PARAMETER = "locations"
}

private enum class TYPE(var value: String) {
INSTANT("instant_search"),
FULL("full_search")
Expand Down
Loading