Skip to content

Commit

Permalink
Merge pull request #440 from bcgov/feature/EDX-1941
Browse files Browse the repository at this point in the history
Endpoint to get program eligibility issue codes
  • Loading branch information
alexmcdermid authored Feb 8, 2024
2 parents 360ce58 + f2652a2 commit 69c6520
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ private URL(){
public static final String ZERO_FTE_REASON_CODES = "/zero-fte-reason-codes";
public static final String HEADCOUNTS = "/headcounts";
public static final String COLLECTION_TYPE_CODES = "/collection-type-codes";
public static final String PROGRAM_ELIGIBILITY_ISSUE_CODES = "/program-eligibility-issue-codes";

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ca.bc.gov.educ.studentdatacollection.api.controller.v1;

import ca.bc.gov.educ.studentdatacollection.api.constants.StudentValidationIssueTypeCode;
import ca.bc.gov.educ.studentdatacollection.api.constants.v1.ProgramEligibilityIssueCode;
import ca.bc.gov.educ.studentdatacollection.api.constants.v1.ZeroFteReasonCodes;
import ca.bc.gov.educ.studentdatacollection.api.endpoint.v1.CodeTableAPIEndpoint;
import ca.bc.gov.educ.studentdatacollection.api.mappers.v1.CodeTableMapper;
Expand Down Expand Up @@ -97,4 +98,15 @@ public List<ZeroFteReasonCode> getZeroFteReasonCodes() {
public List<CollectionTypeCode> getCollectionTypeCodes() {
return codeTableService.getCollectionCodeList().stream().map(mapper::toStructure).toList();
}

@Override
public List<ProgramEligibilityIssueTypeCode> getProgramEligibilityIssueCodes() {
return Arrays.stream(ProgramEligibilityIssueCode.values()).map(code -> {
ProgramEligibilityIssueTypeCode issue = new ProgramEligibilityIssueTypeCode();
issue.setProgramEligibilityIssueTypeCode(code.getCode());
issue.setMessage(code.getMessage());
return issue;
})
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,12 @@ public interface CodeTableAPIEndpoint {
@Tag(name = "Collection Codes", description = "Endpoints to get collection codes.")
@Schema(name = "CollectionTypeCodes", implementation = CollectionTypeCode.class)
List<CollectionTypeCode> getCollectionTypeCodes();

@PreAuthorize("hasAuthority('SCOPE_READ_COLLECTION_CODES')")
@GetMapping(URL.PROGRAM_ELIGIBILITY_ISSUE_CODES)
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
@Transactional(readOnly = true)
@Tag(name = "Collection Codes", description = "Endpoints to get collection codes.")
@Schema(name = "ProgramEligibilityIssueTypeCode", implementation = ProgramEligibilityIssueTypeCode.class)
List<ProgramEligibilityIssueTypeCode> getProgramEligibilityIssueCodes();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ca.bc.gov.educ.studentdatacollection.api.struct.v1;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@SuppressWarnings("squid:S1700")
public class ProgramEligibilityIssueTypeCode implements Serializable {
private static final long serialVersionUID = 6118916290604876032L;

private String programEligibilityIssueTypeCode;
private String message;
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,14 @@ void testGetCollectionTypeCodes_ShouldReturnCodes() throws Exception {
.andExpect(MockMvcResultMatchers.jsonPath("$[0].collectionTypeCode").value("SEPTEMBER"))
.andExpect(MockMvcResultMatchers.jsonPath("$").isArray());
}

@Test
void testGetProgramEligibilityIssueCodes_ShouldReturnCodes() throws Exception {
final GrantedAuthority grantedAuthority = () -> "SCOPE_READ_COLLECTION_CODES";
final SecurityMockMvcRequestPostProcessors.OidcLoginRequestPostProcessor mockAuthority = oidcLogin().authorities(grantedAuthority);

this.mockMvc.perform(get(URL.BASE_URL + URL.PROGRAM_ELIGIBILITY_ISSUE_CODES).with(mockAuthority)).andDo(print()).andExpect(status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$[0].programEligibilityIssueTypeCode").value("HOMESCHOOL"))
.andExpect(MockMvcResultMatchers.jsonPath("$").isArray());
}
}

0 comments on commit 69c6520

Please sign in to comment.