Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically add HAL endpoint links with custom PanacheEntityResource methods #43842

Closed
muItilingualism opened this issue Oct 12, 2024 · 4 comments · Fixed by #44214
Closed
Labels
area/panache kind/enhancement New feature or request
Milestone

Comments

@muItilingualism
Copy link

Description

In quarkus-hibernate-orm-rest-data-panache according to the docs you can add additional endpoints to your PanacheEntityResource interface like so:

@ResourceProperties
public interface PeopleResource extends PanacheEntityResource<Person, Long> {
    @GET
    @Path("/name/{name}")
    @Produces("application/json")
    default List<Person> findByName(@PathParam("name") String name) {
        return Person.find("name = :name", Collections.singletonMap("name", name)).list();
    }
}

Adding HAL support like so:

@ResourceProperties(hal = true)
public interface PeopleResource extends PanacheEntityResource<Person, Long> {
    @GET
    @Path("/name/{name}")
    @Produces({"application/json", "application/hal+json"})
    default List<Person> findByName(@PathParam("name") String name) {
        return Person.find("name = :name", Collections.singletonMap("name", name)).list();
    }
}

Note: also not sure why it is required to have the @Produces({...,"application/hal+json"}) since @ResourceProperties(hal = true) is defined.

However, this does not add the /name/{name} link.

Only the following default links are present

GET /person/name/John

{
  "_embedded": {
    "items": [
      {
        "id": 2,
        "name": "John",
        "_links": {
          "add": {
            "href": "http://localhost:8080/person"
          },
          "count": {
            "href": "http://localhost:8080/person/count"
          },
          "self": {
            "href": "http://localhost:8080/person/2"
          },
          "update": {
            "href": "http://localhost:8080/person/2"
          },
          "list": {
            "href": "http://localhost:8080/person"
          },
          "remove": {
            "href": "http://localhost:8080/person/2"
          }
        }
      }
    ]
  },
  "_links": {
    "add": {
      "href": "http://localhost:8080/person"
    },
    "count": {
      "href": "http://localhost:8080/person/count"
    },
    "list": {
      "href": "http://localhost:8080/person"
    }
  }
}

It would be great if it was possible to add new methods which were also automatically added to the hal links. Or perhaps a way to specify that it should be included in the links. I have had no luck trying to get this to work in other ways (quarkus-hal and quarkus-rest-links) in conjunction with the easy to use quarkus-hibernate-orm-rest-data-panache.

Implementation ideas

No response

@muItilingualism muItilingualism added the kind/enhancement New feature or request label Oct 12, 2024
Copy link

quarkus-bot bot commented Oct 12, 2024

/cc @FroMage (panache), @geoand (rest-data-panache), @loicmathieu (panache)

@geoand
Copy link
Contributor

geoand commented Oct 12, 2024

cc @Sgitario

@FroMage
Copy link
Member

FroMage commented Oct 17, 2024

It would indeed be nice. It would also be nice to make the @Produces inferred and automatic indeed.

@Sgitario
Copy link
Contributor

@muItilingualism @FroMage @geoand #44214 should address this.

@quarkus-bot quarkus-bot bot added this to the 3.17 - main milestone Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/panache kind/enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants