Complete the code to declare a repository interface in Kotlin.
interface UserRepository {
fun getUserById(id: Int): [1]
}The repository interface defines a method that returns a User object by its ID.
Complete the code to implement the repository class that fetches data from a local data source.
class UserRepositoryImpl(private val localDataSource: LocalDataSource) : UserRepository { override fun getUserById(id: Int): User { return [1].getUser(id) } }
The repository implementation uses the localDataSource to get the user data.
Fix the error in the repository method to return a nullable User when not found.
override fun getUserById(id: Int): [1] { return localDataSource.getUser(id) }
The method should return User? to indicate the user might not be found (nullable).
Fill both blanks to create a repository method that saves a user and returns success status.
fun saveUser(user: User): [1] { val result = localDataSource.[2](user) return result > 0 }
The method returns a Boolean indicating success. It calls insertUser on the local data source.
Fill all three blanks to define a repository method that fetches users filtered by age greater than a value.
fun getUsersOlderThan(age: Int): List<User> {
return localDataSource.getUsers().filter { user -> user.[1] [2] [3] }
}The filter checks if the user's age is greater than the given age parameter.