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