Updating a user

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.144.56