What would the @DELETE methods of a Restfull java api look like?

Asked

Viewed 75 times

0

I’m using the FullEntityRepository of deltaspike, the Response has to be a status 204 if successful, and status 400 if not. Any tips? Service layer:

@Transactional
public void deletar(Integer id){
  MotivoConcessao motivoConcessaoParaDeletar = repositorio.findBy(id);
  repositorio.remove(motivoConcessaoParaDeletar);
}

Camada resource:
@DELETE
@Path("{id}")
public Response deletar(@PathParam("id") @Min(value = 1, message = "{recursomotivoconcessao.id.min}") Integer id) {
  return Response.status(204).entity(servico.deletar(id)).build();
}
  • The variable repositorio is of what class?

  • And the Fullentityrepository guy, the deltaspike. You can help me with that?

1 answer

0


According to the documentation of Deltaspike, the method remove evokes the method remove class EntityManager. Like the method of the last spear a IllegalArgumentException if it fails, you could try to capture this exception and, if it does, send the reply with the desired status. Example:

@DELETE
@Path("{id}")
public Response deletar(@PathParam("id") 
                        @Min(value = 1, message = "{ recursomotivoconcessao.id.min}") 
                        Integer id) {
    try {
        servico.deletar(id);
    } catch (IllegalArgumentException e) {
         return Response.status(409).build();
    }
    return Response.status(204).build();
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.