generated from ministryofjustice/hmpps-template-kotlin
-
Notifications
You must be signed in to change notification settings - Fork 1
SDIT-2021 Cater for retries to the mapping creation by performing an upsert #369
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -16,6 +16,7 @@ import org.springframework.validation.annotation.Validated | |
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.PutMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.ResponseStatus | ||
|
@@ -32,6 +33,7 @@ class PrisonPersonResource(private val service: PrisonPersonMigrationService) { | |
|
||
@PostMapping("/migration") | ||
@ResponseStatus(HttpStatus.CREATED) | ||
@Deprecated("Use the PUT endpoint which is idempotent") | ||
@Operation( | ||
summary = "Creates a new prison person migration mapping", | ||
description = "Creates a mapping between nomis alert ids and dps alert id. Requires ROLE_NOMIS_PRISONPERSON", | ||
|
@@ -76,6 +78,31 @@ class PrisonPersonResource(private val service: PrisonPersonMigrationService) { | |
) | ||
} | ||
|
||
@PutMapping("/migration") | ||
@Operation( | ||
summary = "Creates or updates a prison person migration mapping", | ||
description = "Creates or updates a mapping between nomis prisoner numbers and prison person history ids. Requires ROLE_NOMIS_PRISONPERSON", | ||
Comment on lines
+81
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When testing we found that sometimes a prisoner migration is retried despite all records being created in DPS and the mapping service. As DPS is idempotent and just overwrites the previous migration we need the same behaviour in the mapping service, hence switching to a PUT. |
||
requestBody = io.swagger.v3.oas.annotations.parameters.RequestBody( | ||
content = [Content(mediaType = "application/json", schema = Schema(implementation = PrisonPersonMigrationMappingRequest::class))], | ||
), | ||
responses = [ | ||
ApiResponse(responseCode = "200", description = "Mapping created or updated"), | ||
ApiResponse( | ||
responseCode = "401", | ||
description = "Unauthorized to access this endpoint", | ||
content = [Content(mediaType = "application/json", schema = Schema(implementation = ErrorResponse::class))], | ||
), | ||
ApiResponse( | ||
responseCode = "403", | ||
description = "Access forbidden for this endpoint", | ||
content = [Content(mediaType = "application/json", schema = Schema(implementation = ErrorResponse::class))], | ||
), | ||
], | ||
) | ||
suspend fun upsertMapping( | ||
@RequestBody @Valid mappingRequest: PrisonPersonMigrationMappingRequest, | ||
) = service.upsert(mappingRequest) | ||
|
||
@GetMapping("/migration/migration-id/{migrationId}") | ||
@Operation( | ||
summary = "get paged mappings by migration id", | ||
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spring data R2DBC still doesn't support composite entity keys so we needed another way. I thought I'd try out the template instead.