I have this code from the front-end (Angular)
private _baseUrl = "http://localhost:8080/api/v1/professor/";
getProfessor(id: string): Observable<Professor> {
const professor = this.http.get<Professor>(this._baseUrl + id);
return professor;
}
addProfessorRating(id: string, rating: Object): void {
// get the professor, then modify the ratings of them, and make a put request
this.getProfessor(id).subscribe(professor => {
let ratings = professor['ratings'];
ratings.push(rating);
professor['ratings'] = ratings;
return this.http.put<void>(this._baseUrl + id, professor, {
headers: new HttpHeaders({
'content-type': 'application/json'
})
})
});
}
And this endpoint from the backend (Spring boot):
@PutMapping(path = "/{id}")
public String updateProf(@PathVariable("id") String id, @Valid @NotNull @RequestBody Professor professor) {
logger.info("updating professor");
professorService.updateProfessor(id, professor);
return "Updated professor with id: " + id;
}
However, the endpoint is not invoking as the logger doesn't log anything in the console. I tried with Postman and it did make call to the endpoint. Am I doing anything wrong, I would also provide any info if this post is not specific enough.
UPDATE: I called the addProfessorRating by the onSubmit function from Angular form:
onSubmit(rating: Object) {
const id = this.route.snapshot.paramMap.get('id');
this.professorService.addProfessorRating(id, rating);
}
I would appreciate any help.