|
1 | 1 | package uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.dto.v1.request
|
2 | 2 |
|
| 3 | +import com.fasterxml.jackson.annotation.JsonSubTypes |
| 4 | +import com.fasterxml.jackson.annotation.JsonTypeInfo |
3 | 5 | import io.swagger.v3.oas.annotations.media.Schema
|
4 |
| -import uk.gov.justice.digital.hmpps.personintegrationapi.corepersonrecord.enumeration.CorePersonRecordField |
| 6 | +import jakarta.validation.constraints.NotNull |
| 7 | +import org.springframework.format.annotation.DateTimeFormat |
| 8 | +import java.time.LocalDate |
5 | 9 |
|
6 |
| -@Schema(description = "Core Person Record V1 update request") |
7 |
| -data class CorePersonRecordV1UpdateRequestDto( |
| 10 | +@JsonTypeInfo( |
| 11 | + use = JsonTypeInfo.Id.NAME, |
| 12 | + include = JsonTypeInfo.As.EXISTING_PROPERTY, |
| 13 | + property = "fieldName", |
| 14 | + visible = true, |
| 15 | +) |
| 16 | +@JsonSubTypes( |
| 17 | + JsonSubTypes.Type(name = CorePersonRecordV1UpdateRequestDto.BIRTHPLACE, value = BirthplaceUpdateDto::class), |
| 18 | + JsonSubTypes.Type(name = CorePersonRecordV1UpdateRequestDto.COUNTRY_OF_BIRTH, value = CountryOfBirthUpdateDto::class), |
| 19 | + JsonSubTypes.Type(name = CorePersonRecordV1UpdateRequestDto.DATE_OF_BIRTH, value = DateOfBirthUpdateDto::class), |
| 20 | +) |
| 21 | +@Schema(description = "Core Person Record V1 update request base") |
| 22 | +sealed class CorePersonRecordV1UpdateRequestDto { |
| 23 | + abstract val fieldName: String |
| 24 | + abstract val value: Any? |
| 25 | + |
| 26 | + companion object { |
| 27 | + const val BIRTHPLACE = "BIRTHPLACE" |
| 28 | + const val COUNTRY_OF_BIRTH = "COUNTRY_OF_BIRTH" |
| 29 | + const val DATE_OF_BIRTH = "DATE_OF_BIRTH" |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +@Schema(description = "Core Person Record V1 birthplace update request") |
| 34 | +data class BirthplaceUpdateDto( |
8 | 35 | @Schema(
|
| 36 | + description = "The new value for the Birthplace", |
| 37 | + example = "London", |
| 38 | + required = true, |
| 39 | + nullable = false, |
| 40 | + ) |
| 41 | + @field:NotNull() |
| 42 | + override val value: String, |
| 43 | +) : CorePersonRecordV1UpdateRequestDto() { |
| 44 | + @Schema( |
| 45 | + type = "String", |
9 | 46 | description = "The field to be updated",
|
10 |
| - example = "BIRTHPLACE", |
| 47 | + allowableValues = [BIRTHPLACE], |
11 | 48 | required = true,
|
12 | 49 | nullable = false,
|
13 | 50 | )
|
14 |
| - val fieldName: CorePersonRecordField, |
| 51 | + override val fieldName: String = BIRTHPLACE |
| 52 | +} |
15 | 53 |
|
| 54 | +@Schema(description = "Core Person Record V1 date of birth update request") |
| 55 | +data class DateOfBirthUpdateDto( |
16 | 56 | @Schema(
|
17 |
| - description = "The new value for the field", |
18 |
| - example = "London", |
| 57 | + description = "The new value for the date of birth field", |
| 58 | + example = "01/01/2000", |
19 | 59 | required = true,
|
20 | 60 | nullable = false,
|
21 | 61 | )
|
22 |
| - val fieldValue: String, |
23 |
| -) |
| 62 | + @field:NotNull() |
| 63 | + @field:DateTimeFormat(pattern = "dd/mm/yyyy") |
| 64 | + override val value: LocalDate, |
| 65 | +) : CorePersonRecordV1UpdateRequestDto() { |
| 66 | + @Schema( |
| 67 | + type = "String", |
| 68 | + description = "The field to be updated", |
| 69 | + allowableValues = [DATE_OF_BIRTH], |
| 70 | + required = true, |
| 71 | + nullable = false, |
| 72 | + ) |
| 73 | + override val fieldName: String = DATE_OF_BIRTH |
| 74 | +} |
| 75 | + |
| 76 | +@Schema(description = "Core Person Record V1 country of birth update request") |
| 77 | +data class CountryOfBirthUpdateDto( |
| 78 | + @Schema( |
| 79 | + description = "The new value for the country of brith field", |
| 80 | + example = "UK", |
| 81 | + required = true, |
| 82 | + nullable = false, |
| 83 | + ) |
| 84 | + @field:NotNull() |
| 85 | + override val value: String, |
| 86 | +) : CorePersonRecordV1UpdateRequestDto() { |
| 87 | + @Schema( |
| 88 | + type = "String", |
| 89 | + description = "The field to be updated", |
| 90 | + allowableValues = [COUNTRY_OF_BIRTH], |
| 91 | + required = true, |
| 92 | + nullable = false, |
| 93 | + ) |
| 94 | + override val fieldName: String = COUNTRY_OF_BIRTH |
| 95 | +} |
0 commit comments