Reputation: 45
I am trying to learn using ReactiveMongoClient on a Quarkus framework.
I am partly successful with sending a response as Uni>
@GET
@Path("/unpaginated")
public Uni<List<Staff>> unpaginatedStaffList() {
return staffService.getStaffResponse();
}
But when I try to get an object of some other class (StaffResponse) to include a Link object for pagination, I am not getting any Staff record. (For now I have hardcoded Link for pagination )
@GET
@Path("/paginated")
public StaffResponse paginatedStaffList() {
List<Link> links = LinkService.getLinks("/staff?page=2&limit=20", "next");
Uni<List<Staff>> staff = (Uni<List<Staff>>) staffService.getStaffResponse();
return new StaffResponse(links, staff);
}
"staff" is empty in the response.
MongoClient is returning list of Staff ok, looks like the Response object is not getting the list. Tried reading SmallRye Mutiny documentations - could not work out.
Please help.
I have committed the code at: https://github.com/doepradhan/staffApi and a sample json data file (https://github.com/doepradhan/staffApi/blob/master/sample-staff-data.json)
Thank you heaps for you kind help.
Upvotes: 4
Views: 8164
Reputation: 1213
You can't mix up two approaches. You need to use Uni
as an output for the endpoint. That means that you need to convert both input sources into Uni, combine them, and map into StaffResponse
.
LinkService
to return Uni(or use Uni.createFrom().item(links))public StaffResponse(List<Link> links, List<Staff> staff) {
this.links = links;
this.staff = staff;
}
Uni<Tuple>
, map it then to StaffResponse
: @GET
@Path("/paginated")
public Uni<StaffResponse> paginatedStaffList() {
final Uni<List<Link>> links =
Uni.createFrom().item(LinkService.getLinks("/staff?page=2&limit=20", "next"));
Uni<List<Staff>> staff = staffService.getStaffResponse();
return staff.and(links).map(it -> new StaffResponse(it.getItem2(), it.getItem1()));
}
I created a working PR here
Upvotes: 5