Skip to content

Commit

Permalink
[BTD-292] Added keyword filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
paddynski-moj committed Feb 26, 2025
1 parent 09ae1b2 commit 60b5cf3
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 9 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ Example request body:
"uln": "1174112637",
// below are optional fields
"dateOfBirth": "1980-11-01",
"gender": "MALE"
"gender": "MALE",
"keywords": ["english"]
}
```

Expand All @@ -186,7 +187,8 @@ Example response body:
"familyName": "Findlay",
"uln": "1174112637",
"dateOfBirth": "1980-11-01",
"gender": "MALE"
"gender": "MALE",
"keywords": ["english"]
},
"responseType": "Exact Match",
"foundUln": "1174112637",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,14 @@ data class LearningEvent(

@get:XmlElement(name = "LanguageForAssessment", namespace = "http://api.lrs.qcf.gov.uk/model")
var languageForAssessment: String? = null,
)
) {
fun isSubjectOneOf(keywords: List<String>): Boolean {
val subject = this.subject ?: ""
if (subject.isBlank()) {
return false
} else if (keywords.isEmpty()) {
return true
}
return keywords.any { keyword -> subject.contains(keyword, ignoreCase = true) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class LearnerEventsRequest(

@SerializedName("gender")
val gender: Gender? = null,

@SerializedName("keywords")
val keywords: List<String> = listOf(),
) {
fun extractFromRequest(): LearnerEventsLRSRequest = LearnerEventsLRSRequest(
givenName = givenName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import io.swagger.v3.oas.annotations.media.Schema
import io.swagger.v3.oas.annotations.parameters.RequestBody
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.security.SecurityRequirement
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.LearnerEventsRequest
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.response.LearnerEventsResponse
import uk.gov.justice.hmpps.kotlin.common.ErrorResponse

@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
@Operation(
summary = "Get learning events by learner ULN",
summary = "Get learning events by learner ULN and filter by keyword if provided",
description = "Get personal learning records and events by a ULN",
parameters = [Parameter(name = "X-Username", `in` = ParameterIn.HEADER, required = true)],
requestBody = RequestBody(
Expand All @@ -24,7 +25,7 @@ import uk.gov.justice.hmpps.kotlin.common.ErrorResponse
content = [
Content(
mediaType = "application/json",
schema = Schema(implementation = uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.LearnerEventsRequest::class),
schema = Schema(implementation = LearnerEventsRequest::class),
examples = [
ExampleObject(
name = "Exact Match",
Expand All @@ -34,7 +35,8 @@ import uk.gov.justice.hmpps.kotlin.common.ErrorResponse
"familyName": "Findlay",
"uln": "1174112637",
"dateOfBirth": "1980-11-01",
"gender": "MALE"
"gender": "MALE",
"keywords": []
}
""",
),
Expand Down Expand Up @@ -97,7 +99,8 @@ import uk.gov.justice.hmpps.kotlin.common.ErrorResponse
"familyName": "Findlay",
"uln": "1174112637",
"dateOfBirth": "1980-11-01",
"gender": "MALE"
"gender": "MALE",
"keywords": ["english"]
},
"responseType": "Exact Match",
"foundUln": "1174112637",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class LearnerEventsService(
responseType = responseType,
incomingUln = learningEventsResult.incomingUln,
foundUln = learningEventsResult.foundUln,
learnerRecord = learningEventsResult.learnerRecord,
learnerRecord = learningEventsResult.learnerRecord.filter {
it.isSubjectOneOf(request.keywords)
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,16 @@ class LearnerEventsServiceTest {
uln = "test",
dateOfBirth = "1990-01-01",
gender = Gender.MALE,
keywords = listOf("english"),
)
val expectedResult = LearnerEventsResponse(
searchParameters = body,
responseType = LRSResponseType.UNKNOWN_RESPONSE_TYPE,
foundUln = env.body.learningEventsResponse.learningEventsResult.foundUln,
incomingUln = env.body.learningEventsResponse.learningEventsResult.incomingUln,
learnerRecord = env.body.learningEventsResponse.learningEventsResult.learnerRecord,
learnerRecord = env.body.learningEventsResponse.learningEventsResult.learnerRecord.filter {
it.isSubjectOneOf(body.keywords)
},
)

`when`(lrsApiInterfaceMock.getLearnerLearningEvents(any())).thenReturn(
Expand Down

0 comments on commit 60b5cf3

Please sign in to comment.