Skip to content

Commit

Permalink
fix counter
Browse files Browse the repository at this point in the history
  • Loading branch information
noemil12 committed Nov 27, 2023
1 parent b0a6e36 commit 1cfe80b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
@Repository
public interface SignalRepository extends ReactiveCrudRepository<SignalEntity, Long> {

@Query("select * from signal s where s.eservice_id= :eserviceId and s.signal_id BETWEEN :signalIdStart AND :signalIdEnd " +
"order by s.signal_id")
Flux<SignalEntity> findSignal(String eserviceId, Long signalIdStart, Long signalIdEnd);
@Query("select * from signal s where s.eservice_id= :eserviceId and s.signal_id >= :signalIdStart " +
"order by s.signal_id limit :size")
Flux<SignalEntity> findSignal(String eserviceId, Long signalIdStart, Long size);

@Query("select max(s.signal_id) from signal s where s.eservice_id= :eserviceId " +
"group by s.eservice_id")
Mono<Integer> maxSignal(String eserviceId);
@Query("select count (*) from signal s where s.eservice_id= :eserviceId")
Mono<Integer> countAllSignal(String eserviceId);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ public Mono<ResponseEntity<PaginationSignal>> getRequest(String eserviceId, Long
return this.signalService.pullSignal(principal.getPrincipalId(), eserviceId, signalId, finalSize)
.collectList()
.map(list -> ResponseEntity.status(finalStatus)
.body(toPagination(list, principalAndCounter.getT2())));
.body(toPagination(list)));
});
}


private PaginationSignal toPagination(List<Signal> list, Integer maxSignalId ) {
private PaginationSignal toPagination(List<Signal> list) {
PaginationSignal paginationSignal = new PaginationSignal();
paginationSignal.setSignals(list);
if (list == null || list.isEmpty()) paginationSignal.setLastSignalId(maxSignalId.longValue()-1);
if (list == null || list.isEmpty()) paginationSignal.setLastSignalId(null);
else {
paginationSignal.setLastSignalId(list.get(list.size()-1).getSignalId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,17 @@ public class SignalServiceImpl implements SignalService {

@Override
public Flux<Signal> pullSignal(String consumerId, String eServiceId, Long signalId, Long size) {
long finalSignalId = signalId;
long start = finalSignalId+1;
long end = finalSignalId+size;
long start = signalId+1;
return consumerService.getConsumerEservice(eServiceId, consumerId)
.switchIfEmpty(Mono.error(new PDNDGenericException(ExceptionTypeEnum.UNAUTHORIZED, ExceptionTypeEnum.UNAUTHORIZED.getMessage().concat(eServiceId), HttpStatus.FORBIDDEN)))
.flatMap(consumerEService -> organizationService.getEService(eServiceId, consumerEService.getDescriptorId()))
.doOnNext(eService -> log.info("Searching signals from {} to {}", start, end))
.flatMapMany(eservice -> signalRepository.findSignal(eServiceId, start, end))
.doOnNext(eService -> log.info("Searching signals from {} to {}", start, size))
.flatMapMany(eservice -> signalRepository.findSignal(eServiceId, start, size))
.map(signalMapper::toDto);
}

public Mono<Integer> counter(String eServiceId){
return signalRepository.maxSignal(eServiceId);
return signalRepository.countAllSignal(eServiceId);

}

Expand Down

0 comments on commit 1cfe80b

Please sign in to comment.