How do you upsert a list of objects in Java or in ...
# announcements
z
How do you upsert a list of objects in Java or in Kotlin. What is the best practice or the best chain for something like upserting a setting. Scenario one match-id can have many settings and that can change.
Copy code
data class Setting(val typeId: Int, val type: String, val isSubscribed: Boolean, val matchId: Int)

    val settings = mutableListOf(Setting(1, "Goal Notification", true, matchId = 123), Setting(2, "Half Time Notification", true, matchId = 567))

    //upsert?/
    val newSettings = settings.add(Setting(1, "Goal Notification", false, matchId = 123))

    val latestSettings = settings.filter { setting -> setting.typeId == 1 }.map {
        // add or update over here
    }
Should I use a set instead a list?
o
you are probably looking for a MutableMap. If you add a new "setting" to the same key, it will update it.