From 27f29ef66565e528a45c2cafe8eb6dc7cf1b960e Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Tue, 18 Oct 2022 12:30:26 +0200 Subject: [PATCH] hs-office-sepamandate simplyfied controller code --- .../sepamandate/HsOfficeSepaMandateController.java | 10 +++------- .../HsOfficeSepaMandateControllerAcceptanceTest.java | 12 ++++++------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateController.java b/src/main/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateController.java index 7dd7b159..51e998a0 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateController.java @@ -3,10 +3,10 @@ package net.hostsharing.hsadminng.hs.office.sepamandate; import com.vladmihalcea.hibernate.type.range.Range; import net.hostsharing.hsadminng.Mapper; import net.hostsharing.hsadminng.context.Context; -import net.hostsharing.hsadminng.hs.office.bankaccount.HsOfficeBankAccountEntity; -import net.hostsharing.hsadminng.hs.office.debitor.HsOfficeDebitorEntity; import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficeSepaMandatesApi; -import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.*; +import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeSepaMandateInsertResource; +import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeSepaMandatePatchResource; +import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeSepaMandateResource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.transaction.annotation.Transactional; @@ -135,8 +135,6 @@ public class HsOfficeSepaMandateController implements HsOfficeSepaMandatesApi { } final BiConsumer SEPA_MANDATE_ENTITY_TO_RESOURCE_POSTMAPPER = (entity, resource) -> { - resource.setDebitor(map(entity.getDebitor(), HsOfficeDebitorResource.class)); - resource.setBankAccount(map(entity.getBankAccount(), HsOfficeBankAccountResource.class)); resource.setValidFrom(entity.getValidity().lower()); if (entity.getValidity().hasUpperBound()) { resource.setValidTo(entity.getValidity().upper().minusDays(1)); @@ -144,8 +142,6 @@ public class HsOfficeSepaMandateController implements HsOfficeSepaMandatesApi { }; final BiConsumer SEPA_MANDATE_RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> { - entity.setDebitor(em.getReference(HsOfficeDebitorEntity.class, resource.getDebitorUuid())); - entity.setBankAccount(em.getReference(HsOfficeBankAccountEntity.class, resource.getBankAccountUuid())); entity.setValidity(toPostgresDateRange(resource.getValidFrom(), resource.getValidTo())); }; } diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateControllerAcceptanceTest.java index 6046674b..cbb0abb2 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/sepamandate/HsOfficeSepaMandateControllerAcceptanceTest.java @@ -339,7 +339,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest { void globalAdmin_canPatchValidToOfArbitrarySepaMandate() { context.define("superuser-alex@hostsharing.net"); - final var givenSepaMandate = givenSomeTemporarySepaMandateBessler(); + final var givenSepaMandate = givenSomeTemporarySepaMandate(); final var location = RestAssured // @formatter:off .given() @@ -379,7 +379,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest { void globalAdmin_canNotPatchReferenceOfArbitrarySepaMandate() { context.define("superuser-alex@hostsharing.net"); - final var givenSepaMandate = givenSomeTemporarySepaMandateBessler(); + final var givenSepaMandate = givenSomeTemporarySepaMandate(); final var location = RestAssured // @formatter:off .given() @@ -415,7 +415,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest { @Test void globalAdmin_canDeleteArbitrarySepaMandate() { context.define("superuser-alex@hostsharing.net"); - final var givenSepaMandate = givenSomeTemporarySepaMandateBessler(); + final var givenSepaMandate = givenSomeTemporarySepaMandate(); RestAssured // @formatter:off .given() @@ -434,7 +434,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest { @Accepts({ "SepaMandate:X(Access Control)" }) void bankAccountAdminUser_canNotDeleteRelatedSepaMandate() { context.define("superuser-alex@hostsharing.net"); - final var givenSepaMandate = givenSomeTemporarySepaMandateBessler(); + final var givenSepaMandate = givenSomeTemporarySepaMandate(); assertThat(givenSepaMandate.getReference()).isEqualTo("temp ref X"); RestAssured // @formatter:off @@ -454,7 +454,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest { @Accepts({ "SepaMandate:X(Access Control)" }) void normalUser_canNotDeleteUnrelatedSepaMandate() { context.define("superuser-alex@hostsharing.net"); - final var givenSepaMandate = givenSomeTemporarySepaMandateBessler(); + final var givenSepaMandate = givenSomeTemporarySepaMandate(); assertThat(givenSepaMandate.getReference()).isEqualTo("temp ref X"); RestAssured // @formatter:off @@ -471,7 +471,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest { } } - private HsOfficeSepaMandateEntity givenSomeTemporarySepaMandateBessler() { + private HsOfficeSepaMandateEntity givenSomeTemporarySepaMandate() { return jpaAttempt.transacted(() -> { context.define("superuser-alex@hostsharing.net"); final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("First").get(0);