Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unlock door api models #70

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,42 @@
package com.ioki.passenger.api.models

import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.PrimitiveKind
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder

@Serializable
public data class ApiUnlockDoorRequest(
@SerialName(value = "desired_state") val desiredState: String,
)
@SerialName(value = "desired_state") val desiredState: DesiredState,
) {
@Serializable(with = DesiredStateSerializer::class)
public enum class DesiredState {
@SerialName(value = "unlocked")
UNLOCKED,
UNSUPPORTED,
}
}

internal object DesiredStateSerializer : KSerializer<ApiUnlockDoorRequest.DesiredState> {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("DesiredState", PrimitiveKind.STRING)

override fun serialize(encoder: Encoder, value: ApiUnlockDoorRequest.DesiredState) {
encoder.encodeString(
when (value) {
ApiUnlockDoorRequest.DesiredState.UNLOCKED -> "unlocked"
ApiUnlockDoorRequest.DesiredState.UNSUPPORTED -> "unsupported"
},
)
}

override fun deserialize(decoder: Decoder): ApiUnlockDoorRequest.DesiredState {
return when (decoder.decodeString()) {
"unlocked" -> ApiUnlockDoorRequest.DesiredState.UNLOCKED
else -> ApiUnlockDoorRequest.DesiredState.UNSUPPORTED
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ public data class ApiVehicle(
@SerialName(value = "storage_spaces") val storageSpaces: Int,
val autonomous: Boolean,
@SerialName(value = "supports_door_open_requests") val supportsDoorOpenRequests: Boolean?,
Copy link
Collaborator

@StefMa StefMa Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also be non-null, right? 🤔

And did you asked about the supports_door_open_requests already? 🤔
Right now it is not delivered in case it is non-autonomous.
However, it should be set to false in that case.

@SerialName(value = "door_control_available") val doorControlAvailable: Boolean?,
@SerialName(value = "door_control_available") val doorControlAvailable: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ private val rideResponse =
"operator_information":"Operated by Ioki",
"seats": 5,
"storage_spaces": 3,
"autonomous": false
"autonomous": false,
"door_control_available": false
},
"driver": {
"display_name": "John Doe",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal class ApiUnlockDoorRequestTest : IokiApiModelTest() {
fun serialization() {
testSerializationWithJsonString(
ApiUnlockDoorRequest(
desiredState = "unlocked",
desiredState = ApiUnlockDoorRequest.DesiredState.UNLOCKED,
),
unlockDoorRequest,
)
Expand All @@ -17,7 +17,7 @@ internal class ApiUnlockDoorRequestTest : IokiApiModelTest() {
fun serializationMinimal() {
testSerializationWithJsonString(
ApiUnlockDoorRequest(
desiredState = "locked",
desiredState = ApiUnlockDoorRequest.DesiredState.UNSUPPORTED,
),
unlockDoorRequestMinimal,
)
Expand All @@ -34,6 +34,6 @@ private val unlockDoorRequest =
private val unlockDoorRequestMinimal =
"""
{
"desired_state": "locked"
"desired_state": "unsupported"
}
"""
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ fun createApiVehicle(
storageSpace: Int = 0,
autonomous: Boolean = false,
supportsDoorOpenRequests: Boolean? = null,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, not null 🤓

doorControlAvailable: Boolean? = null,
doorControlAvailable: Boolean = false,
): ApiVehicle = ApiVehicle(
licensePlate = licensePlate,
nickname = nickname,
Expand Down
Loading