KEYCLOAK-5160 Use setParameter in photoz-restful-api example services

This commit is contained in:
Alex Szczuczko 2017-07-06 10:22:10 -06:00
parent db269e28d6
commit 81c0e62d79
2 changed files with 3 additions and 3 deletions

View file

@ -83,14 +83,14 @@ public class AlbumService {
@GET @GET
@Produces("application/json") @Produces("application/json")
public Response findAll() { public Response findAll() {
return Response.ok(this.entityManager.createQuery("from Album where userId = '" + request.getUserPrincipal().getName() + "'").getResultList()).build(); return Response.ok(this.entityManager.createQuery("from Album where userId = :id").setParameter("id", request.getUserPrincipal().getName()).getResultList()).build();
} }
@GET @GET
@Path("{id}") @Path("{id}")
@Produces("application/json") @Produces("application/json")
public Response findById(@PathParam("id") String id) { public Response findById(@PathParam("id") String id) {
List result = this.entityManager.createQuery("from Album where id = " + id).getResultList(); List result = this.entityManager.createQuery("from Album where id = :id").setParameter("id", id).getResultList();
if (result.isEmpty()) { if (result.isEmpty()) {
return Response.status(Status.NOT_FOUND).build(); return Response.status(Status.NOT_FOUND).build();

View file

@ -43,7 +43,7 @@ public class ProfileService {
@Produces("application/json") @Produces("application/json")
public Response view(@Context HttpServletRequest request) { public Response view(@Context HttpServletRequest request) {
Principal userPrincipal = request.getUserPrincipal(); Principal userPrincipal = request.getUserPrincipal();
List albums = this.entityManager.createQuery("from Album where userId = '" + userPrincipal.getName() + "'").getResultList(); List albums = this.entityManager.createQuery("from Album where userId = :id").setParameter("id", userPrincipal.getName()).getResultList();
return Response.ok(new Profile(userPrincipal.getName(), albums.size())).build(); return Response.ok(new Profile(userPrincipal.getName(), albums.size())).build();
} }