Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legal entity new endpoint #99

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@ interface GateLegalEntityApi {
@GetExchange("/input/legal-entities/{externalId}")
fun getLegalEntityByExternalId(@Parameter(description = "External identifier") @PathVariable externalId: String): LegalEntityGateInputResponse

@Operation(
summary = "Get page of legal-entities filtered by a collection of externalIds",
description = "Get page of legal-entities filtered by a collection of externalIds."
)
@ApiResponses(
value = [
ApiResponse(responseCode = "200", description = "The requested page of legal-entities"),
ApiResponse(responseCode = "400", description = "On malformed pagination request", content = [Content()]),
]
)
@PostMapping("/input/legal-entities/search")
@PostExchange("/input/legal-entities/search")
fun getLegalEntitiesByExternalIds(
@ParameterObject @Valid paginationRequest: PaginationStartAfterRequest,
@RequestBody externalIds: Collection<String>
): PageStartAfterResponse<LegalEntityGateInputResponse>

@Operation(
summary = "Get page of legal entities",
description = "Get page of legal entities."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ class LegalEntityController(
return legalEntityService.getLegalEntityByExternalId(externalId)
}

override fun getLegalEntitiesByExternalIds(
paginationRequest: PaginationStartAfterRequest,
externalIds: Collection<String>
): PageStartAfterResponse<LegalEntityGateInputResponse> {
return legalEntityService.getLegalEntities(limit = paginationRequest.limit, startAfter = paginationRequest.startAfter, externalIds = externalIds)
}

override fun getLegalEntities(paginationRequest: PaginationStartAfterRequest): PageStartAfterResponse<LegalEntityGateInputResponse> {
return legalEntityService.getLegalEntities(paginationRequest.limit, paginationRequest.startAfter)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class LegalEntityService(
}
}

fun getLegalEntities(limit: Int, startAfter: String?): PageStartAfterResponse<LegalEntityGateInputResponse> {
val partnerCollection = saasClient.getLegalEntities(limit, startAfter)
fun getLegalEntities(limit: Int, startAfter: String?, externalIds: Collection<String>? = null): PageStartAfterResponse<LegalEntityGateInputResponse> {
val partnerCollection = saasClient.getLegalEntities(limit, startAfter, externalIds)

val validEntries = toValidLegalEntities(partnerCollection.values)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,63 @@ internal class LegalEntityControllerInputIT @Autowired constructor(
)
}


/**
* Given legal entity exists in SaaS
* When getting legal entities page based on external id list
* Then legal entities page mapped to the catena data model should be returned
*/
@Test
fun `get legal entity filter by external ids`() {
val legalEntitiesSaas = listOf(
SaasValues.legalEntityResponse1,
SaasValues.legalEntityResponse2,
)

val expectedLegalEntities = listOf(
ResponseValues.legalEntityGateInputResponse1,
ResponseValues.legalEntityGateInputResponse2,
)

val limit = 2
val startAfter = "Aaa111"
val nextStartAfter = "Aaa222"
val total = 10
val invalidEntries = 0

wireMockServer.stubFor(
get(urlPathMatching(SAAS_MOCK_BUSINESS_PARTNER_PATH))
.willReturn(
aResponse()
.withHeader("Content-Type", "application/json")
.withBody(
objectMapper.writeValueAsString(
PagedResponseSaas(
limit = limit,
startAfter = startAfter,
nextStartAfter = nextStartAfter,
total = total,
values = legalEntitiesSaas
)
)
)
)
)

val paginationValue = PaginationStartAfterRequest(startAfter, limit)
val listExternalIds = legalEntitiesSaas.mapNotNull { it.externalId }
val pageResponse = gateClient.legalEntities().getLegalEntitiesByExternalIds(paginationValue, listExternalIds)

assertThat(pageResponse).isEqualTo(
PageStartAfterResponse(
total = total,
nextStartAfter = nextStartAfter,
content = expectedLegalEntities,
invalidEntries = invalidEntries
)
)
}

/**
* Given legal entity without legal address in SaaS
* When getting legal entities page
Expand Down