Hello, I have a class teacher registered and I want to change it by passing an array of materials.
I have the following code:
class teacher:
//... atributos não importantes ao problema
@ManyToMany
@JoinTable(name = "teacher_x_lesson",
joinColumns = @JoinColumn(name = "id_teacher"),
inverseJoinColumns = @JoinColumn(name = "id_lesson"))
private List<Lesson> lesson;
In the resource I arrived here but I do not know if I'm on the right path.
@PutMapping("/{id}/lesson")
@PreAuthorize("hasAuthority('ROLE_PUT_TEACHER') and #oauth2.hasScope('wride')")
public void putLessonTeacher(@PathVariable Long id, List<Lesson> idLesson) {
Teacher teacher = repository.findById(id).get();
teacher.setLesson(idLesson);
BeanUtils.copyProperties(idLesson, teacher, "id" );
}
In Postman I'm passing the following:
{
"lesson": [
{"id":1}
]
}