Skip to content

Commit

Permalink
feat: Added request with handling response
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielGreenEngineer committed Oct 31, 2024
1 parent 755baa4 commit 61346e7
Show file tree
Hide file tree
Showing 24 changed files with 219 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.personalization.Params.InternalParameter
import com.personalization.Params.TrackEvent
import com.personalization.api.OnApiCallbackListener
import com.personalization.api.managers.InAppNotificationManager
import com.personalization.api.managers.ProductsManager
import com.personalization.api.managers.RecommendationManager
import com.personalization.api.managers.SearchManager
import com.personalization.api.managers.TrackEventManager
Expand Down Expand Up @@ -53,6 +54,9 @@ open class SDK {
@Inject
lateinit var recommendationManager: RecommendationManager

@Inject
lateinit var productsManager: ProductsManager

@Inject
lateinit var trackEventManager: TrackEventManager

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.personalization.api.responses.products

import com.google.gson.annotations.SerializedName

data class Brand(
@SerializedName("name")
val name: String,
@SerializedName("picture")
val picture: String,
@SerializedName("count")
val count: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.personalization.api.responses.products

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?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.personalization.api.responses.products

import com.google.gson.annotations.SerializedName

data class Filter(
@SerializedName("filter")
val filter: FilterDetails
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.personalization.api.responses.products

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>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.personalization.api.responses.products

import com.google.gson.annotations.SerializedName

data class FilterValue(
@SerializedName("value")
val value: String,
@SerializedName("count")
val count: Int
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.personalization.sdk.domain.models.products
package com.personalization.api.responses.products

data class ImageUrlResized(
val sizeToPath: Map<String, String>
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.personalization.api.responses.products

import com.google.gson.annotations.SerializedName

data class PriceRange(
@SerializedName("min")
val min: Double,
@SerializedName("max")
val max: Double
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.personalization.api.responses.products

import com.google.gson.annotations.SerializedName

data class PriceRangeItem(
@SerializedName("to")
val to: Double,
@SerializedName("count")
val count: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.personalization.api.responses.products

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>
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.personalization.sdk.domain.models.products
package com.personalization.api.responses.products

data class ProductCategory(
val id: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.personalization.sdk.domain.models.products
package com.personalization.api.responses.products

data class ProductParam(
val key: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.personalization.api.responses.products

import com.google.gson.annotations.SerializedName

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
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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
private val sendNetworkMethodUseCase: SendNetworkMethodUseCase,
) : ProductsManager {

override fun getProductsList(
Expand All @@ -19,6 +21,52 @@ internal class ProductsManagerImpl @Inject constructor(
filters: Map<String, Any>?,
listener: OnApiCallbackListener?
) {
TODO("Not yet implemented")
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 = ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,4 @@ abstract class RepositoriesModule {
@Binds
abstract fun bindNotificationRepository(impl: NotificationRepositoryImpl): NotificationRepository

// @Binds
// abstract fun bindProductsRepository(impl: PreferencesRepositoryImpl): PreferencesRepository
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 61346e7

Please sign in to comment.