Skip to content

Commit

Permalink
Merge pull request #143 from andacata/fix/#142-tokens-cpo-repository-…
Browse files Browse the repository at this point in the history
…optional-return
  • Loading branch information
lilgallon authored Nov 18, 2024
2 parents 6050bab + 4988e75 commit 210ff9d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ interface TokensCpoInterface {
partyId: CiString,
tokenUid: CiString,
type: TokenType? = TokenType.RFID,
): OcpiResponseBody<Token>
): OcpiResponseBody<Token?>

/**
* PUT Method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TokensEmspClient(
partyId: CiString,
tokenUid: CiString,
type: TokenType?,
): OcpiResponseBody<Token> =
): OcpiResponseBody<Token?> =
with(buildTransport()) {
send(
HttpRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ interface TokensCpoRepository {
partyId: CiString,
tokenUid: CiString,
type: TokenType? = TokenType.RFID,
): Token
): Token?

/**
* PUT Method
*
* New or updated Token objects are pushed from the eMSP to the CPO
*
* @param token (Request Body) New or updated Token object
* @param countryCode (Request parameter) Country code of the eMSP sending this PUT request to the CPO system. This
* SHALL be the same value as the country_code in the Token object being
* pushed. max-length = 36
Expand All @@ -55,13 +54,14 @@ interface TokensCpoRepository {
* @param tokenUid (Request parameter) Token.uid of the (new) Token object (to replace). max-length = 36
* @param type (Request parameter) Token.type of the Token of the (new) Token object (to replace). Default if omitted:
* RFID
* @param token (Request Body) New or updated Token object
*/
suspend fun putToken(
token: Token,
countryCode: CiString,
partyId: CiString,
tokenUid: CiString,
type: TokenType? = TokenType.RFID,
token: Token,
): Token

/**
Expand All @@ -72,7 +72,6 @@ interface TokensCpoRepository {
*
* Any request to the PATCH method SHALL contain the last_updated field.
*
* @param token (Request Body) New or updated Token object
* @param countryCode (Request parameter) Country code of the eMSP sending this PUT request to the CPO system. This
* SHALL be the same value as the country_code in the Token object being
* pushed. max-length = 36
Expand All @@ -82,12 +81,13 @@ interface TokensCpoRepository {
* @param tokenUid (Request parameter) Token.uid of the (new) Token object (to replace). max-length = 36
* @param type (Request parameter) Token.type of the Token of the (new) Token object (to replace). Default if omitted:
* RFID
* @param token (Request Body) New or updated Token object
*/
suspend fun patchToken(
token: TokenPartial,
countryCode: CiString,
partyId: CiString,
tokenUid: CiString,
type: TokenType? = TokenType.RFID,
token: TokenPartial,
): Token?
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ open class TokensCpoService(
partyId: CiString,
tokenUid: CiString,
type: TokenType?,
): OcpiResponseBody<Token> = OcpiResponseBody.of {
): OcpiResponseBody<Token?> = OcpiResponseBody.of {
validate {
validateLength("countryCode", countryCode, 2)
validateLength("partyId", partyId, 3)
validateLength("tokenUid", tokenUid, 36)
}

service.getToken(countryCode, partyId, tokenUid, type).validate()
service.getToken(countryCode, partyId, tokenUid, type)?.validate()
}

override suspend fun putToken(
Expand All @@ -46,7 +46,7 @@ open class TokensCpoService(
validateSame("tokenUid", tokenUid, token.uid)
}

service.putToken(token, countryCode, partyId, tokenUid, type).validate()
service.putToken(countryCode, partyId, tokenUid, type, token).validate()
}

override suspend fun patchToken(
Expand All @@ -63,6 +63,6 @@ open class TokensCpoService(
validateLength("tokenUid", tokenUid, 36)
}

service.patchToken(token, countryCode, partyId, tokenUid, type)?.validate()
service.patchToken(countryCode, partyId, tokenUid, type, token)?.validate()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ class TokensCpoHttpPatchTokenTest {
val srv = mockk<TokensCpoRepository> {
coEvery {
patchToken(
capture(slots.token),
capture(slots.countryCode),
capture(slots.partyId),
capture(slots.tokenUID),
capture(slots.type),
capture(slots.token),
)
} coAnswers { token }
}.buildServer()
Expand Down Expand Up @@ -146,11 +146,11 @@ class TokensCpoHttpPatchTokenTest {
val srv = mockk<TokensCpoRepository> {
coEvery {
patchToken(
capture(slots.token),
capture(slots.countryCode),
capture(slots.partyId),
capture(slots.tokenUID),
capture(slots.type),
capture(slots.token),
)
} coAnswers { token }
}.buildServer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ class TokensCpoHttpPutTokenTest {
val srv = mockk<TokensCpoRepository> {
coEvery {
putToken(
capture(slots.token),
capture(slots.countryCode),
capture(slots.partyId),
capture(slots.tokenUID),
capture(slots.type),
capture(slots.token),
)
} coAnswers { token }
}.buildServer()
Expand Down

0 comments on commit 210ff9d

Please sign in to comment.