|
| 1 | +package uk.gov.justice.digital.hmpps.organisationsapi.resource.sync |
| 2 | + |
| 3 | +import io.swagger.v3.oas.annotations.Operation |
| 4 | +import io.swagger.v3.oas.annotations.Parameter |
| 5 | +import io.swagger.v3.oas.annotations.media.Content |
| 6 | +import io.swagger.v3.oas.annotations.media.Schema |
| 7 | +import io.swagger.v3.oas.annotations.responses.ApiResponse |
| 8 | +import io.swagger.v3.oas.annotations.responses.ApiResponses |
| 9 | +import io.swagger.v3.oas.annotations.security.SecurityRequirement |
| 10 | +import io.swagger.v3.oas.annotations.tags.Tag |
| 11 | +import jakarta.validation.Valid |
| 12 | +import org.springframework.http.MediaType |
| 13 | +import org.springframework.security.access.prepost.PreAuthorize |
| 14 | +import org.springframework.web.bind.annotation.GetMapping |
| 15 | +import org.springframework.web.bind.annotation.PathVariable |
| 16 | +import org.springframework.web.bind.annotation.PutMapping |
| 17 | +import org.springframework.web.bind.annotation.RequestBody |
| 18 | +import org.springframework.web.bind.annotation.RequestMapping |
| 19 | +import org.springframework.web.bind.annotation.ResponseBody |
| 20 | +import org.springframework.web.bind.annotation.RestController |
| 21 | +import uk.gov.justice.digital.hmpps.organisationsapi.facade.SyncFacade |
| 22 | +import uk.gov.justice.digital.hmpps.organisationsapi.model.request.sync.SyncUpdateTypesRequest |
| 23 | +import uk.gov.justice.digital.hmpps.organisationsapi.model.response.sync.SyncTypesResponse |
| 24 | +import uk.gov.justice.digital.hmpps.organisationsapi.swagger.AuthApiResponses |
| 25 | + |
| 26 | +@Tag(name = "Migration and synchronisation") |
| 27 | +@RestController |
| 28 | +@RequestMapping(value = ["sync"], produces = [MediaType.APPLICATION_JSON_VALUE]) |
| 29 | +@AuthApiResponses |
| 30 | +class SyncTypesController(val syncFacade: SyncFacade) { |
| 31 | + |
| 32 | + @GetMapping(path = ["/organisation-types/{organisationId}"], produces = [MediaType.APPLICATION_JSON_VALUE]) |
| 33 | + @Operation( |
| 34 | + summary = "Returns the organisation types for an organisation by ID", |
| 35 | + description = """ |
| 36 | + Requires role: ROLE_ORGANISATIONS_MIGRATION. |
| 37 | + Used to get the organisation types for this organisation. |
| 38 | + """, |
| 39 | + security = [SecurityRequirement(name = "bearer")], |
| 40 | + ) |
| 41 | + @ApiResponses( |
| 42 | + value = [ |
| 43 | + ApiResponse( |
| 44 | + responseCode = "200", |
| 45 | + description = "Returning the details of the organisation types", |
| 46 | + content = [ |
| 47 | + Content( |
| 48 | + mediaType = "application/json", |
| 49 | + schema = Schema(implementation = SyncTypesResponse::class), |
| 50 | + ), |
| 51 | + ], |
| 52 | + ), |
| 53 | + ApiResponse( |
| 54 | + responseCode = "404", |
| 55 | + description = "No organisation with the requested ID was found", |
| 56 | + ), |
| 57 | + ], |
| 58 | + ) |
| 59 | + @PreAuthorize("hasAnyRole('ROLE_ORGANISATIONS_MIGRATION')") |
| 60 | + fun syncGetTypesByOrganisationId( |
| 61 | + @Parameter(description = "The internal organisation ID.", required = true) |
| 62 | + @PathVariable organisationId: Long, |
| 63 | + ) = syncFacade.getTypesByOrganisationId(organisationId) |
| 64 | + |
| 65 | + @PutMapping(path = ["/organisation-types/{organisationId}"], produces = [MediaType.APPLICATION_JSON_VALUE]) |
| 66 | + @ResponseBody |
| 67 | + @Operation( |
| 68 | + summary = "Updates the organisation types for a given organisation ID", |
| 69 | + description = """ |
| 70 | + Requires role: ROLE_ORGANISATIONS_MIGRATION. |
| 71 | + Used to update an organisation's types. |
| 72 | + """, |
| 73 | + security = [SecurityRequirement(name = "bearer")], |
| 74 | + ) |
| 75 | + @ApiResponses( |
| 76 | + value = [ |
| 77 | + ApiResponse( |
| 78 | + responseCode = "200", |
| 79 | + description = "Successfully updated the organisation's types", |
| 80 | + content = [ |
| 81 | + Content( |
| 82 | + mediaType = "application/json", |
| 83 | + schema = Schema(implementation = SyncTypesResponse::class), |
| 84 | + ), |
| 85 | + ], |
| 86 | + ), |
| 87 | + ApiResponse( |
| 88 | + responseCode = "404", |
| 89 | + description = "The organisation ID was not found", |
| 90 | + ), |
| 91 | + ApiResponse( |
| 92 | + responseCode = "400", |
| 93 | + description = "Invalid request data", |
| 94 | + ), |
| 95 | + ], |
| 96 | + ) |
| 97 | + @PreAuthorize("hasAnyRole('ROLE_ORGANISATIONS_MIGRATION')") |
| 98 | + fun syncUpdateWeb( |
| 99 | + @Parameter(description = "The internal organisation ID.", required = true) |
| 100 | + @PathVariable organisationId: Long, |
| 101 | + @Valid @RequestBody syncUpdateTypesRequest: SyncUpdateTypesRequest, |
| 102 | + ) = syncFacade.updateTypes(organisationId, syncUpdateTypesRequest) |
| 103 | +} |
0 commit comments