Giuliopime
09/26/2022, 10:17 PM/**
* Represents a single list, which can contain categories to organize list items in it
*/
@Serializable
data class ListDto(
@Contextual @SerialName("_id") val id: String = ObjectId().toHexString(),
val user_id: String,
var name: String,
val categories: MutableList<CategoryDto>,
// TODO: types do be defined
var icon: String,
var color: String
)
I want the user to create a new List from the frontend so I will need to receive the list data in my ktor put route
route("/lists") {
get {
// Returns all lists
}
put {
// Need to receive the list data here but obviously it doesn't have an id yet
}
The issue is that when the user wants to create a list it will not send the list id too, 'cause that will be generated on the server after receiving the list properties like name, categories, etc...
Isn't there a way to reuse the ListDto data class but fill the id variable dynamically?Giuliopime
09/26/2022, 10:22 PM= ObjectId().toHexString()
already does it for the id, but that about the user_id
for exampleAdam Cooper
09/26/2022, 10:24 PMGiuliopime
09/26/2022, 10:24 PMAdam Cooper
09/26/2022, 10:26 PMGiuliopime
09/26/2022, 10:27 PMGiuliopime
09/26/2022, 10:28 PMAdam Cooper
09/26/2022, 10:32 PMAdam Cooper
09/26/2022, 10:32 PM@Transient
Giuliopime
09/26/2022, 10:44 PMGiuliopime
09/26/2022, 10:44 PMAdam Cooper
09/26/2022, 10:45 PMGiuliopime
09/26/2022, 10:48 PMAdam Cooper
09/26/2022, 10:49 PMGiuliopime
09/26/2022, 10:50 PM