Skip to content

Commit

Permalink
[INJIVER-587] - refactor logic of getting latest submission
Browse files Browse the repository at this point in the history
Signed-off-by: Sreenadh S <[email protected]>
  • Loading branch information
sree96 committed Dec 23, 2024
1 parent fdb3c18 commit 10fa0df
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class VPSubmissionController {

Expand All @@ -30,14 +32,13 @@ public class VPSubmissionController {

@GetMapping(path = "/vp-result/{transactionId}")
public ResponseEntity<VPTokenResultDto> getVPResult(@PathVariable String transactionId) {
String requestId = verifiablePresentationRequestService.getLatestRequestIdFor(transactionId);
VPRequestStatusDto currentVPRequestStatusDto = verifiablePresentationRequestService.getCurrentRequestStatus(requestId);
List<String> requestIds = verifiablePresentationRequestService.getLatestRequestIdFor(transactionId);

if (transactionId.isEmpty() || currentVPRequestStatusDto.getStatus() != VPRequestStatus.COMPLETED) {
if (requestIds.isEmpty()) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}

VPTokenResultDto result = verifiablePresentationSubmissionService.getVPResult(requestId,transactionId);
VPTokenResultDto result = verifiablePresentationSubmissionService.getVPResult(requestIds,transactionId);
if (result != null) {
return new ResponseEntity<>(result, HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import jakarta.validation.constraints.NotNull;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;

public interface AuthorizationRequestCreateResponseRepository extends JpaRepository<AuthorizationRequestCreateResponse, String> {
Optional<AuthorizationRequestCreateResponse> findFirstByTransactionIdOrderByExpiresAtDesc(@NotNull String transactionId);
List<AuthorizationRequestCreateResponse> findAllByTransactionIdOrderByExpiresAtDesc(@NotNull String transactionId);
}

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.springframework.stereotype.Service;

import java.time.Instant;
import java.util.List;

@Service
public class VerifiablePresentationRequestServiceImpl implements VerifiablePresentationRequestService {
Expand Down Expand Up @@ -75,7 +76,7 @@ public String getTransactionIdFor(String requestId) {
}

@Override
public String getLatestRequestIdFor(String transactionId) {
return authorizationRequestCreateResponseRepository.findFirstByTransactionIdOrderByExpiresAtDesc(transactionId).map(AuthorizationRequestCreateResponse::getRequestId).orElse(null);
public List<String> getLatestRequestIdFor(String transactionId) {
return authorizationRequestCreateResponseRepository.findAllByTransactionIdOrderByExpiresAtDesc(transactionId).stream().map(AuthorizationRequestCreateResponse::getRequestId).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ private VPTokenResultDto processSubmission(VPSubmission vpSubmission, String tra
}

@Override
public VPTokenResultDto getVPResult(String requestId, String transactionId) {
VPSubmission vpSubmission = vpSubmissionRepository.findById(requestId).orElse(null);
public VPTokenResultDto getVPResult(List<String> requestIds, String transactionId) {
VPSubmission vpSubmission = vpSubmissionRepository.findAllById(requestIds).getFirst();

if (vpSubmission == null){
return new VPTokenResultDto(transactionId, VPResultStatus.NOT_SUBMITTED,null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import io.inji.verify.dto.authorizationrequest.VPRequestResponseDto;
import io.inji.verify.dto.authorizationrequest.VPRequestStatusDto;

import java.util.List;

public interface VerifiablePresentationRequestService {
VPRequestResponseDto createAuthorizationRequest(VPRequestCreateDto vpRequestCreate);

VPRequestStatusDto getCurrentRequestStatus(String requestId);
String getTransactionIdFor(String requestId);
String getLatestRequestIdFor(String transactionId);
List<String> getLatestRequestIdFor(String transactionId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import io.inji.verify.dto.submission.VPSubmissionDto;
import io.inji.verify.dto.submission.VPTokenResultDto;

import java.util.List;

public interface VerifiablePresentationSubmissionService {
ResponseAcknowledgementDto submit(VPSubmissionDto vpSubmissionDto);

VPTokenResultDto getVPResult(String requestId, String transactionId);
VPTokenResultDto getVPResult(List<String> requestId, String transactionId);
}

0 comments on commit 10fa0df

Please sign in to comment.