-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
25 changed files
with
663 additions
and
210 deletions.
There are no files selected for viewing
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
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
4 changes: 4 additions & 0 deletions
4
src/main/kotlin/io/github/smaugfm/lunchmoney/api/LunchmoneyApiInternal.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
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
53 changes: 1 addition & 52 deletions
53
src/main/kotlin/io/github/smaugfm/lunchmoney/exception/LunchmoneyApiResponseException.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,54 +1,3 @@ | ||
package io.github.smaugfm.lunchmoney.exception | ||
|
||
import io.github.smaugfm.lunchmoney.response.ApiErrorResponse | ||
import io.netty.handler.codec.http.HttpResponseStatus | ||
|
||
@Suppress("MemberVisibilityCanBePrivate") | ||
class LunchmoneyApiResponseException : LunchmoneyApiException { | ||
val apiErrorResponse: ApiErrorResponse? | ||
val statusCode: Int | ||
val body: String | ||
|
||
constructor( | ||
body: String, | ||
cause: ApiErrorResponse, | ||
statusCode: Int | ||
) : super(errorMessage(cause)) { | ||
this.body = body | ||
this.apiErrorResponse = cause | ||
this.statusCode = statusCode | ||
} | ||
|
||
constructor( | ||
body: String, | ||
cause: Throwable, | ||
statusCode: Int | ||
) : super(cause) { | ||
this.body = body | ||
this.apiErrorResponse = null | ||
this.statusCode = statusCode | ||
} | ||
|
||
constructor( | ||
statusCode: Int | ||
) : super( | ||
"Response body is empty but status is $statusCode " + | ||
HttpResponseStatus.valueOf(statusCode).reasonPhrase() | ||
) { | ||
this.body = "" | ||
this.apiErrorResponse = null | ||
this.statusCode = statusCode | ||
} | ||
|
||
companion object { | ||
private fun errorMessage(apiErrorResponse: ApiErrorResponse): String { | ||
val msg = apiErrorResponse.message | ||
if (msg != null) { | ||
return msg | ||
} | ||
|
||
return apiErrorResponse.error?.joinToString(", ") | ||
?: "Received erroneous response from Lunchmoney API" | ||
} | ||
} | ||
} | ||
class LunchmoneyApiResponseException(message: String) : LunchmoneyApiException(message) |
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
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/io/github/smaugfm/lunchmoney/model/LunchmoneyBudgetRecurringItem.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,21 @@ | ||
@file:UseSerializers( | ||
BigDecimalSerializer::class, | ||
CurrencySerializer::class, | ||
) | ||
|
||
package io.github.smaugfm.lunchmoney.model | ||
|
||
import io.github.smaugfm.lunchmoney.serializer.BigDecimalSerializer | ||
import io.github.smaugfm.lunchmoney.serializer.CurrencySerializer | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.UseSerializers | ||
import java.math.BigDecimal | ||
import java.util.Currency | ||
|
||
@Serializable | ||
data class LunchmoneyBudgetRecurringItem( | ||
val payee: String, | ||
val amount: BigDecimal, | ||
val currency: Currency, | ||
val toBase: Double | ||
) |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/io/github/smaugfm/lunchmoney/model/LunchmoneyBudgetRecurringItemList.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 io.github.smaugfm.lunchmoney.model | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class LunchmoneyBudgetRecurringItemList( | ||
val list: List<LunchmoneyBudgetRecurringItem> | ||
) |
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
62 changes: 50 additions & 12 deletions
62
src/main/kotlin/io/github/smaugfm/lunchmoney/response/ApiErrorResponse.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,19 +1,57 @@ | ||
package io.github.smaugfm.lunchmoney.response | ||
|
||
import io.github.smaugfm.lunchmoney.exception.LunchmoneyApiResponseException | ||
import io.github.smaugfm.lunchmoney.model.LunchmoneyCategoryDeletionDependency | ||
import io.github.smaugfm.lunchmoney.serializer.StringOrStringArrayDeserializer | ||
import io.github.smaugfm.lunchmoney.serializer.CategoryDeletionErrorSerializer | ||
import io.github.smaugfm.lunchmoney.serializer.StructuredApiErrorResponseSerializer | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
|
||
@Serializable | ||
data class ApiErrorResponse( | ||
var name: String? = null, | ||
var message: String? = null, | ||
@Serializable(with = StringOrStringArrayDeserializer::class) | ||
var error: List<String>? = null, | ||
var dependents: LunchmoneyCategoryDeletionDependency? = null | ||
) { | ||
fun toException(body: String, statusCode: Int): LunchmoneyApiResponseException { | ||
return LunchmoneyApiResponseException(body, this, statusCode) | ||
sealed class ApiErrorResponse { | ||
|
||
abstract val msg: String | ||
|
||
data class UnknownApiErrorResponse(override val msg: String) : ApiErrorResponse() | ||
|
||
@Serializable(StructuredApiErrorResponseSerializer::class) | ||
sealed class StructuredApiErrorResponse : ApiErrorResponse() { | ||
@Serializable | ||
data class AccessTokenError(val name: String, val message: String) : StructuredApiErrorResponse() { | ||
override val msg = message | ||
} | ||
|
||
@Serializable | ||
data class SingleError(val error: String) : StructuredApiErrorResponse() { | ||
override val msg = error | ||
} | ||
|
||
@Serializable | ||
data class MultipleErrors(val error: List<String>) : StructuredApiErrorResponse() { | ||
override val msg = error.joinToString("\n") | ||
} | ||
|
||
@Serializable(with = CategoryDeletionErrorSerializer::class) | ||
sealed class CategoryDeletionError : StructuredApiErrorResponse() { | ||
|
||
@Serializable | ||
data class CategoryDeletionDependencySingle( | ||
val dependents: LunchmoneyCategoryDeletionDependency | ||
) : CategoryDeletionError() { | ||
override val msg: String | ||
get() = json.encodeToString(dependents) | ||
} | ||
|
||
@Serializable | ||
data class CategoryDeletionDependencyMultiple( | ||
val dependents: List<LunchmoneyCategoryDeletionDependency> | ||
) : CategoryDeletionError() { | ||
override val msg: String | ||
get() = json.encodeToString(dependents) | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
private val json = Json { prettyPrint = true } | ||
} | ||
} |
Oops, something went wrong.