I read many blog and tutorial, but i didn't find delete operation in dropwizard web services.
Here is my code:
public class PersonDAO extends AbstractDAO<Person> {
public PersonDAO(SessionFactory factory) {
super(factory);
}
public Optional<Person> findById(Long id) {
return Optional.fromNullable(get(id));
}
public Person create(Person person) {
return persist(person);
}
public List<Person> findAll() {
return list(namedQuery("com.example.helloworld.core.Person.findAll"));
}
//here i want to create delete method
}
here is my service file:
@Path("/people")
@Produces(MediaType.APPLICATION_JSON)
public class PeopleResource {
private final PersonDAO peopleDAO;
public PeopleResource(PersonDAO peopleDAO) {
this.peopleDAO = peopleDAO;
}
@POST
@UnitOfWork
public Person createPerson(Person person) {
return peopleDAO.create(person);
}
@GET
@UnitOfWork
public List<Person> listPeople() {
return peopleDAO.findAll();
}
@GET
@Path("/{id}")
public Optional<Person> getUser(@PathParam("id") Integer id) {
Optional<Person> person = peopleDAO.findPeopleById(id);
return person;
}
//here i add to delete method that call to dao class
}
If anyone have an idea please suggest me, thanks in advance.
Try to do in DAO:
public void delete(Person person){
currentSession().delete(person);
}
How about using a @DELETE method?
@DELETE
@Path("/{id}")
public void delete(@PathParam("id") IntParam id) {
peopleDAO.deleteById(id.get());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With