Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Apr 11, 2024
1 parent 0ea6560 commit 9f3c254
Showing 1 changed file with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,32 +58,31 @@ public Optional<CustomerResponse> findCustomerById(Long id) {
}

public List<RevisionResult> findCustomerRevisionsById(Long id) {
List<CompletableFuture<RevisionResult>> revisionDtoCF = customerRepository
List<CompletableFuture<RevisionResult>> revisionCFList = customerRepository
.findRevisions(id)
.get()
.map(customerRevision -> CompletableFuture.supplyAsync(
() -> customerRevisionToRevisionDTOMapper.convert(customerRevision)))
.toList();
return revisionDtoCF.stream().map(CompletableFuture::join).toList();
return revisionCFList.stream().map(CompletableFuture::join).toList();
}

public PagedResult<RevisionResult> findCustomerHistoryById(Long id, Pageable pageRequest) {
if (customerRepository.findById(id).isEmpty()) {
throw new CustomerNotFoundException(id);
}

RevisionSort sortDir;
Optional<Sort.Direction> direction =
pageRequest.getSort().stream().map(Sort.Order::getDirection).findFirst();
if (direction.isPresent()) {
if (Sort.Direction.ASC.name().equalsIgnoreCase(direction.get().name())) {
sortDir = RevisionSort.asc();
} else {
sortDir = RevisionSort.desc();
}
} else {
sortDir = RevisionSort.desc();
}
RevisionSort sortDir = pageRequest.getSort().stream()
.map(Sort.Order::getDirection)
.findFirst()
.map(direction -> {
if (Sort.Direction.ASC.name().equalsIgnoreCase(direction.name())) {
return RevisionSort.asc();
} else {
return RevisionSort.desc();
}
})
.orElse(RevisionSort.desc());

Pageable pageable = PageRequest.of(pageRequest.getPageNumber(), pageRequest.getPageSize(), sortDir);
Page<Revision<Integer, Customer>> customerRevisions = customerRepository.findRevisions(id, pageable);
Expand Down

0 comments on commit 9f3c254

Please sign in to comment.