-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Данила Беляков
authored and
Данила Беляков
committed
Aug 1, 2024
1 parent
71f596b
commit fb83c3c
Showing
7 changed files
with
72 additions
and
29 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
alice-ktx/src/main/kotlin/com/github/alice/ktx/api/common/Response.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.github.alice.ktx.api.common | ||
|
||
sealed interface Response<T>{ | ||
data class Failed<T>(val message: String): Response<T> | ||
data class Success<T>(val data: T): Response<T> | ||
} |
13 changes: 13 additions & 0 deletions
13
alice-ktx/src/main/kotlin/com/github/alice/ktx/api/common/extensions/ResponseExtensions.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.github.alice.ktx.api.common.extensions | ||
|
||
import com.github.alice.ktx.api.common.Response | ||
import com.github.alice.ktx.api.dialog.yandex.models.ErrorBody | ||
import io.ktor.client.call.* | ||
import io.ktor.client.statement.* | ||
|
||
suspend inline fun <reified T> HttpResponse.response(): Response<T> { | ||
return if(status.value in 200..299) | ||
Response.Success(this.body()) | ||
else | ||
Response.Failed(this.body<ErrorBody>().message) | ||
} |
11 changes: 6 additions & 5 deletions
11
alice-ktx/src/main/kotlin/com/github/alice/ktx/api/dialog/DialogApi.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
package com.github.alice.ktx.api.dialog | ||
|
||
import com.github.alice.ktx.api.common.Response | ||
import com.github.alice.ktx.api.dialog.yandex.models.image.response.ImageUpload | ||
import com.github.alice.ktx.api.dialog.yandex.models.image.response.Images | ||
import com.github.alice.ktx.api.dialog.yandex.models.status.Status | ||
import java.io.File | ||
|
||
interface DialogApi { | ||
suspend fun getStatus(): Status | ||
suspend fun uploadImage(url: String): ImageUpload | ||
suspend fun uploadImage(file: File): ImageUpload | ||
suspend fun getAllImages(): Images | ||
suspend fun deleteImage(id: String): Boolean | ||
suspend fun getStatus(): Response<Status> | ||
suspend fun uploadImage(url: String): Response<ImageUpload> | ||
suspend fun uploadImage(file: File): Response<ImageUpload> | ||
suspend fun getAllImages(): Response<Images> | ||
suspend fun deleteImage(id: String): Response<Unit> | ||
} |
This file contains 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
8 changes: 8 additions & 0 deletions
8
alice-ktx/src/main/kotlin/com/github/alice/ktx/api/dialog/yandex/models/ErrorBody.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.github.alice.ktx.api.dialog.yandex.models | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ErrorBody( | ||
val message: String | ||
) |
This file contains 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
This file contains 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