Find the code snippet for the updateUser() operation:
// to update a user
@PutMapping("/user/{id}")
fun updateUser(@PathVariable(name = "id")id: Long, @Valid @RequestBody userDetails: UserModel): UserModel {
val currentUser: UserModel = userRepository.findById(id).get()
currentUser.name = userDetails.name
currentUser.email = userDetails.email
currentUser.contact_number = userDetails.contact_number
return userRepository.save(currentUser)
}
The @PutMapping("/user/{id}") annotation is the URL path of "/user/{id}", and it is a PUT request with a specific ID. Here, we will update the specific user details in the database.