address 저장

public record AddressRegistrationRequest(
        String sido,
        String sigungu,
        String eupMyeonDong,
        String detailAddress,
        String addressType,
        String addressVerificationStatus
){
}
public record Address(SiDo sido,
                      SiGunGu sigungu,
                      EupMyeonDong eupMyeonDong,
                      String detailAddress,
                      AddressType addressType) {
    public Address(AddressRegistrationRequest addressRegistrationRequest) {
        this(new SiDo(addressRegistrationRequest.sido()),
             new SiGunGu(addressRegistrationRequest.sigungu()),
             new EupMyeonDong(addressRegistrationRequest.eupMyeonDong()),
             addressRegistrationRequest.detailAddress(),
             AddressType.valueOf(addressRegistrationRequest.addressType()));
    }

}
@Repository
@RequiredArgsConstructor
public class AddressDao implements AddressRepository {
    private final AddressJpaRepository addressJpaRepository;
    private final SiDoJpaRepository siDoJpaRepository;
    private final SigunguJpaRepository sigunguJpaRepository;
    private final EupMyeonDongJpaRepository eupMyeonDongJpaRepository;
    @Override
    public AddressResponse save(Address address) {
        AddressEntity addressEntity = addressJpaRepository.save(new AddressEntity());
        return addressEntity.toDomain();
    }
}

주소 저장 요청 전에 3번의 주소 검색 과정을 거치게 됩니다.

시도, 시군구, 읍면동에 대한 검색 후 주소 저장이 되는데 이때 시도,시군구,읍면동은 id 값만 address에 참조키로 저장됩니다.

댓글남기기