diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorController.java b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorController.java index 32721f0d..86548373 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorController.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.UUID; import static net.hostsharing.hsadminng.hs.office.relation.HsOfficeRelationType.DEBITOR; +import static net.hostsharing.hsadminng.repr.TaggedNumber.cropTag; @RestController @@ -53,11 +54,11 @@ public class HsOfficeDebitorController implements HsOfficeDebitorsApi { final String currentSubject, final String assumedRoles, final String name, - final Integer debitorNumber) { + final String debitorNumber) { context.define(currentSubject, assumedRoles); final var entities = debitorNumber != null - ? debitorRepo.findDebitorByDebitorNumber(debitorNumber) + ? debitorRepo.findDebitorByDebitorNumber(cropTag("D-", debitorNumber)) : debitorRepo.findDebitorByOptionalNameLike(name); final var resources = mapper.mapList(entities, HsOfficeDebitorResource.class); diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepository.java b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepository.java index bb6cd0f2..b2b51df6 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepository.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/debitor/HsOfficeDebitorRepository.java @@ -1,8 +1,10 @@ package net.hostsharing.hsadminng.hs.office.debitor; +import net.hostsharing.hsadminng.hs.office.membership.HsOfficeMembershipEntity; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.Repository; +import jakarta.validation.constraints.NotNull; import java.util.List; import java.util.Optional; import java.util.UUID; @@ -16,13 +18,16 @@ public interface HsOfficeDebitorRepository extends Repository findDebitorByDebitorNumber(int partnerNumber, byte debitorNumberSuffix); + WHERE partner.partnerNumber = :partnerNumber + AND debitor.debitorNumberSuffix = :debitorNumberSuffix + """) + List findDebitorByDebitorNumber(int partnerNumber, String debitorNumberSuffix); default List findDebitorByDebitorNumber(int debitorNumber) { - return findDebitorByDebitorNumber( debitorNumber/100, (byte) (debitorNumber%100)); + final var partnerNumber = debitorNumber / 100; + final String suffix = String.format("%02d", debitorNumber % 100); + final var result = findDebitorByDebitorNumber(partnerNumber, suffix); + return result; } @Query(""" 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 52ef2aad..976aad83 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 @@ -131,7 +131,7 @@ public class HsOfficeSepaMandateController implements HsOfficeSepaMandatesApi { if (entity.getValidity().hasUpperBound()) { resource.setValidTo(entity.getValidity().upper().minusDays(1)); } - resource.getDebitor().setDebitorNumber(entity.getDebitor().getDebitorNumber()); + resource.getDebitor().setDebitorNumber("D-" + entity.getDebitor().getDebitorNumber()); }; final BiConsumer SEPA_MANDATE_RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> { diff --git a/src/main/resources/api-definition/hs-office/hs-office-debitor-schemas.yaml b/src/main/resources/api-definition/hs-office/hs-office-debitor-schemas.yaml index bc3d402e..bca2f0a2 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-debitor-schemas.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-debitor-schemas.yaml @@ -12,10 +12,10 @@ components: debitorRel: $ref: 'hs-office-relation-schemas.yaml#/components/schemas/HsOfficeRelation' debitorNumber: - type: integer - format: int32 - minimum: 1000000 - maximum: 9999999 + type: string + minLength: 9 + maxLength: 9 + pattern: 'D-[0-9]{7}' debitorNumberSuffix: type: string pattern: '^[0-9][0-9]$' diff --git a/src/main/resources/api-definition/hs-office/hs-office-debitors.yaml b/src/main/resources/api-definition/hs-office/hs-office-debitors.yaml index 16554531..2e5c3383 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-debitors.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-debitors.yaml @@ -17,7 +17,10 @@ get: in: query required: false schema: - type: integer + type: string + minLength: 9 + maxLength: 9 + pattern: 'D-[0-9]{7}' description: Debitor number of the requested debitor. responses: "200": diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java index e5e47cf6..0a844632 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/scenarios/HsOfficeScenarioTests.java @@ -238,7 +238,7 @@ class HsOfficeScenarioTests extends ScenarioTest { @Test @Order(2011) @Requires("Person: Test AG") - @Produces("Debitor: Billing GmbH") + @Produces("Debitor: D-3101000 - Test AG - main debitor") void shouldCreateExternalDebitorForPartner() { new CreateExternalDebitorForPartner(this) .given("partnerPersonTradeName", "Test AG") @@ -283,7 +283,7 @@ class HsOfficeScenarioTests extends ScenarioTest { void shouldCreateSepaMandateForDebitor() { new CreateSepaMandateForDebitor(this) // existing debitor - .given("debitorNumber", "3101000") + .given("debitorNumber", "D-3101000") // new sepa-mandate .given("mandateReference", "Test AG - main debitor")