Skip to content

Commit

Permalink
[INJIVEr-587] - only sending status now
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 065747e commit 20eea82
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package io.inji.verify.controller;

import io.inji.verify.dto.authorizationrequest.StatusDto;
import io.inji.verify.dto.authorizationrequest.VPRequestCreateDto;
import io.inji.verify.dto.authorizationrequest.VPRequestResponseDto;
import io.inji.verify.enums.Status;
import io.inji.verify.enums.SubmissionStatus;
import io.inji.verify.spi.VerifiablePresentationRequestService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -28,12 +29,12 @@ public ResponseEntity<VPRequestResponseDto> createVPRequest(@Valid @RequestBody
}

@GetMapping(path = "/{requestId}/status")
public ResponseEntity<StatusDto> getStatus(@PathVariable String requestId) {
public ResponseEntity<Status> getStatus(@PathVariable String requestId) {

StatusDto statusDto = verifiablePresentationRequestService.getCurrentRequestState(requestId);
if (statusDto == null)
Status status = verifiablePresentationRequestService.getCurrentRequestStatus(requestId);
if (status == null)
return new ResponseEntity<>(null, HttpStatus.NOT_FOUND);

return new ResponseEntity<>(statusDto, HttpStatus.OK);
return new ResponseEntity<>(status, HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package io.inji.verify.controller;

import io.inji.verify.dto.authorizationrequest.StatusDto;
import io.inji.verify.dto.submission.PresentationSubmissionDto;
import io.inji.verify.dto.submission.ResponseAcknowledgementDto;
import io.inji.verify.dto.submission.VPSubmissionDto;
import io.inji.verify.dto.submission.VPTokenResultDto;
import io.inji.verify.enums.SubmissionState;
import io.inji.verify.enums.Status;
import io.inji.verify.shared.Constants;
import io.inji.verify.spi.VerifiablePresentationRequestService;
import io.inji.verify.spi.VerifiablePresentationSubmissionService;
Expand All @@ -31,9 +30,9 @@ public class VPSubmissionController {
@GetMapping(path = "/vp-result/{transactionId}")
public ResponseEntity<VPTokenResultDto> getVPResult(@PathVariable String transactionId) {
String requestId = verifiablePresentationRequestService.getLatestRequestIdFor(transactionId);
StatusDto authRequestState = verifiablePresentationRequestService.getCurrentRequestState(requestId);
Status currentStatus = verifiablePresentationRequestService.getCurrentRequestStatus(requestId);

if (transactionId.isEmpty() || authRequestState.getStatus() != SubmissionState.COMPLETED) {
if (transactionId.isEmpty() || currentStatus != Status.COMPLETED) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}

Expand All @@ -50,8 +49,8 @@ public ResponseEntity<ResponseAcknowledgementDto> submitVP(@RequestParam(value =
VPSubmissionDto vpSubmissionDto = new VPSubmissionDto(vpToken, presentationSubmissionDto, state);
verifiablePresentationSubmissionService.submit(vpSubmissionDto);

StatusDto authRequestState = verifiablePresentationRequestService.getCurrentRequestState(vpSubmissionDto.getState());
if (authRequestState == null) {
Status currentStatus = verifiablePresentationRequestService.getCurrentRequestStatus(vpSubmissionDto.getState());
if (currentStatus == null) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.inji.verify.enums;

public enum SubmissionState {
public enum Status {
PENDING,
COMPLETED,
PARTIALLY_COMPLETED,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package io.inji.verify.services;

import io.inji.verify.dto.authorizationrequest.AuthorizationRequestResponseDto;
import io.inji.verify.dto.authorizationrequest.StatusDto;
import io.inji.verify.dto.authorizationrequest.VPRequestCreateDto;
import io.inji.verify.dto.authorizationrequest.VPRequestResponseDto;
import io.inji.verify.dto.presentation.PresentationDefinitionDto;
import io.inji.verify.enums.SubmissionState;
import io.inji.verify.enums.Status;
import io.inji.verify.models.AuthorizationRequestCreateResponse;
import io.inji.verify.models.PresentationDefinition;
import io.inji.verify.models.VPSubmission;
Expand Down Expand Up @@ -53,20 +52,20 @@ public VPRequestResponseDto createAuthorizationRequest(VPRequestCreateDto vpRequ
}

@Override
public StatusDto getCurrentRequestState(String requestId) {
public Status getCurrentRequestStatus(String requestId) {
VPSubmission vpSubmission = vpSubmissionRepository.findById(requestId).orElse(null);

if (vpSubmission != null) {
return new StatusDto(SubmissionState.COMPLETED);
return Status.COMPLETED;
}
Long expiresAt = authorizationRequestCreateResponseRepository.findById(requestId).map(AuthorizationRequestCreateResponse::getExpiresAt).orElse(null);
if (expiresAt == null){
return null;
}
if(Instant.now().toEpochMilli() > expiresAt){
return new StatusDto(SubmissionState.EXPIRED);
return Status.EXPIRED;
}
return new StatusDto(SubmissionState.PENDING);
return Status.PENDING;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.inji.verify.spi;

import io.inji.verify.dto.authorizationrequest.StatusDto;
import io.inji.verify.dto.authorizationrequest.VPRequestCreateDto;
import io.inji.verify.dto.authorizationrequest.VPRequestResponseDto;
import io.inji.verify.enums.Status;

public interface VerifiablePresentationRequestService {
VPRequestResponseDto createAuthorizationRequest(VPRequestCreateDto vpRequestCreate);

StatusDto getCurrentRequestState(String requestId);
Status getCurrentRequestStatus(String requestId);
String getTransactionIdFor(String requestId);
String getLatestRequestIdFor(String transactionId);
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package io.inji.verify.services;

import io.inji.verify.dto.authorizationrequest.StatusDto;
import io.inji.verify.dto.authorizationrequest.VPRequestCreateDto;
import io.inji.verify.dto.authorizationrequest.VPRequestResponseDto;
import io.inji.verify.dto.presentation.InputDescriptorDto;
import io.inji.verify.dto.presentation.PresentationDefinitionDto;
import io.inji.verify.dto.presentation.SubmissionRequirementDto;
import io.inji.verify.repository.AuthorizationRequestCreateResponseRepository;
import io.inji.verify.repository.PresentationDefinitionRepository;
import io.inji.verify.enums.SubmissionState;
import io.inji.verify.enums.Status;
import io.inji.verify.models.AuthorizationRequestCreateResponse;
import io.inji.verify.models.PresentationDefinition;
import io.inji.verify.repository.VPSubmissionRepository;
Expand Down Expand Up @@ -82,9 +81,9 @@ public void shouldGetCurrentAuthorizationRequestStateForExistingRequest() {
when(mockAuthorizationRequestCreateResponseRepository.findById("req_id")).thenReturn(java.util.Optional.of(mockResponse));
when(mockVPSubmissionRepository.findById("req_id")).thenReturn(Optional.empty());

StatusDto state = service.getCurrentRequestState("req_id");
Status status = service.getCurrentRequestStatus("req_id");

assertEquals(SubmissionState.PENDING, state.getStatus());
assertEquals(Status.PENDING, status);
}

@Test
Expand All @@ -94,8 +93,8 @@ public void shouldGetCurrentAuthorizationRequestStateForNonexistentRequest() {
when(mockAuthorizationRequestCreateResponseRepository.findById("req_id")).thenReturn(java.util.Optional.of(mockResponse));


StatusDto state = service.getCurrentRequestState("nonexistent_id");
Status status = service.getCurrentRequestStatus("nonexistent_id");

assertNull(state);
assertNull(status);
}
}

0 comments on commit 20eea82

Please sign in to comment.