Skip to content

Commit 30f76f3

Browse files
committed
remove last deprecated
1 parent 7bd6a16 commit 30f76f3

File tree

3 files changed

+37
-27
lines changed

3 files changed

+37
-27
lines changed

cli/src/main/kotlin/CliViewModel.kt

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
import arrow.core.NonEmptyList
12
import arrow.core.getOrElse
23
import arrow.core.raise.either
4+
import arrow.core.raise.nullable
5+
import arrow.core.raise.recover
6+
import arrow.core.toNonEmptyListOrNull
37
import client.ScryfallApi
8+
import co.touchlab.kermit.Logger
49
import com.mfriend.collection.CollectionImporter
510
import com.mfriend.db.Card
611
import com.mfriend.db.DatabaseHelper
@@ -13,13 +18,16 @@ class CliViewModel(
1318
composeLogger: ComposeLogger,
1419
) {
1520
val logs = composeLogger.logs
21+
1622
// TODO Replace with raise and expose results to UI
1723
suspend fun translateCsv(filePath: String) {
1824
val succ = either {
1925
val imported = importer.parseCardCastle(filePath).bind()
2026
val cardRows = imported.map { importCard ->
21-
api.searchCard("${importCard.name} s:${importCard.set} cn:\"${importCard.number}\"").bind()
22-
.first() to importCard.count
27+
val results = withErrorString {
28+
api.searchCardRaise("${importCard.name} s:${importCard.set} cn:\"${importCard.number}\"")
29+
}
30+
results.first() to importCard.count
2331
}.map { (card, count) ->
2432
Card(
2533
-1, // TODO Fix insert
@@ -39,22 +47,25 @@ class CliViewModel(
3947
}
4048

4149
suspend fun searchAndAddCards(query: String) {
42-
api.searchCard(query)
43-
.map {
44-
val selection = it.first()
45-
val card = Card(
46-
-1, // TODO Fix insert
47-
selection.name,
48-
selection.set,
49-
selection.setName,
50-
selection.imageUris?.large?.url,
51-
selection.scryfallUrl.url,
52-
)
53-
database.insertCard(card)
54-
}.mapLeft { throw Exception(it) }
50+
// TODO make this pure or something
51+
recover({
52+
val results = api.searchCardRaise(query)
53+
val selection = results.first()
54+
val card = Card(
55+
-1, // TODO Fix insert
56+
selection.name,
57+
selection.set,
58+
selection.setName,
59+
selection.imageUris?.large?.url,
60+
selection.scryfallUrl.url,
61+
)
62+
database.insertCard(card)
63+
}, { Logger.e(it.toString()) })
5564
}
5665

5766
fun getCards() = database.getCards()
5867

59-
suspend fun searchCards(query: String): List<CardDto>? = api.searchCard(query).getOrElse { null }
68+
suspend fun searchCards(query: String): NonEmptyList<CardDto>? = nullable {
69+
ignoreErrors { api.searchCardRaise(query).toNonEmptyListOrNull() }
70+
}
6071
}

scryfall/src/commonMain/kotlin/client/ScryfallApi.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package client
22

3-
import arrow.core.Either
43
import arrow.core.raise.Raise
54
import arrow.core.raise.catch
6-
import arrow.core.raise.either
7-
import arrow.core.raise.withError
85
import ensure
96
import io.ktor.client.call.body
107
import io.ktor.client.request.HttpRequestBuilder
@@ -32,9 +29,6 @@ interface ScryfallApi : AutoCloseable {
3229

3330
context(_: Raise<ScryfallError>)
3431
suspend fun setsRaise(): List<SetDto>
35-
36-
@Deprecated("Use raise variant", replaceWith = ReplaceWith("searchCardRaise(searchParam)"))
37-
suspend fun searchCard(searchParam: String): Either<String, List<CardDto>>
3832
}
3933

4034
class ScryfallApiImpl : ScryfallApi, AutoCloseable {
@@ -83,11 +77,6 @@ class ScryfallApiImpl : ScryfallApi, AutoCloseable {
8377
override suspend fun setsRaise(): List<SetDto> =
8478
client.get { scryfall("sets") }.responseBodyOrRaise<ListResp<SetDto>>().data
8579

86-
@Deprecated("Use raise variant", replaceWith = ReplaceWith("searchCardRaise(searchParam)"))
87-
override suspend fun searchCard(searchParam: String): Either<String, List<CardDto>> = either {
88-
withError({ it.toString() }) { searchCardRaise(searchParam) }
89-
}
90-
9180
companion object {
9281
const val ScryfallBaseUri: String = "https://api.scryfall.com"
9382
const val CardApiBase: String = "/cards"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@file:OptIn(ExperimentalTypeInference::class)
2+
3+
import arrow.core.raise.RaiseDSL
4+
import arrow.core.raise.withError
5+
import kotlin.experimental.ExperimentalTypeInference
6+
7+
context(raise: Raise<String>) @RaiseDSL
8+
inline fun <OtherError, A> withErrorString(
9+
@BuilderInference block: Raise<OtherError>.() -> A
10+
): A = raise.withError({ it.toString() }, block)

0 commit comments

Comments
 (0)