mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-17 23:47:02 +05:30
api: add support for pagination
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
93985ee02d
commit
e7860e4f55
3 changed files with 4 additions and 3 deletions
|
@ -37,7 +37,7 @@ class MainActivity : AppCompatActivity() {
|
|||
val coroutineScope = rememberCoroutineScope()
|
||||
val posts = mutableStateListOf<LobstersPost>()
|
||||
coroutineScope.launch {
|
||||
posts.addAll(apiClient.getHottestPosts())
|
||||
posts.addAll(apiClient.getHottestPosts(1))
|
||||
}
|
||||
LobstersApp(posts)
|
||||
}
|
||||
|
|
|
@ -2,8 +2,9 @@ package dev.msfjarvis.lobsters.api
|
|||
|
||||
import dev.msfjarvis.lobsters.model.LobstersPost
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Query
|
||||
|
||||
interface LobstersApi {
|
||||
@GET("hottest.json")
|
||||
suspend fun getHottestPosts(): List<LobstersPost>
|
||||
suspend fun getHottestPosts(@Query("page") page: Int): List<LobstersPost>
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ class LobstersApiTest {
|
|||
|
||||
@Test
|
||||
fun `api gets correct number of items`() = runBlocking {
|
||||
val posts = apiClient.getHottestPosts()
|
||||
val posts = apiClient.getHottestPosts(1)
|
||||
assertEquals(25, posts.size)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue