mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 19:57:04 +05:30
feat(api): remove tag search endpoints
This commit is contained in:
parent
42cc852a20
commit
d343f3db2b
6 changed files with 0 additions and 75 deletions
|
@ -9,7 +9,6 @@ package dev.msfjarvis.claw.api
|
|||
import com.slack.eithernet.ApiResult
|
||||
import dev.msfjarvis.claw.model.LobstersPost
|
||||
import dev.msfjarvis.claw.model.LobstersPostDetails
|
||||
import dev.msfjarvis.claw.model.Tags
|
||||
import dev.msfjarvis.claw.model.User
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Path
|
||||
|
@ -30,12 +29,6 @@ interface LobstersApi {
|
|||
@GET("u/{username}.json")
|
||||
suspend fun getUser(@Path("username") username: String): ApiResult<User, Unit>
|
||||
|
||||
@GET("t/{tags}.json")
|
||||
suspend fun getPostsByTags(
|
||||
@Path("tags") tag: Tags,
|
||||
@Query("page") page: Int,
|
||||
): ApiResult<List<LobstersPost>, Unit>
|
||||
|
||||
companion object {
|
||||
const val BASE_URL = "https://lobste.rs"
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import com.slack.eithernet.ApiResult.Success
|
|||
import com.slack.eithernet.test.newEitherNetController
|
||||
import dev.msfjarvis.claw.model.LobstersPost
|
||||
import dev.msfjarvis.claw.model.LobstersPostDetails
|
||||
import dev.msfjarvis.claw.model.Tags
|
||||
import dev.msfjarvis.claw.model.User
|
||||
import dev.msfjarvis.claw.util.TestUtils.assertIs
|
||||
import kotlinx.coroutines.test.runTest
|
||||
|
@ -50,25 +49,4 @@ class ApiTest {
|
|||
assertIs<Success<User>>(user)
|
||||
assertThat(user.value.username).isEqualTo("msfjarvis")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `get posts by single tag`() = runTest {
|
||||
val tags = Tags()
|
||||
tags.addTag("meta")
|
||||
val posts = api.getPostsByTags(tags, 1)
|
||||
assertIs<Success<List<LobstersPost>>>(posts)
|
||||
assertThat(posts.value).hasSize(25)
|
||||
assertThat(posts.value[0].tags).contains("meta")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `get posts by multiple tags`() = runTest {
|
||||
val tags = Tags()
|
||||
tags.addTag("programming")
|
||||
tags.addTag("rust")
|
||||
val posts = api.getPostsByTags(tags, 1)
|
||||
assertIs<Success<List<LobstersPost>>>(posts)
|
||||
assertThat(posts.value).hasSize(25)
|
||||
assertThat(posts.value[0].tags).containsAnyOf("programming", "rust")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,13 +6,11 @@
|
|||
*/
|
||||
package dev.msfjarvis.claw.api
|
||||
|
||||
import com.slack.eithernet.ApiResult.Companion.httpFailure
|
||||
import com.slack.eithernet.ApiResult.Companion.success
|
||||
import com.slack.eithernet.test.EitherNetController
|
||||
import com.slack.eithernet.test.enqueue
|
||||
import dev.msfjarvis.claw.model.LobstersPost
|
||||
import dev.msfjarvis.claw.model.LobstersPostDetails
|
||||
import dev.msfjarvis.claw.model.Tags
|
||||
import dev.msfjarvis.claw.model.User
|
||||
import dev.msfjarvis.claw.util.TestUtils.getResource
|
||||
import kotlinx.serialization.ExperimentalSerializationApi
|
||||
|
@ -29,19 +27,6 @@ class ApiWrapper(controller: EitherNetController<LobstersApi>) {
|
|||
private val postDetails: LobstersPostDetails =
|
||||
json.decodeFromString(getResource("post_details_tdfoqh.json"))
|
||||
private val user: User = json.decodeFromString(getResource("msfjarvis.json"))
|
||||
private val metaPosts: List<LobstersPost> = json.decodeFromString(getResource("meta.json"))
|
||||
private val programmingRustPosts: List<LobstersPost> =
|
||||
json.decodeFromString(getResource("programming_rust.json"))
|
||||
private val getPostsBody = { args: Array<Any> ->
|
||||
val tags = args[0] as Tags
|
||||
if ("meta" in tags) {
|
||||
success(metaPosts)
|
||||
} else if ("programming" in tags && "rust" in tags) {
|
||||
success(programmingRustPosts)
|
||||
} else {
|
||||
httpFailure(400)
|
||||
}
|
||||
}
|
||||
|
||||
val api = controller.api
|
||||
|
||||
|
@ -50,7 +35,5 @@ class ApiWrapper(controller: EitherNetController<LobstersApi>) {
|
|||
controller.enqueue(LobstersApi::getHottestPosts) { success(hottest) }
|
||||
controller.enqueue(LobstersApi::getPostDetails) { success(postDetails) }
|
||||
controller.enqueue(LobstersApi::getUser) { success(user) }
|
||||
controller.enqueue(LobstersApi::getPostsByTags, getPostsBody)
|
||||
controller.enqueue(LobstersApi::getPostsByTags, getPostsBody)
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
* Copyright © 2023 Harsh Shandilya.
|
||||
* Use of this source code is governed by an MIT-style
|
||||
* license that can be found in the LICENSE file or at
|
||||
* https://opensource.org/licenses/MIT.
|
||||
*/
|
||||
package dev.msfjarvis.claw.model
|
||||
|
||||
class Tags {
|
||||
private val tags = arrayListOf<String>()
|
||||
|
||||
fun addTag(tag: String) {
|
||||
tags.add(tag)
|
||||
}
|
||||
|
||||
fun removeTag(tag: String) {
|
||||
tags.remove(tag)
|
||||
}
|
||||
|
||||
operator fun contains(tag: String): Boolean {
|
||||
return tag in tags
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return tags.joinToString(",")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue