Skip to content

Commit

Permalink
Add application status from mandatory question ID
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-tco committed Jan 22, 2024
1 parent 96d1617 commit f2fff63
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import gov.cabinetoffice.gap.applybackend.dto.api.UpdateGrantMandatoryQuestionDto;
import gov.cabinetoffice.gap.applybackend.enums.GrantMandatoryQuestionStatus;
import gov.cabinetoffice.gap.applybackend.mapper.GrantMandatoryQuestionMapper;
import gov.cabinetoffice.gap.applybackend.model.GrantApplicant;
import gov.cabinetoffice.gap.applybackend.model.GrantMandatoryQuestions;
import gov.cabinetoffice.gap.applybackend.model.GrantScheme;
import gov.cabinetoffice.gap.applybackend.model.Submission;
import gov.cabinetoffice.gap.applybackend.model.*;
import gov.cabinetoffice.gap.applybackend.service.GrantApplicantService;
import gov.cabinetoffice.gap.applybackend.service.GrantMandatoryQuestionService;
import gov.cabinetoffice.gap.applybackend.service.GrantSchemeService;
Expand All @@ -25,8 +22,11 @@

import javax.validation.Valid;
import java.time.Instant;
import java.util.Objects;
import java.util.UUID;

import static gov.cabinetoffice.gap.applybackend.utils.SecurityContextHelper.getUserIdFromSecurityContext;

@RequiredArgsConstructor
@RestController
@RequestMapping("/grant-mandatory-questions")
Expand Down Expand Up @@ -156,4 +156,14 @@ public ResponseEntity<String> updateMandatoryQuestion(@PathVariable final UUID m

return ResponseEntity.ok(grantMandatoryQuestionService.generateNextPageUrl(url, mandatoryQuestionId, jwtPayload.getSub()));
}

@GetMapping("/{mandatoryQuestionId}/application/status")
public ResponseEntity<String> getApplicationStatusByMandatoryQuestionId(@PathVariable final UUID mandatoryQuestionId) {
final JwtPayload jwtPayload = (JwtPayload) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

final GrantMandatoryQuestions grantMandatoryQuestions = grantMandatoryQuestionService.getGrantMandatoryQuestionById(mandatoryQuestionId, jwtPayload.getSub());
final GrantApplication grantApplication = grantMandatoryQuestions.getGrantScheme().getGrantApplication();

return ResponseEntity.ok(grantApplication.getApplicationStatus().name());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import gov.cabinetoffice.gap.applybackend.dto.api.GetGrantMandatoryQuestionDto;
import gov.cabinetoffice.gap.applybackend.dto.api.JwtPayload;
import gov.cabinetoffice.gap.applybackend.dto.api.UpdateGrantMandatoryQuestionDto;
import gov.cabinetoffice.gap.applybackend.enums.GrantApplicationStatus;
import gov.cabinetoffice.gap.applybackend.enums.GrantMandatoryQuestionFundingLocation;
import gov.cabinetoffice.gap.applybackend.enums.GrantMandatoryQuestionOrgType;
import gov.cabinetoffice.gap.applybackend.enums.GrantMandatoryQuestionStatus;
Expand Down Expand Up @@ -347,4 +348,29 @@ void shouldReturnTrueIfUserHasMandatoryQuestionsForValidSchemeId() {

}

@Test
void shouldReturnApplicationStatusFromQuestionUUID() {

final GrantApplication application = GrantApplication.builder()
.id(1)
.applicationStatus(GrantApplicationStatus.REMOVED)
.build();
final GrantScheme scheme = GrantScheme.builder()
.id(schemeId)
.grantApplication(application)
.build();

final GrantMandatoryQuestions mandatoryQuestions = GrantMandatoryQuestions.builder()
.id(MANDATORY_QUESTION_ID)
.grantScheme(scheme)
.createdBy(applicant)
.build();

when(grantMandatoryQuestionService.getGrantMandatoryQuestionById(MANDATORY_QUESTION_ID, jwtPayload.getSub()))
.thenReturn(mandatoryQuestions);

final ResponseEntity<String> methodResponse = controllerUnderTest.getApplicationStatusByMandatoryQuestionId(MANDATORY_QUESTION_ID);
assertThat(methodResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(methodResponse.getBody()).isEqualTo("REMOVED");
}
}

0 comments on commit f2fff63

Please sign in to comment.