4 ms·
Maybe I'm not getting what you're saying but the data is partial? In the situation above we have a valid record created by someone else. This is pseudocode obvi
by vips7L 2y ago
Maybe I'm not getting what you're saying but the data is partial? In the situation above we have a valid record created by someone else. This is pseudocode obviously, but I genuinely don't know what copying or building or immutability is going to buy me here other than being more complex. There is no worrying about the record being in an invalid state because it could have never gotten to the database in an invalid state.
class User {
Long? id;
String email;
String? name;
Integer? age;
Sex? sex;
Avatar? avatar;
User(String email) {
this.email = email;
}
}
record ProfileVm(String? name, Integer? age, Sex? sex, Avatar? avatar) {}
// some ui controller
var user = findById(id)
if (user == null) {
return notFound();
}
var vm = ProfileVm.fromJson(request.json());
user.setName(vm.name());
user.setAge(vm.age());
user.setSex(vm.sex());
user.setAvatar(vm.avatar());
user.save();
return ok();