-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
PanacheChildEntityResource #28450
Comments
/cc @FroMage, @loicmathieu |
cc @Sgitario |
I really like this enhancement. To elaborate on the implementation details, let's introduce this example: @Entity
public class Item extends PanacheEntity {
public String name;
public Resource resource;
}
@Entity
public class Resource extends PanacheEntity {
public String type;
public List<Item> items;
} At the moment, when having these two entities, Panache will expose the following endpoints:
And the idea of this feature is somehow to also expose the child entities like the resource field in the Item entity, so we can have the following additional endpoints:
The question now is how to configure the child entities to expose these additional resources. These are some options: a. Either use an interface or abstract class like PanacheChildEntityResource as suggested in the issue descriptionExample: @Entity
public class Resource extends PanacheEntity implements PanacheChildEntityResource {
public String type;
public List<Item> items;
} I don't like this approach because you could not expose the child entities for only one single resource, but for all. Also, the b. Or use a new annotation
|
Hi! Thanks for picking this up so quickly. I have no opinion on the implementation. I just would like to see a solution and best practice provided for the problem. Thanks! |
@geoand are you ok with proceeding with the second approach? |
Seems reasonable to me, but let's also see what @loicmathieu thinks |
UPDATE @ResourceProperties(subResources = { @SubResourceProperties(of = "resource") })
public interface ItemResource extends PanacheEntityResource<Item, Long> {
} Or using the repository: @ResourceProperties(subResources = { @SubResourceProperties(of = "resource") })
public interface ItemRepository extends PanacheRepositoryResource<Item, Long> {
} The additional benefit is that we keep the entity for persistence configuration only and the |
Also, for multiple child resources there would be a need for such a config anyway... |
Well, forgive me for ruining the party, but what is the real use-case here? What benefit do we have for getting nested resources by URI over fetching them from the parent? Or is it that they're not included in the parent representation? |
As far as I see it, the use case here is to individually customize the child entities' resources (sub-resources). For example, users want to secure the parent resource with the role "admin", but allow other roles like "user" to use the child's resources, so administrators can manage the parent entities and allow other issues with fewer permissions to list/add/remove/update the child entities. @gmuellerinform reported this related issue #28507 which goes in this direction. |
This doesn't ring true to me. In my experience, admins in small shops have every permission, while other users are restricted access based on ownership/permissions of the resource itself, which is never on static "roles". |
On the other hand, the example I introduced was very true to me. The idea is that users, using it in one way or the other, can use this extension.
Sorry, I don't understand your point here. I was not speaking about the complexity of doing this, but that users can't do this at the moment because we're not generating "/parent/1/subresources/1". However, I only wanted to give an example (the roles) of a real use case. Another point is that having to provide the whole entity to update one sub-resource entity, it's sub-optimal. Maybe, @gmuellerinform can share his use case here too, but I do think it's a good enhancement. |
I am just looking for an easy to use CRUD resource, which includes permissions and child management. Being able to define your Entities and spin up a complete and secure CRUD API would drastically improve productivity. |
OK, so what I understand here is that you don't want to expose the child resources as toplevel resources, because they only make sense as belonging to other parent resources? Like GitHub issues belonging to GitHub projects? Now, this makes a lot of sense to me. That's a use-case that is clear and justified. So, if you had the following entities: @Entity
public class Project extends PanacheBaseEntity {
@Id
public String name;
@OneToMany(mappedBy = "project")
public List<Issue> issues;
}
@Entity
public class Issue extends PanacheBaseEntity {
@Id
public long number;
@ManyToOne
public Project project;
}
public interface ProjectResource extends PanacheEntityResource<Project, String> {
} Then what would the representation look like for a given project with two entities? As it currently stands? |
It would look like /projetct/{project_id}/issues/{issued_id} I think this would be a nice way for the representation. Top-level children would be okay too, if there was a filter in the PanacheEntityResource, like /issues?project=1 My agenda is to promote Quarkus in my company and I would like to show a fully functional CRUD without any resource code. |
I was asking about the entity representation: what does the JSON look like ATM? |
Oh, sorry. I guess this depends on your API style?! I currently use @JsonIdentityReference(alwaysAsId = true) to return a list of ids:
With the nested routes, issues could be left out in the json as well, but this should be the developers choise?! I also plan to use JsonViews in future to let the client chose verbosity. |
OK, so we currently return the IDs. Up to the caller to know how to map them into a URI. I'd probably rather we return links to the issues, no? |
Hi! Sorry for the quiet time, was busy with other projects. @FroMage was aking for a use case earlier. One I encountered a couple of times now is "give me all issues for project X filtered by date". Currently I need to fetch the project, and query every issue. Even if the issues are exported, since I cannot query for the project in the issues resource (only primitive types accoding to the docs). So, the initially suggested sub resource is a way to allow this selection. But, being able to query for relations (via id) on the issues resource would actually be better, and maybe easier. Thank you for your time! |
Description
PanacheEntityResource already provides a nice and quick way to expose entities.
It would be great to have a PanacheChildEntityResource which uses the path parameter containing the parent id, so endpoints like
/product/1/variations
are possible.
Thanks!
Implementation ideas
No response
The text was updated successfully, but these errors were encountered: