-
Notifications
You must be signed in to change notification settings - Fork 5
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 #89 from microservices-course-itmo/add-recommendation
Add recommendation
- Loading branch information
Showing
9 changed files
with
68 additions
and
7 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
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
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
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
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/itmo/wineup/features/wine_info/WineInfoViewModel.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,32 @@ | ||
package com.itmo.wineup.features.wine_info | ||
|
||
import android.util.Log | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.itmo.wineup.features.catalog.domain.GetWineListUseCase | ||
import com.itmo.wineup.features.catalog.models.WineModel | ||
import com.itmo.wineup.network.retrofit.data.WinePositionConverter | ||
import com.itmo.wineup.network.retrofit.data.WineRecommendationResponse | ||
import kotlinx.coroutines.launch | ||
|
||
class WineInfoViewModel : ViewModel() { | ||
|
||
private val getWineListUseCase = GetWineListUseCase() | ||
|
||
val recommendationList = MutableLiveData<List<WineModel>>() | ||
|
||
fun getRecommendationList(id: String) { | ||
viewModelScope.launch { | ||
try{ | ||
val list = getWineListUseCase.getRecommendationList(id) | ||
recommendationList.value = WinePositionConverter.toWineModel(list.recommendations) | ||
} catch (e: Throwable){ | ||
Log.e("error", "error getting recommendations + ${e.message}") | ||
//todo show error screen | ||
} | ||
|
||
} | ||
} | ||
|
||
} |
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
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
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/itmo/wineup/network/retrofit/data/WineRecommendationResponse.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.itmo.wineup.network.retrofit.data | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class WineRecommendationResponse ( | ||
|
||
@SerializedName("wine_position") | ||
val winePosition: WinePositionResponse, | ||
|
||
val recommendations: List<WinePositionResponse> | ||
|
||
) |
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