Skip to content

Commit

Permalink
feat(cdr): getCdr param is open
Browse files Browse the repository at this point in the history
  • Loading branch information
pbourseau committed Jun 19, 2024
1 parent 0cd29ad commit 226a5e0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,20 @@ class CdrsCpoClient(
private val transportClientBuilder: TransportClientBuilder,
private val serverVersionsEndpointUrl: String,
private val partnerRepository: PartnerRepository
) : CdrsEmspInterface {
) : CdrsEmspInterface<URL> {
private suspend fun buildTransport(): TransportClient = transportClientBuilder
.buildFor(
module = ModuleID.cdrs,
partnerUrl = serverVersionsEndpointUrl,
partnerRepository = partnerRepository
)

override suspend fun getCdr(
cdrId: CiString
): OcpiResponseBody<Cdr?> =
with(buildTransport()) {
override suspend fun getCdr(param: URL): OcpiResponseBody<Cdr?> =
with(transportClientBuilder.build(param)) {
send(
HttpRequest(
method = HttpMethod.GET,
path = "/$cdrId"
path = "/"
).withRequiredHeaders(
requestId = generateRequestId(),
correlationId = generateCorrelationId()
Expand All @@ -44,9 +42,7 @@ class CdrsCpoClient(
.parseBody()
}

override suspend fun postCdr(
cdr: Cdr
): OcpiResponseBody<URL?> =
override suspend fun postCdr(cdr: Cdr): OcpiResponseBody<URL?> =
with(buildTransport()) {
send(
HttpRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.izivia.ocpi.toolkit.modules.cdr.domain.Cdr
* - PATCH: n/a (CDRs cannot be updated)
* - DELETE: n/a (CDRs cannot be removed)
*/
interface CdrsEmspInterface {
interface CdrsEmspInterface<T> {
/**
* GET Method
*
Expand All @@ -26,10 +26,9 @@ interface CdrsEmspInterface {
* No structure defined. This is open to the eMSP to define, the URL is provided to the CPO by the eMSP in
* the result of the POST request. Therefore, OCPI does not define variables.
*
* @param cdrId (max-length 36) id of the Cdr object to get from the eMSP’s system.
* @return Cdr Requested Cdr object.
*/
suspend fun getCdr(cdrId: CiString): OcpiResponseBody<Cdr?>
suspend fun getCdr(param: T): OcpiResponseBody<Cdr?>

/**
* POST Method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.izivia.ocpi.toolkit.transport.domain.HttpMethod
import com.izivia.ocpi.toolkit.transport.domain.VariablePathSegment

class CdrsEmspServer(
private val service: CdrsEmspInterface,
private val service: CdrsEmspInterface<String>,
versionsRepository: MutableVersionsRepository? = null,
basePathOverride: String? = null
) : OcpiSelfRegisteringModuleServer(
Expand All @@ -26,15 +26,14 @@ class CdrsEmspServer(
override suspend fun doRegisterOn(transportServer: TransportServer) {
transportServer.handle(
method = HttpMethod.GET,
path = basePathSegments + listOf(
VariablePathSegment("cdrId")
)
path =
basePathSegments +
listOf(
VariablePathSegment("cdrId")
)
) { req ->
req.httpResponse {
service
.getCdr(
cdrId = req.pathParams["cdrId"]!!
)
service.getCdr(param = req.pathParams["cdrId"]!!)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import com.izivia.ocpi.toolkit.modules.cdr.domain.Cdr
* - PATCH: n/a (CDRs cannot be updated)
* - DELETE: n/a (CDRs cannot be removed)
*/
interface CdrsEmspRepository {
interface CdrsEmspRepository<T> {
/**
* GET Method
*
Expand All @@ -25,10 +25,9 @@ interface CdrsEmspRepository {
* No structure defined. This is open to the eMSP to define, the URL is provided to the CPO by the eMSP in
* the result of the POST request. Therefore, OCPI does not define variables.
*
* @param cdrId (max-length 36) id of the Cdr object to get from the eMSP’s system.
* @return Cdr Requested Cdr object.
*/
suspend fun getCdr(cdrId: CiString): Cdr?
suspend fun getCdr(param: T): Cdr?

/**
* POST Method
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
package com.izivia.ocpi.toolkit.modules.cdr.services

import com.izivia.ocpi.toolkit.common.CiString
import com.izivia.ocpi.toolkit.common.OcpiResponseBody
import com.izivia.ocpi.toolkit.common.URL
import com.izivia.ocpi.toolkit.common.validation.isUrl
import com.izivia.ocpi.toolkit.common.validation.validate
import com.izivia.ocpi.toolkit.common.validation.validateLength
import com.izivia.ocpi.toolkit.common.validation.validateUrl
import com.izivia.ocpi.toolkit.modules.cdr.CdrsEmspInterface
import com.izivia.ocpi.toolkit.modules.cdr.domain.Cdr
import com.izivia.ocpi.toolkit.modules.cdr.repositories.CdrsEmspRepository

class CdrsEmspService(
private val service: CdrsEmspRepository
) : CdrsEmspInterface {
override suspend fun getCdr(cdrId: CiString): OcpiResponseBody<Cdr?> = OcpiResponseBody.of {
private val service: CdrsEmspRepository<String>
) : CdrsEmspInterface<String> {
/**
* GET Method
*
* Fetch CDRs from the receivers' system.
*
* Endpoint structure definition:
*
* @param param Id of the requested Cdr
* @return Cdr Requested Cdr object.
*/
override suspend fun getCdr(param: String): OcpiResponseBody<Cdr?> = OcpiResponseBody.of {
validate {
validateLength("cdrId", cdrId, 39)
validateLength("cdrId", param, 36)
}
service
.getCdr(cdrId)
?.validate()
service.getCdr(param)?.validate()
}

override suspend fun postCdr(cdr: Cdr): OcpiResponseBody<URL?> = OcpiResponseBody.of {
validate {
cdr.validate()
}
service.postCdr(cdr)?.isUrl()
service.postCdr(cdr)?.validateUrl()
}
}

0 comments on commit 226a5e0

Please sign in to comment.