-
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.
Merge pull request #71 from rees46/feat/dynamic-filter
feat: Adding filter guide
- Loading branch information
Showing
18 changed files
with
321 additions
and
20 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
17 changes: 17 additions & 0 deletions
17
personalization-sdk/src/main/kotlin/com/personalization/api/managers/ProductsManager.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,17 @@ | ||
package com.personalization.api.managers | ||
|
||
import com.personalization.api.OnApiCallbackListener | ||
|
||
interface ProductsManager { | ||
|
||
fun getProductsList( | ||
brands: String?, | ||
merchants: String?, | ||
categories: String?, | ||
locations: String?, | ||
limit: Int?, | ||
page: Int?, | ||
filters: Map<String, Any>?, | ||
listener: OnApiCallbackListener? = null | ||
) | ||
} |
12 changes: 12 additions & 0 deletions
12
...onalization-sdk/src/main/kotlin/com/personalization/api/responses/products/brand/Brand.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.personalization.api.responses.products.brand | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class Brand( | ||
@SerializedName("name") | ||
val name: String, | ||
@SerializedName("picture") | ||
val picture: String, | ||
@SerializedName("count") | ||
val count: Int | ||
) |
20 changes: 20 additions & 0 deletions
20
...ation-sdk/src/main/kotlin/com/personalization/api/responses/products/category/Category.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,20 @@ | ||
package com.personalization.api.responses.products.category | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class Category( | ||
@SerializedName("id") | ||
val id: String, | ||
@SerializedName("name") | ||
val name: String, | ||
@SerializedName("url") | ||
val url: String, | ||
@SerializedName("url_handle") | ||
val urlHandle: String, | ||
@SerializedName("count") | ||
val count: Int, | ||
@SerializedName("parent") | ||
val parent: String?, | ||
@SerializedName("alias") | ||
val alias: String? | ||
) |
8 changes: 8 additions & 0 deletions
8
...alization-sdk/src/main/kotlin/com/personalization/api/responses/products/filter/Filter.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,8 @@ | ||
package com.personalization.api.responses.products.filter | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class Filter( | ||
@SerializedName("filter") | ||
val filter: FilterDetails | ||
) |
14 changes: 14 additions & 0 deletions
14
...on-sdk/src/main/kotlin/com/personalization/api/responses/products/filter/FilterDetails.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.personalization.api.responses.products.filter | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class FilterDetails( | ||
@SerializedName("count") | ||
val count: Int, | ||
@SerializedName("priority") | ||
val priority: Int, | ||
@SerializedName("ranges") | ||
val ranges: List<Int>?, | ||
@SerializedName("values") | ||
val values: List<FilterValue> | ||
) |
10 changes: 10 additions & 0 deletions
10
...tion-sdk/src/main/kotlin/com/personalization/api/responses/products/filter/FilterValue.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.personalization.api.responses.products.filter | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class FilterValue( | ||
@SerializedName("value") | ||
val value: String, | ||
@SerializedName("count") | ||
val count: Int | ||
) |
5 changes: 5 additions & 0 deletions
5
...n-sdk/src/main/kotlin/com/personalization/api/responses/products/image/ImageUrlResized.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,5 @@ | ||
package com.personalization.api.responses.products.image | ||
|
||
data class ImageUrlResized( | ||
val sizeToPath: Map<String, String> | ||
) |
10 changes: 10 additions & 0 deletions
10
...zation-sdk/src/main/kotlin/com/personalization/api/responses/products/price/PriceRange.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.personalization.api.responses.products.price | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class PriceRange( | ||
@SerializedName("min") | ||
val min: Double, | ||
@SerializedName("max") | ||
val max: Double | ||
) |
10 changes: 10 additions & 0 deletions
10
...on-sdk/src/main/kotlin/com/personalization/api/responses/products/price/PriceRangeItem.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.personalization.api.responses.products.price | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class PriceRangeItem( | ||
@SerializedName("to") | ||
val to: Double, | ||
@SerializedName("count") | ||
val count: Int | ||
) |
55 changes: 55 additions & 0 deletions
55
...ization-sdk/src/main/kotlin/com/personalization/api/responses/products/product/Product.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,55 @@ | ||
package com.personalization.api.responses.products.product | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import com.personalization.api.responses.product.ImageUrlResized | ||
|
||
data class Product( | ||
@SerializedName("brand") | ||
val brand: String, | ||
@SerializedName("currency") | ||
val currency: String, | ||
@SerializedName("id") | ||
val id: String, | ||
@SerializedName("is_new") | ||
val isNew: Boolean? = null, | ||
@SerializedName("name") | ||
val name: String, | ||
@SerializedName("old_price") | ||
val oldPrice: String = "0", | ||
@SerializedName("price") | ||
val price: Double, | ||
@SerializedName("price_formatted") | ||
val priceFormatted: String, | ||
@SerializedName("price_full_formatted") | ||
val priceFullFormatted: String, | ||
@SerializedName("picture") | ||
val picture: String, | ||
@SerializedName("url") | ||
val url: String, | ||
@SerializedName("description") | ||
val description: String, | ||
@SerializedName("category_ids") | ||
val categoryIds: List<String>, | ||
@SerializedName("fashion_feature") | ||
val fashionFeature: String?, | ||
@SerializedName("fashion_gender") | ||
val fashionGender: String?, | ||
@SerializedName("sales_rate") | ||
val salesRate: Int, | ||
@SerializedName("relative_sales_rate") | ||
val relativeSalesRate: Double, | ||
@SerializedName("image_url") | ||
val imageUrl: String, | ||
@SerializedName("image_url_handle") | ||
val imageUrlHandle: String, | ||
@SerializedName("image_url_resized") | ||
val imageUrlResized: ImageUrlResized, | ||
@SerializedName("_id") | ||
val internalId: String, | ||
@SerializedName("group_id") | ||
val groupId: String, | ||
@SerializedName("barcode") | ||
val barcode: String, | ||
@SerializedName("categories") | ||
val categories: List<ProductCategory> | ||
) |
8 changes: 8 additions & 0 deletions
8
...sdk/src/main/kotlin/com/personalization/api/responses/products/product/ProductCategory.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,8 @@ | ||
package com.personalization.api.responses.products.product | ||
|
||
data class ProductCategory( | ||
val id: String, | ||
val name: String, | ||
val parent: String?, | ||
val params: List<ProductParam> | ||
) |
6 changes: 6 additions & 0 deletions
6
...on-sdk/src/main/kotlin/com/personalization/api/responses/products/product/ProductParam.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,6 @@ | ||
package com.personalization.api.responses.products.product | ||
|
||
data class ProductParam( | ||
val key: String, | ||
val values: List<String> | ||
) |
27 changes: 27 additions & 0 deletions
27
...dk/src/main/kotlin/com/personalization/api/responses/products/product/ProductsResponse.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,27 @@ | ||
package com.personalization.api.responses.products.product | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import com.personalization.api.responses.products.brand.Brand | ||
import com.personalization.api.responses.products.category.Category | ||
import com.personalization.api.responses.products.filter.Filter | ||
import com.personalization.api.responses.products.price.PriceRange | ||
import com.personalization.api.responses.products.price.PriceRangeItem | ||
|
||
data class ProductsResponse( | ||
@SerializedName("brands") | ||
val brands: List<Brand>, | ||
@SerializedName("categories") | ||
val categories: List<Category>, | ||
@SerializedName("filters") | ||
val filters: List<Filter>, | ||
@SerializedName("price_range") | ||
val priceRange: PriceRange, | ||
@SerializedName("products") | ||
val products: List<Product>, | ||
@SerializedName("products_total") | ||
val productsTotal: Int, | ||
@SerializedName("price_ranges") | ||
val priceRanges: List<PriceRangeItem>, | ||
@SerializedName("price_median") | ||
val priceMedian: Double | ||
) |
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
72 changes: 72 additions & 0 deletions
72
...ion-sdk/src/main/kotlin/com/personalization/features/products/impl/ProductsManagerImpl.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,72 @@ | ||
package com.personalization.features.products.impl | ||
|
||
import com.personalization.Params | ||
import com.personalization.api.OnApiCallbackListener | ||
import com.personalization.api.managers.ProductsManager | ||
import com.personalization.sdk.domain.usecases.network.SendNetworkMethodUseCase | ||
import javax.inject.Inject | ||
import org.json.JSONObject | ||
|
||
internal class ProductsManagerImpl @Inject constructor( | ||
private val sendNetworkMethodUseCase: SendNetworkMethodUseCase, | ||
) : ProductsManager { | ||
|
||
override fun getProductsList( | ||
brands: String?, | ||
merchants: String?, | ||
categories: String?, | ||
locations: String?, | ||
limit: Int?, | ||
page: Int?, | ||
filters: Map<String, Any>?, | ||
listener: OnApiCallbackListener? | ||
) { | ||
sendNetworkMethodUseCase.getAsync( | ||
method = GET_PRODUCT_LIST_REQUEST, | ||
params = Params().buildParams( | ||
brands = brands, | ||
merchants = merchants, | ||
categories = categories, | ||
locations = locations, | ||
limit = limit, | ||
page = page, | ||
filters = filters, | ||
).build(), | ||
listener = listener | ||
) | ||
} | ||
|
||
private fun Params.buildParams( | ||
brands: String?, | ||
merchants: String?, | ||
categories: String?, | ||
locations: String?, | ||
limit: Int?, | ||
page: Int?, | ||
filters: Map<String, Any>?, | ||
): Params = this.apply { | ||
limit?.let { put(LIMIT_KEY, it) } | ||
page?.let { put(PAGE_KEY, it) } | ||
locations?.let { put(LOCATION_KEY, it) } | ||
brands?.let { put(BRANDS_KEY, it) } | ||
merchants?.let { put(MERCHANTS_KEY, it) } | ||
categories?.let { put(CATEGORIES_KEY, it) } | ||
|
||
filters?.takeIf { it.isNotEmpty() }?.let { | ||
val filtersJson = JSONObject(it).toString() | ||
put(FILTERS_KEY, filtersJson) | ||
} | ||
} | ||
|
||
companion object { | ||
const val GET_PRODUCT_LIST_REQUEST = "products" | ||
|
||
private const val LIMIT_KEY = "limit" | ||
private const val PAGE_KEY = "page" | ||
private const val LOCATION_KEY = "locations" | ||
private const val BRANDS_KEY = "brands" | ||
private const val MERCHANTS_KEY = "merchants" | ||
private const val CATEGORIES_KEY = "categories" | ||
private const val FILTERS_KEY = "" | ||
} | ||
} |
Oops, something went wrong.