On the backend I have the POST method which works fine through postman using this url:
http://localhost:8087/termine/updateProduct/1
However in angular it throws error (on IDE - visual studio code) An argument for 'product' was not provided for my updateProduct method:
updateProduct(id: number, product: Product): Observable<Product> {
return this.http.post<Product>(`${this.baseUrl}/updateProduct/${id}`, product);
}
Here is the code in backend/API:
@PostMapping("updateProduct/{productId}")
public boolean updateProduct(@RequestBody Product productDetails,@PathVariable("productId") String productId) throws JsonProcessingException, ProductExistsException{
boolean result= productService.updateProduct(productDetails, productId);
return result;
}
All the rest of these methods work fine:
getAllProducts(){
return this.http.get<Product[]>(this.baseUrl "/getAllProducts");
}
addProduct(product: Product): Observable<Product>{
return this.http.post<Product>(this.baseUrl "/addProduct", product);
}
deleteProduct(id: number):Observable<{}>{
return this.http.delete(`${this.baseUrl}/deleteProduct/${id}`);
}
getProductById(id: number){
return this.http.get<Product>(`${this.baseUrl}/getProductById/${id}`);
CodePudding user response:
You check API: updateProduct (method: Put or post) if method = Put
updateProduct(id: number, product: Product): Observable<Product> {
return this.http.put(`${this.baseUrl}/updateProduct/${id}`, product);
}
CodePudding user response:
I was missing Product after http.post
updateProduct(id: number, product: Product): Observable<Product> {
return this.http.post<Product>(`${this.baseUrl}/updateProduct/${id}`, product);
}