refactor HsOfficeContactEntityPatcherUnitTest to PatchUnitTestBase
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
package net.hostsharing.hsadminng.hs.office.contact;
|
||||
|
||||
import net.hostsharing.hsadminng.EntityPatcher;
|
||||
import net.hostsharing.hsadminng.OptionalFromJson;
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeContactPatchResource;
|
||||
|
||||
class HsOfficeContactEntityPatch {
|
||||
class HsOfficeContactEntityPatch implements EntityPatcher<HsOfficeContactPatchResource> {
|
||||
|
||||
private final HsOfficeContactEntity entity;
|
||||
|
||||
@ -11,7 +12,8 @@ class HsOfficeContactEntityPatch {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
void apply(final HsOfficeContactPatchResource resource) {
|
||||
@Override
|
||||
public void apply(final HsOfficeContactPatchResource resource) {
|
||||
OptionalFromJson.of(resource.getLabel()).ifPresent(entity::setLabel);
|
||||
OptionalFromJson.of(resource.getPostalAddress()).ifPresent(entity::setPostalAddress);
|
||||
OptionalFromJson.of(resource.getEmailAddresses()).ifPresent(entity::setEmailAddresses);
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.office.partner;
|
||||
|
||||
import net.hostsharing.hsadminng.Mapper;
|
||||
import net.hostsharing.hsadminng.OptionalFromJson;
|
||||
import net.hostsharing.hsadminng.context.Context;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactRepository;
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficePartnersApi;
|
||||
@ -125,7 +124,7 @@ public class HsOfficePartnerController implements HsOfficePartnersApi {
|
||||
|
||||
final var current = partnerRepo.findByUuid(partnerUuid).orElseThrow();
|
||||
|
||||
new HsOfficePartnerEntityPatch(current, contactRepo::findByUuid, personRepo::findByUuid).apply(body);
|
||||
new HsOfficePartnerEntityPatcher(current, contactRepo::findByUuid, personRepo::findByUuid).apply(body);
|
||||
|
||||
final var saved = partnerRepo.save(current);
|
||||
final var mapped = map(saved, HsOfficePartnerResource.class);
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.hostsharing.hsadminng.hs.office.partner;
|
||||
|
||||
import net.hostsharing.hsadminng.EntityPatch;
|
||||
import net.hostsharing.hsadminng.EntityPatcher;
|
||||
import net.hostsharing.hsadminng.OptionalFromJson;
|
||||
import net.hostsharing.hsadminng.hs.office.contact.HsOfficeContactEntity;
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePartnerPatchResource;
|
||||
@ -12,13 +12,13 @@ import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
class HsOfficePartnerEntityPatch implements EntityPatch<HsOfficePartnerPatchResource> {
|
||||
class HsOfficePartnerEntityPatcher implements EntityPatcher<HsOfficePartnerPatchResource> {
|
||||
|
||||
private final HsOfficePartnerEntity entity;
|
||||
private final Function<UUID, Optional<HsOfficeContactEntity>> fetchContact;
|
||||
private final Function<UUID, Optional<HsOfficePersonEntity>> fetchPerson;
|
||||
|
||||
HsOfficePartnerEntityPatch(
|
||||
HsOfficePartnerEntityPatcher(
|
||||
final HsOfficePartnerEntity entity,
|
||||
final Function<UUID, Optional<HsOfficeContactEntity>> fetchContact,
|
||||
final Function<UUID, Optional<HsOfficePersonEntity>> fetchPerson) {
|
@ -6,7 +6,6 @@ import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficePersonsA
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePersonInsertResource;
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePersonPatchResource;
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePersonResource;
|
||||
import net.hostsharing.hsadminng.hs.office.person.HsOfficePersonEntityPatch;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -109,7 +108,7 @@ public class HsOfficePersonController implements HsOfficePersonsApi {
|
||||
|
||||
final var current = personRepo.findByUuid(personUuid).orElseThrow();
|
||||
|
||||
new HsOfficePersonEntityPatch(current).apply(body);
|
||||
new HsOfficePersonEntityPatcher(current).apply(body);
|
||||
|
||||
final var saved = personRepo.save(current);
|
||||
final var mapped = map(saved, HsOfficePersonResource.class);
|
||||
|
@ -3,15 +3,15 @@ package net.hostsharing.hsadminng.hs.office.person;
|
||||
import net.hostsharing.hsadminng.OptionalFromJson;
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePersonPatchResource;
|
||||
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficePersonTypeResource;
|
||||
import net.hostsharing.hsadminng.EntityPatch;
|
||||
import net.hostsharing.hsadminng.EntityPatcher;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
class HsOfficePersonEntityPatch implements EntityPatch<HsOfficePersonPatchResource> {
|
||||
class HsOfficePersonEntityPatcher implements EntityPatcher<HsOfficePersonPatchResource> {
|
||||
|
||||
private final HsOfficePersonEntity entity;
|
||||
|
||||
HsOfficePersonEntityPatch(final HsOfficePersonEntity entity) {
|
||||
HsOfficePersonEntityPatcher(final HsOfficePersonEntity entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
Reference in New Issue
Block a user