Skip to content

Commit

Permalink
Merge pull request #95 from andacata/main
Browse files Browse the repository at this point in the history
refactor(common) #93: rename to camelCase the fields of OcpiResponseBody
  • Loading branch information
lilgallon authored Mar 26, 2024
2 parents ecca198 + a70ea1a commit a0d84bf
Show file tree
Hide file tree
Showing 10 changed files with 157 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ inline fun <reified T> HttpResponse.parsePaginatedBody(offset: Int): OcpiRespons
offset = offset,
nextPageUrl = getHeader(Header.LINK)?.split("<")?.elementAtOrNull(1)?.split(">")?.first()
),
status_code = parsedBody.status_code,
status_message = parsedBody.status_message,
statusCode = parsedBody.statusCode,
statusMessage = parsedBody.statusMessage,
timestamp = parsedBody.timestamp
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import java.time.Instant
*
* @property data Contains the actual response data object or list of objects from each request, depending on the
* cardinality of the response data, this is an array (card. * or +), or a single object (card. 1 or ?)
* @property status_code Response code, as listed in Status Codes, indicates how the request was handled. To avoid
* @property statusCode Response code, as listed in Status Codes, indicates how the request was handled. To avoid
* confusion with HTTP codes, at least four digits are used.
* @property status_message An optional status message which may help when debugging.
* @property statusMessage An optional status message which may help when debugging.
* @property timestamp The time this message was generated.
*/
data class OcpiResponseBody<T>(
val data: T?,
val status_code: Int,
val status_message: String?,
val statusCode: Int,
val statusMessage: String?,
val timestamp: Instant
) {
companion object {
Expand All @@ -41,15 +41,15 @@ data class OcpiResponseBody<T>(

fun <T> success(data: T) = OcpiResponseBody(
data = data,
status_code = OcpiStatus.SUCCESS.code,
status_message = "Success",
statusCode = OcpiStatus.SUCCESS.code,
statusMessage = "Success",
timestamp = now()
)

fun <T> invalid(message: String) = OcpiResponseBody<T>(
data = null,
status_code = OcpiStatus.CLIENT_INVALID_PARAMETERS.code,
status_message = message,
statusCode = OcpiStatus.CLIENT_INVALID_PARAMETERS.code,
statusMessage = message,
timestamp = now()
)

Expand Down Expand Up @@ -99,8 +99,8 @@ fun OcpiException.toHttpResponse(): HttpResponse =
body = mapper.writeValueAsString(
OcpiResponseBody(
data = null,
status_code = ocpiStatus.code,
status_message = message,
statusCode = ocpiStatus.code,
statusMessage = message,
timestamp = Instant.now()
)
),
Expand All @@ -121,7 +121,7 @@ suspend fun <T> HttpRequest.httpResponse(fn: suspend () -> OcpiResponseBody<T>):
val isPaginated = ocpiResponseBody.data is SearchResult<*>

HttpResponse(
status = when (ocpiResponseBody.status_code) {
status = when (ocpiResponseBody.statusCode) {
OcpiStatus.SUCCESS.code -> if (ocpiResponseBody.data != null) HttpStatus.OK else HttpStatus.NOT_FOUND
OcpiStatus.CLIENT_INVALID_PARAMETERS.code -> HttpStatus.BAD_REQUEST
else -> HttpStatus.OK
Expand All @@ -130,8 +130,8 @@ suspend fun <T> HttpRequest.httpResponse(fn: suspend () -> OcpiResponseBody<T>):
if (isPaginated) {
OcpiResponseBody(
data = (ocpiResponseBody.data as SearchResult<*>?)?.list,
status_code = ocpiResponseBody.status_code,
status_message = ocpiResponseBody.status_message,
statusCode = ocpiResponseBody.statusCode,
statusMessage = ocpiResponseBody.statusMessage,
timestamp = ocpiResponseBody.timestamp
)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ open class CredentialsClientService(
?.let { clientToken ->
buildCredentialClient()
.get(token = clientToken)
.let { it.data ?: throw OcpiResponseException(it.status_code, it.status_message ?: "unknown") }
.let { it.data ?: throw OcpiResponseException(it.statusCode, it.statusMessage ?: "unknown") }
}
?: throw OcpiClientGenericException(
"Could not find CREDENTIALS_TOKEN_C associated with partner $serverVersionsEndpointUrl"
Expand Down Expand Up @@ -103,7 +103,7 @@ open class CredentialsClientService(
),
debugHeaders = emptyMap()
).let {
it.data ?: throw OcpiResponseException(it.status_code, it.status_message ?: "unknown")
it.data ?: throw OcpiResponseException(it.statusCode, it.statusMessage ?: "unknown")
}

// Save credentials roles of partner
Expand Down Expand Up @@ -152,7 +152,7 @@ open class CredentialsClientService(
),
debugHeaders = emptyMap()
).let {
it.data ?: throw OcpiResponseException(it.status_code, it.status_message ?: "unknown")
it.data ?: throw OcpiResponseException(it.statusCode, it.statusMessage ?: "unknown")
}

// Save credentials roles of partner
Expand Down Expand Up @@ -182,8 +182,8 @@ open class CredentialsClientService(
clientPartnerRepository.invalidateCredentialsServerToken(partnerUrl = serverVersionsEndpointUrl)
}
.also {
if (it.status_code != OcpiStatus.SUCCESS.code) {
throw OcpiResponseException(it.status_code, it.status_message ?: "unknown")
if (it.statusCode != OcpiStatus.SUCCESS.code) {
throw OcpiResponseException(it.statusCode, it.statusMessage ?: "unknown")
}
}
}
Expand All @@ -199,7 +199,7 @@ open class CredentialsClientService(
)
.getVersions()
.let {
it.data ?: throw OcpiResponseException(it.status_code, it.status_message ?: "unknown")
it.data ?: throw OcpiResponseException(it.statusCode, it.statusMessage ?: "unknown")
}
val availableClientVersionNumbers = clientVersionsRepository.getVersions()

Expand All @@ -225,7 +225,7 @@ open class CredentialsClientService(
)
.getVersionDetails()
.let {
it.data ?: throw OcpiResponseException(it.status_code, it.status_message ?: "unknown")
it.data ?: throw OcpiResponseException(it.statusCode, it.statusMessage ?: "unknown")
}

checkRequiredEndpoints(requiredEndpoints, versionDetails.endpoints)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ open class CredentialsServerService(
.let {
it.data
?: throw OcpiServerUnusableApiException(
"Could not get versions of sender, there was an error during the call: '${it.status_message}'"
"Could not get versions of sender, there was an error during the call: '${it.statusMessage}'"
)
}

Expand Down Expand Up @@ -197,7 +197,7 @@ open class CredentialsServerService(
.let {
it.data
?: throw OcpiServerUnusableApiException(
"Could not get version of sender, there was an error during the call: '${it.status_message}'"
"Could not get version of sender, there was an error during the call: '${it.statusMessage}'"
)
}

Expand Down
Loading

0 comments on commit a0d84bf

Please sign in to comment.