generated from ministryofjustice/hmpps-template-kotlin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [BTD-541] * [BTD-541] Added check match end point * [BTD-541] Added check match end point * [BTD-541] Added check match end point * [BTD-541] Added check match end point * [BTD-541] Added check match end point * [BTD-541] Added doco * [BTD-541] Added doco * [BTD-541] Added doco * [BTD-541] * [BTD-541] Fixed errors * [BTD-541] Fixed errors * [BTD-541] Fixed errors * Request model * Response model * Confirm match endpoint + swagger docs * Int tests * Int test fix * Model validation test * Match Service Test update * Fixes for openapi * Readme * nomis id consistency * Remove response body KEEP request body * additional comments * readme * readme update * readme update * Readme * Readme --------- Co-authored-by: Patrick Lucas <patrick.lucas@justice.gov.uk> Co-authored-by: Ewan Donovan <ewan.donovan@digital.justice.co.uk>
- Loading branch information
1 parent
bade5ff
commit 3d4c730
Showing
7 changed files
with
264 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...tlin/uk/gov/justice/digital/hmpps/learnerrecordsapi/models/request/ConfirmMatchRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request | ||
|
||
import jakarta.validation.constraints.Pattern | ||
|
||
class ConfirmMatchRequest( | ||
|
||
@field:Pattern(regexp = "^[0-9]{1,10}\$") | ||
val matchingUln: String, | ||
|
||
) |
62 changes: 62 additions & 0 deletions
62
src/main/kotlin/uk/gov/justice/digital/hmpps/learnerrecordsapi/openapi/MatchConfirmApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package uk.gov.justice.digital.hmpps.learnerrecordsapi.openapi | ||
|
||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.Parameter | ||
import io.swagger.v3.oas.annotations.enums.ParameterIn | ||
import io.swagger.v3.oas.annotations.media.Content | ||
import io.swagger.v3.oas.annotations.media.ExampleObject | ||
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.ConfirmMatchRequest | ||
import uk.gov.justice.hmpps.kotlin.common.ErrorResponse | ||
|
||
@Target(AnnotationTarget.FUNCTION) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
@Operation( | ||
summary = "Confirm a match", | ||
description = "Confirm a match between a nomis id and a ULN", | ||
parameters = [ | ||
Parameter(name = "X-Username", `in` = ParameterIn.HEADER, required = true), | ||
Parameter(name = "nomisId", `in` = ParameterIn.PATH, required = true), | ||
], | ||
requestBody = RequestBody( | ||
description = "a ULN to match with the nomis id in the path", | ||
required = true, | ||
content = [ | ||
Content( | ||
mediaType = "application/json", | ||
schema = Schema(implementation = ConfirmMatchRequest::class), | ||
examples = [ | ||
ExampleObject( | ||
name = "Example Request", | ||
value = """ | ||
{ | ||
"matchingUln": "1964986809" | ||
} | ||
""", | ||
), | ||
], | ||
), | ||
], | ||
), | ||
security = [SecurityRequirement(name = "learner-records-search-read-only-role")], | ||
responses = [ | ||
ApiResponse( | ||
responseCode = "201", | ||
description = "The request was successful and the match was created.", | ||
), | ||
ApiResponse( | ||
responseCode = "401", | ||
description = "Unauthorized to access this endpoint", | ||
content = [Content(mediaType = "application/json", schema = Schema(implementation = ErrorResponse::class))], | ||
), | ||
ApiResponse( | ||
responseCode = "403", | ||
description = "Forbidden to access this endpoint", | ||
content = [Content(mediaType = "application/json", schema = Schema(implementation = ErrorResponse::class))], | ||
), | ||
], | ||
) | ||
annotation class MatchConfirmApi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
.../uk/gov/justice/digital/hmpps/learnerrecordsapi/models/request/ConfirmMatchRequestTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request | ||
|
||
import jakarta.validation.Validation | ||
import jakarta.validation.ValidatorFactory | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import org.junit.jupiter.api.Test | ||
|
||
class ConfirmMatchRequestTest { | ||
|
||
private val factory: ValidatorFactory = Validation.buildDefaultValidatorFactory() | ||
private val validator = factory.validator | ||
|
||
@Test | ||
fun `valid uln should pass validation`() { | ||
val request = ConfirmMatchRequest( | ||
matchingUln = "1234567890", | ||
) | ||
|
||
assertTrue(validator.validate(request).isEmpty()) | ||
} | ||
|
||
@Test | ||
fun `invalid uln should fail validation`() { | ||
val request = ConfirmMatchRequest( | ||
matchingUln = "1234567890abcdedf", | ||
) | ||
|
||
assertTrue(validator.validate(request).size == 1) | ||
} | ||
} |
Oops, something went wrong.