anyone could tell me what’s wrong with this `exist...
# spring
d
anyone could tell me what’s wrong with this
existingUser.copy(username...
here :
Copy code
package com.example.app.controllers

import com.example.app.models.User
import com.example.app.repositories.UserRepository
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import java.util.*
import javax.validation.Valid

@RestController
@RequestMapping("/api")
class UserController(private val userRepository: UserRepository) {

    @PutMapping("/users/{id}")
    fun updateUserById(@PathVariable(value = "id") userId: Long,
                          @Valid @RequestBody newUser: User): ResponseEntity<User> {
        return userRepository.findById(userId).map { existingUser ->
            val updatedUser: User = existingUser.copy(username = newUser.username)
            ResponseEntity.ok().body(userRepository.save(updatedUser))
        }.orElse(ResponseEntity.notFound().build())
    }
I get this compiling error:
Unresolved reference: copy
k
Are you sure
com.example.app.models.User
has a
copy
method? Data classes have a compiler-generated copy method, but maybe User is not a data class.
☝️ 1
d
Thanks for the help @Klitos Kyriacou I ended up changing my class to
data class User (
which add the copy method.