我有一个使用 Quarkus、Panache 和 MapStruct 的休息 Api ...返回这个对象
// DTO
public ResponseObjectList(int itemsCount, List<T> items) {
super();
this.itemsCount = itemsCount;
this.items = items;
}
// RESOURCE
@GET
public Response getClubs() {
ResponseObjectList<ClubDTO> allClubs = clubService.getAll();
if (allClubs == null || allClubs.size() == 0) {
throw new NotFoundException("Clubs Not Found");
}
return Response.status(Response.Status.OK).entity(allClubs).build();
}
// SERVICE
public ResponseObjectList<ClubDTO> getAll() {
List<ClubDTO> results = new ArrayList<ClubDTO>();
Stream<Club> clubs = Club.streamAll();
results = clubs.map(club -> clubMapper.toDto(club)).collect(Collectors.toList());
return new ResponseObjectList<ClubDTO>(results.size(), results);
}
// MAPSTRUCT MAPPER
default ClubDTO toDto(Club club) {
ClubDTO _club = new ClubDTO();
_club.setId(club.id);
_club.setName(club.name);
_club.setAddress(club.address);
_club.setCity(club.city);
_club.setZipCode(club.zipCode);
_club.setInscriptionEmail(club.inscriptionEmail);
_club.setInfoEmail(club.infoEmail);
_club.setTelephone(club.telephone);
return _club;
}
我的愿望是将其转换为反应式方法。所以类似的东西......
@GET
public Uni<Response> getClubs() {
return clubService.getAll();
}
public Uni<ResponseObjectList<ClubDTO>> getAll() {
// using MapStruct and build an objet with size and details
return Club.listAll() (...)
}
你能告诉我这是否可能吗?我不知道如何构建我的 Dto 对象……您是否遇到过同样的“困难”?如果是这样,您是如何解决的。
谢谢