|
| 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.DeleteMapping |
| 15 | +import org.springframework.web.bind.annotation.GetMapping |
| 16 | +import org.springframework.web.bind.annotation.PathVariable |
| 17 | +import org.springframework.web.bind.annotation.PostMapping |
| 18 | +import org.springframework.web.bind.annotation.PutMapping |
| 19 | +import org.springframework.web.bind.annotation.RequestBody |
| 20 | +import org.springframework.web.bind.annotation.RequestMapping |
| 21 | +import org.springframework.web.bind.annotation.ResponseBody |
| 22 | +import org.springframework.web.bind.annotation.RestController |
| 23 | +import uk.gov.justice.digital.hmpps.organisationsapi.facade.SyncFacade |
| 24 | +import uk.gov.justice.digital.hmpps.organisationsapi.model.request.sync.SyncCreateAddressPhoneRequest |
| 25 | +import uk.gov.justice.digital.hmpps.organisationsapi.model.request.sync.SyncUpdateAddressPhoneRequest |
| 26 | +import uk.gov.justice.digital.hmpps.organisationsapi.model.response.sync.SyncAddressPhoneResponse |
| 27 | +import uk.gov.justice.digital.hmpps.organisationsapi.swagger.AuthApiResponses |
| 28 | +import uk.gov.justice.hmpps.kotlin.common.ErrorResponse |
| 29 | + |
| 30 | +@Tag(name = "Migration and synchronisation") |
| 31 | +@RestController |
| 32 | +@RequestMapping(value = ["sync"], produces = [MediaType.APPLICATION_JSON_VALUE]) |
| 33 | +@AuthApiResponses |
| 34 | +class SyncAddressPhoneController(val syncFacade: SyncFacade) { |
| 35 | + |
| 36 | + @GetMapping(path = ["/organisation-address-phone/{organisationAddressPhoneId}"], produces = [MediaType.APPLICATION_JSON_VALUE]) |
| 37 | + @Operation( |
| 38 | + summary = "Returns the data for one organisation address phone number by ID", |
| 39 | + description = """ |
| 40 | + Requires role: ROLE_ORGANISATIONS_MIGRATION. |
| 41 | + Used to get the details for one organisation address phone number by ID. |
| 42 | + """, |
| 43 | + security = [SecurityRequirement(name = "bearer")], |
| 44 | + ) |
| 45 | + @ApiResponses( |
| 46 | + value = [ |
| 47 | + ApiResponse( |
| 48 | + responseCode = "200", |
| 49 | + description = "Returning the details of the organisation address-linked phone number", |
| 50 | + content = [ |
| 51 | + Content( |
| 52 | + mediaType = "application/json", |
| 53 | + schema = Schema(implementation = SyncAddressPhoneResponse::class), |
| 54 | + ), |
| 55 | + ], |
| 56 | + ), |
| 57 | + ApiResponse( |
| 58 | + responseCode = "400", |
| 59 | + description = "The request has invalid or missing fields", |
| 60 | + content = [Content(schema = Schema(implementation = ErrorResponse::class))], |
| 61 | + ), |
| 62 | + ApiResponse( |
| 63 | + responseCode = "404", |
| 64 | + description = "No organisation address number with the requested ID was found", |
| 65 | + content = [Content(schema = Schema(implementation = ErrorResponse::class))], |
| 66 | + ), |
| 67 | + ], |
| 68 | + ) |
| 69 | + @PreAuthorize("hasAnyRole('ROLE_ORGANISATIONS_MIGRATION')") |
| 70 | + fun syncGetAddressPhoneById( |
| 71 | + @Parameter(description = "The internal ID for an organisation address-linked phone number", required = true) |
| 72 | + @PathVariable organisationAddressPhoneId: Long, |
| 73 | + ) = syncFacade.getAddressPhoneById(organisationAddressPhoneId) |
| 74 | + |
| 75 | + @DeleteMapping(path = ["/organisation-address-phone/{organisationAddressPhoneId}"], produces = [MediaType.APPLICATION_JSON_VALUE]) |
| 76 | + @Operation( |
| 77 | + summary = "Deletes one organisation address-linked phone number by internal ID", |
| 78 | + description = """ |
| 79 | + Requires role: ROLE_ORGANISATIONS_MIGRATION. |
| 80 | + Used to delete an organisation's address-linked phone number by internal ID. |
| 81 | + """, |
| 82 | + security = [SecurityRequirement(name = "bearer")], |
| 83 | + ) |
| 84 | + @ApiResponses( |
| 85 | + value = [ |
| 86 | + ApiResponse( |
| 87 | + responseCode = "204", |
| 88 | + description = "Successfully deleted the organisation address phone number", |
| 89 | + ), |
| 90 | + ApiResponse( |
| 91 | + responseCode = "404", |
| 92 | + description = "No organisation address-linked phone number with the requested ID was found", |
| 93 | + content = [Content(schema = Schema(implementation = ErrorResponse::class))], |
| 94 | + ), |
| 95 | + ], |
| 96 | + ) |
| 97 | + @PreAuthorize("hasAnyRole('ROLE_ORGANISATIONS_MIGRATION')") |
| 98 | + fun syncDeleteAddressPhoneById( |
| 99 | + @Parameter(description = "The internal ID for the organisation address-linked phone number.", required = true) |
| 100 | + @PathVariable organisationAddressPhoneId: Long, |
| 101 | + ) = syncFacade.deleteAddressPhone(organisationAddressPhoneId) |
| 102 | + |
| 103 | + @PostMapping(path = ["/organisation-address-phone"], produces = [MediaType.APPLICATION_JSON_VALUE]) |
| 104 | + @ResponseBody |
| 105 | + @Operation( |
| 106 | + summary = "Creates a new address-linked phone number for an organisation", |
| 107 | + description = """ |
| 108 | + Requires role: ROLE_ORGANISATIONS_MIGRATION. |
| 109 | + Used to create a new address-linked phone number for an organisation. |
| 110 | + """, |
| 111 | + security = [SecurityRequirement(name = "bearer")], |
| 112 | + ) |
| 113 | + @ApiResponses( |
| 114 | + value = [ |
| 115 | + ApiResponse( |
| 116 | + responseCode = "201", |
| 117 | + description = "Successfully created the address-linked phone number for an organisation", |
| 118 | + content = [ |
| 119 | + Content( |
| 120 | + mediaType = "application/json", |
| 121 | + schema = Schema(implementation = SyncAddressPhoneResponse::class), |
| 122 | + ), |
| 123 | + ], |
| 124 | + ), |
| 125 | + ApiResponse( |
| 126 | + responseCode = "400", |
| 127 | + description = "The request has invalid or missing fields", |
| 128 | + content = [Content(schema = Schema(implementation = ErrorResponse::class))], |
| 129 | + ), |
| 130 | + ApiResponse( |
| 131 | + responseCode = "404", |
| 132 | + description = "The organisation or address was not found", |
| 133 | + content = [Content(schema = Schema(implementation = ErrorResponse::class))], |
| 134 | + ), |
| 135 | + ], |
| 136 | + ) |
| 137 | + @PreAuthorize("hasAnyRole('ROLE_ORGANISATIONS_MIGRATION')") |
| 138 | + fun syncCreateAddressPhone( |
| 139 | + @Valid @RequestBody syncCreateAddressPhoneRequest: SyncCreateAddressPhoneRequest, |
| 140 | + ) = syncFacade.createAddressPhone(syncCreateAddressPhoneRequest) |
| 141 | + |
| 142 | + @PutMapping(path = ["/organisation-address-phone/{organisationAddressPhoneId}"], produces = [MediaType.APPLICATION_JSON_VALUE]) |
| 143 | + @ResponseBody |
| 144 | + @Operation( |
| 145 | + summary = "Updates an organisation address-linked phone number with altered or additional details", |
| 146 | + description = """ |
| 147 | + Requires role: ROLE_ORGANISATIONS_MIGRATION. |
| 148 | + Used to update an organisation's address-linked phone number. |
| 149 | + """, |
| 150 | + security = [SecurityRequirement(name = "bearer")], |
| 151 | + ) |
| 152 | + @ApiResponses( |
| 153 | + value = [ |
| 154 | + ApiResponse( |
| 155 | + responseCode = "200", |
| 156 | + description = "Successfully updated the organisation's address-linked phone number", |
| 157 | + content = [ |
| 158 | + Content( |
| 159 | + mediaType = "application/json", |
| 160 | + schema = Schema(implementation = SyncAddressPhoneResponse::class), |
| 161 | + ), |
| 162 | + ], |
| 163 | + ), |
| 164 | + ApiResponse( |
| 165 | + responseCode = "404", |
| 166 | + description = "The organisation, address or phone number was not found", |
| 167 | + content = [Content(schema = Schema(implementation = ErrorResponse::class))], |
| 168 | + ), |
| 169 | + ApiResponse( |
| 170 | + responseCode = "400", |
| 171 | + description = "Invalid request data", |
| 172 | + content = [Content(schema = Schema(implementation = ErrorResponse::class))], |
| 173 | + ), |
| 174 | + ], |
| 175 | + ) |
| 176 | + @PreAuthorize("hasAnyRole('ROLE_ORGANISATIONS_MIGRATION')") |
| 177 | + fun syncUpdateAddressPhone( |
| 178 | + @Parameter(description = "The internal ID for the organisation address-linked phone number.", required = true) |
| 179 | + @PathVariable organisationAddressPhoneId: Long, |
| 180 | + @Valid @RequestBody syncUpdateAddressPhoneRequest: SyncUpdateAddressPhoneRequest, |
| 181 | + ) = syncFacade.updateAddressPhone(organisationAddressPhoneId, syncUpdateAddressPhoneRequest) |
| 182 | +} |
0 commit comments