Untitled

 avatar
unknown
plain_text
a year ago
839 B
4
Indexable
 @PostMapping("/add-address")
    public AddressEntity createAddress(
            @RequestParam("street") String street,
            @RequestParam("city") String cityName,
            @RequestParam("country") String countryName
    ) {
        CityEntity city = cityRepository.findCityEntityByName(cityName)
                .orElseGet(() -> {
                    CountryEntity country = countryRepository.findCountryEntityByName(countryName)
                            .orElseGet(() -> countryRepository.save(new CountryEntity(countryName)));
                    return cityRepository.save(new CityEntity(cityName, country));
                });

        AddressEntity address = new AddressEntity();
        address.setStreet(street);
        address.setCity(city);

        return addressRepository.save(address);
    }
Editor is loading...
Leave a Comment