KEYCLOAK-5160 Use setParameter in photoz-restful-api example services
This commit is contained in:
parent
db269e28d6
commit
81c0e62d79
2 changed files with 3 additions and 3 deletions
|
@ -83,14 +83,14 @@ public class AlbumService {
|
|||
@GET
|
||||
@Produces("application/json")
|
||||
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
|
||||
@Path("{id}")
|
||||
@Produces("application/json")
|
||||
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()) {
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
|
|
|
@ -43,7 +43,7 @@ public class ProfileService {
|
|||
@Produces("application/json")
|
||||
public Response view(@Context HttpServletRequest request) {
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue