Frontend todo.ts and todo.html
Console.log
backend-code with spring boot //TodoService; function for Update
public Todos updateTodoWithMap(Long id, Map<Object, Object> objectMap) {
Optional<Todos> todos = todoRepository.findById(id);
objectMap.forEach((key, value) -> {
Field field = ReflectionUtils.findField(Todos.class, (String) key);
field.setAccessible(true);
ReflectionUtils.setField(field, todos.get(), value);
});
return todoRepository.save(todos.get());
}
and frontend with angular http request
updateTodo(id: any, todoData: Todo): Observable<Todo> {
return this.http.patch<Todo>(`${this.baseUrl}/${id}`, todoData)
.pipe(
catchError(this.handleError)
);
}
I want to send an http patch request to the server, but I get error message 415. what should I do. what is wrong?
Conroller Class from Todo with PatchMapping:
@CrossOrigin(origins = "https://localhost:8100")
@RestController
@RequestMapping("/auth/users")
public class TodosController {
@Autowired
private final TodosService todoService;
public TodosController(TodosService todoService) {
this.todoService = todoService;
}
@GetMapping("todo")
public List<Todos> getTodos() {
return this.todoService.getTodos();
}
@PostMapping("todo")
public Todos addTodos(@RequestBody Todos toDos) {
return this.todoService.addTodo(toDos);
}
/*@PutMapping("todo/{id}")
public Todos update(@PathVariable(value = "id") Long todoId, @RequestBody Todos todosDetail)
throws NoteNotFoundException {
Todos updatedTodos = this.todoService.updateTodo(todoId, todosDetail);
return updatedTodos;
}*/
@PatchMapping("todo/{id}")
public Todos updateTodoWithMap(@PathVariable(value="id") Long id, @RequestBody
Map<Object,Object> objectMap ){
return todoService.updateTodoWithMap(id, objectMap);
}
@DeleteMapping("todo/{id}")
public Boolean delete(@PathVariable Long id) {
return this.todoService.delete(id);
}
}