Chciałem napisać API z podstawowymi metodmi w Javie z użyciem Quarkusa i mam problem przy endpoincie GET z parametrem id. Nie wiem czemu nie zwraca mi obiektu z id 1, przy zapytaniu typu GET - localhost:8080/hello/1 .
package org.acme;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@Path("/hello")
@Produces(MediaType.APPLICATION_JSON)
public class ExampleResource {
private List<Car> carList;
public ExampleResource() {
this.carList = new ArrayList<>();
this.carList.add(new Car(1, "Audi", 290000));
this.carList.add(new Car(2, "Opel", 12200));
}
@GET
public List<Car> getCarList() {
return this.carList;
}
@GET
@Path("/{id}")
public List<Car> getCarListById(@PathParam("id") Integer id) {
List<Car> new_list = new ArrayList<>();
for(Car car: carList){
if(car.getId() == id)
new_list.add(car);
}
return new_list;
}
@POST
public void addCar(Car auto) { this.carList.add(auto);};
@DELETE
public List<Car> delete(Car deleted_car) {
carList.remove(deleted_car);
return carList;
}
}
package org.acme;
public class Car {
public Integer id;
private String name;
private Integer prize;
public Car() {
}
public Car(Integer id, String name, Integer prize) {
this.id = id;
this.name = name;
this.prize = prize;
}
public Integer getId() {
return id;
}
public String getName() {
return name;
}
public Integer getPrize() {
return prize;
}
}
Ponad to @DELETE też nie chce zadziałać, kiedy korzystając z Postman'a wysyłam zapytanie DELETE z obiektem JSON w body :
{
"id": 1,
"name": "Audi",
"prize": 290000
}