This commit is contained in:
2023-11-26 22:53:05 +03:00
parent 964636333b
commit 812ceec09c
4 changed files with 7 additions and 8 deletions
@@ -7,7 +7,6 @@ class ApiUtils {
companion object { companion object {
private const val BASE_URL = "https://my-json-server.typicode.com/YarikHumster/SweetShopViki/" private const val BASE_URL = "https://my-json-server.typicode.com/YarikHumster/SweetShopViki/"
fun getInterfaceDAO(): DAOInterface { fun getInterfaceDAO(): DAOInterface {
return RetrofitClient.getClient(BASE_URL).create(DAOInterface::class.java) return RetrofitClient.getClient(BASE_URL).create(DAOInterface::class.java)
} }
@@ -5,9 +5,9 @@ import com.google.gson.annotations.SerializedName
import java.io.Serializable import java.io.Serializable
data class Product( data class Product(
@SerializedName("categoryId") @Expose var categoryId: Int,
@SerializedName("Name") @Expose var name: String?, @SerializedName("Name") @Expose var name: String?,
@SerializedName("ImagePath") @Expose var imagePath: String?, @SerializedName("ImagePath") @Expose var imagePath: String?,
@SerializedName("Price") @Expose var price: Double?, @SerializedName("Price") @Expose var price: Double?,
@SerializedName("MenuItemId") @Expose var menuItemId: Int, @SerializedName("MenuItemId") @Expose var menuItemId: Int
@SerializedName("categoryId") @Expose var categoryId: Int
): Serializable ): Serializable
@@ -32,6 +32,7 @@ class Repository(context: Context) {
try { try {
isLoading.value = LOADING.LOADING isLoading.value = LOADING.LOADING
val response = dif.getCategories() val response = dif.getCategories()
Log.d("CATEGORY", response.toString())
if (response.isSuccessful) { if (response.isSuccessful) {
val tempList = response.body() val tempList = response.body()
categoriesList.value = tempList!! categoriesList.value = tempList!!
@@ -50,6 +51,7 @@ class Repository(context: Context) {
try { try {
isLoading.value = LOADING.LOADING isLoading.value = LOADING.LOADING
val response = dif.getProducts(categoryId) val response = dif.getProducts(categoryId)
Log.d("PRODUCT", response.toString())
if (response.isSuccessful) { if (response.isSuccessful) {
val tempList = response.body() val tempList = response.body()
productList.value = tempList!! productList.value = tempList!!
@@ -58,7 +60,7 @@ class Repository(context: Context) {
isLoading.value = LOADING.ERROR isLoading.value = LOADING.ERROR
} }
} catch (t: Throwable) { } catch (t: Throwable) {
t.localizedMessage?.toString()?.let { Log.e("getCategories", it) } t.localizedMessage?.toString()?.let { Log.e("getProducts", it) }
isLoading.value = LOADING.ERROR isLoading.value = LOADING.ERROR
} }
@@ -77,7 +79,7 @@ class Repository(context: Context) {
} }
} catch (t: Throwable) { } catch (t: Throwable) {
t.localizedMessage?.toString()?.let { Log.e("getCategories", it) } t.localizedMessage?.toString()?.let { Log.e("getSearch", it) }
isLoading.value = LOADING.ERROR isLoading.value = LOADING.ERROR
} }
@@ -11,11 +11,9 @@ interface DAOInterface {
suspend fun getCategories(): Response<List<Categories>> suspend fun getCategories(): Response<List<Categories>>
@GET("products") @GET("products/{categoryId}")
suspend fun getProducts(@Path("categoryId") categoryId: Int): Response<List<Product>> suspend fun getProducts(@Path("categoryId") categoryId: Int): Response<List<Product>>
@GET("search") @GET("search")
suspend fun getSearch(): Response<List<Product>> suspend fun getSearch(): Response<List<Product>>
} }