Skip to content

Commit

Permalink
Fix to missing main use
Browse files Browse the repository at this point in the history
  • Loading branch information
slkendell-mt committed Mar 8, 2024
1 parent 5efec7a commit 8e8face
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,35 @@ public BeaconRegistrationDTO toRegistrationDTO(Beacon beacon) {
.build();
}

public BeaconRegistrationDTO toRegistrationDTO(
Beacon beacon,
BeaconUse mainUse
) {
return BeaconRegistrationDTO
.builder()
.id(Objects.requireNonNull(beacon.getId()).unwrap())
.hexId(beacon.getHexId())
.manufacturer(beacon.getManufacturer())
.model(beacon.getModel())
.manufacturerSerialNumber(beacon.getManufacturerSerialNumber())
.referenceNumber(beacon.getReferenceNumber())
.chkCode(beacon.getChkCode())
.batteryExpiryDate(beacon.getBatteryExpiryDate())
.lastServicedDate(beacon.getLastServicedDate())
.mti(beacon.getMti())
.svdr(beacon.getSvdr())
.csta(beacon.getCsta())
.beaconType(beacon.getBeaconType())
.protocol(beacon.getProtocol())
.coding(beacon.getCoding())
.accountHolderId(beacon.getAccountHolderId().unwrap())
.status(beacon.getBeaconStatus())
.createdDate(beacon.getCreatedDate())
.lastModifiedDate(beacon.getLastModifiedDate())
.mainUseName(mainUse != null ? mainUse.getName() : "")
.build();
}

public BeaconDTO toDTO(Beacon beacon) {
BeaconDTO dto = new BeaconDTO();
dto.setId(Objects.requireNonNull(beacon.getId()).unwrap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@ public class BeaconRegistrationDTO {

@NotNull
private UUID accountHolderId;

private String mainUseName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import uk.gov.mca.beacons.api.accountholder.mappers.AccountHolderMapper;
import uk.gov.mca.beacons.api.beacon.mappers.BeaconMapper;
import uk.gov.mca.beacons.api.beaconowner.mappers.BeaconOwnerMapper;
import uk.gov.mca.beacons.api.beaconuse.domain.BeaconUse;
import uk.gov.mca.beacons.api.beaconuse.mappers.BeaconUseMapper;
import uk.gov.mca.beacons.api.emergencycontact.mappers.EmergencyContactMapper;
import uk.gov.mca.beacons.api.export.mappers.ExportMapper;
Expand Down Expand Up @@ -71,7 +72,12 @@ public Registration fromDTO(CreateRegistrationDTO dto) {
public RegistrationDTO toDTO(Registration registration) {
return RegistrationDTO
.builder()
.beaconDTO(beaconMapper.toRegistrationDTO(registration.getBeacon()))
.beaconDTO(
beaconMapper.toRegistrationDTO(
registration.getBeacon(),
registration.getMainUse()
)
)
.beaconOwnerDTO(
// special case for handling deleted beacon owners, this won't be necessary with a resource oriented API
registration.getBeaconOwner() == null
Expand Down

0 comments on commit 8e8face

Please sign in to comment.