- Endpoint:
GET /users/{userId} - Description: Retrieve information about a specific user.
- Parameters:
userId(path parameter) - ID of the user to retrieve.
- Response:
This file contains hidden or 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
| @Composable | |
| fun <T> T.useDebounce( | |
| delayMillis: Long = 300L, | |
| // 1. couroutine scope | |
| coroutineScope: CoroutineScope = rememberCoroutineScope(), | |
| onChange: (T) -> Unit | |
| ): T{ | |
| // 2. updating state | |
| val state by rememberUpdatedState(this) | |
This file contains hidden or 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
| @Composable | |
| fun RestaurantSearchBar( | |
| modifier: Modifier = Modifier, | |
| hint: String = "Search", | |
| onSearch: (String) -> Unit = {} | |
| ) { | |
| // 1. text field state | |
| var text by remember { | |
| mutableStateOf("") | |
| } |
This file contains hidden or 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
| fun MutableList<Restaurant>.search( | |
| query: String | |
| ): MutableList<Restaurant>{ | |
| val result = mutableListOf<Restaurant>() | |
| this.forEach {restaurant -> | |
| if (restaurant.title.contains(query, ignoreCase = true) || restaurant.description.contains(query, ignoreCase = true)){ | |
| result.add(restaurant) | |
| } | |
| } | |
| return result |
This file contains hidden or 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
| class RestaurantsViewModel: ViewModel() { | |
| private val _restaurantsState by mutableStateOf( | |
| restaurants | |
| ) | |
| val restaurantsState = _restaurantsState | |
| fun toggleIsFavourite( | |
| rid: Int, | |
| ) { |
This file contains hidden or 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
| @Composable | |
| fun RestaurantScreen( | |
| modifier: Modifier = Modifier | |
| ){ | |
| val vm: RestaurantsViewModel = viewModel() | |
| var myRestaurants = vm.restaurantsState | |
This file contains hidden or 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
| class MainActivity : ComponentActivity() { | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| setContent { | |
| LearnTheme { | |
| Surface( | |
| modifier = Modifier.fillMaxSize(), | |
| color = MaterialTheme.colors.background | |
| ) { |
NewerOlder