diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionController.java b/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionController.java index ed84b7b6..c8a9241e 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionController.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionController.java @@ -38,7 +38,7 @@ public class HsOfficeCoopSharesTransactionController implements HsOfficeCoopShar @Override @Transactional(readOnly = true) - public ResponseEntity> listCoopShares( + public ResponseEntity> getListOfCoopShares( final String currentSubject, final String assumedRoles, final UUID membershipUuid, @@ -57,7 +57,7 @@ public class HsOfficeCoopSharesTransactionController implements HsOfficeCoopShar @Override @Transactional - public ResponseEntity postCoopSharesTransaction( + public ResponseEntity postNewCoopSharesTransaction( final String currentSubject, final String assumedRoles, final HsOfficeCoopSharesTransactionInsertResource requestBody) { @@ -80,7 +80,7 @@ public class HsOfficeCoopSharesTransactionController implements HsOfficeCoopShar @Override @Transactional(readOnly = true) - public ResponseEntity getCoopShareTransactionByUuid( + public ResponseEntity geSingletCoopShareTransactionByUuid( final String currentSubject, final String assumedRoles, final UUID shareTransactionUuid) { context.define(currentSubject, assumedRoles); @@ -132,8 +132,8 @@ public class HsOfficeCoopSharesTransactionController implements HsOfficeCoopShar final BiConsumer RESOURCE_TO_ENTITY_POSTMAPPER = (resource, entity) -> { if ( resource.getRevertedShareTxUuid() != null ) { - entity.setAdjustedShareTx(coopSharesTransactionRepo.findByUuid(resource.getRevertedShareTxUuid()) - .orElseThrow(() -> new EntityNotFoundException("ERROR: [400] adjustedShareTxUuid %s not found".formatted(resource.getRevertedShareTxUuid())))); + entity.setRevertedShareTx(coopSharesTransactionRepo.findByUuid(resource.getRevertedShareTxUuid()) + .orElseThrow(() -> new EntityNotFoundException("ERROR: [400] revertedShareTxUuid %s not found".formatted(resource.getRevertedShareTxUuid())))); } }; } diff --git a/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntity.java b/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntity.java index 8af8b624..3be9373f 100644 --- a/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntity.java +++ b/src/main/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntity.java @@ -48,8 +48,8 @@ public class HsOfficeCoopSharesTransactionEntity implements Stringifyable, BaseE .withProp(HsOfficeCoopSharesTransactionEntity::getShareCount) .withProp(HsOfficeCoopSharesTransactionEntity::getReference) .withProp(HsOfficeCoopSharesTransactionEntity::getComment) - .withProp(at -> ofNullable(at.getAdjustedShareTx()).map(HsOfficeCoopSharesTransactionEntity::toShortString).orElse(null)) - .withProp(at -> ofNullable(at.getAdjustmentShareTx()).map(HsOfficeCoopSharesTransactionEntity::toShortString).orElse(null)) + .withProp(at -> ofNullable(at.getRevertedShareTx()).map(HsOfficeCoopSharesTransactionEntity::toShortString).orElse(null)) + .withProp(at -> ofNullable(at.getReversalShareTx()).map(HsOfficeCoopSharesTransactionEntity::toShortString).orElse(null)) .quotedValues(false); @Id @@ -96,11 +96,11 @@ public class HsOfficeCoopSharesTransactionEntity implements Stringifyable, BaseE * Optionally, the UUID of the corresponding transaction for an adjustment transaction. */ @OneToOne - @JoinColumn(name = "adjustedsharetxuuid") - private HsOfficeCoopSharesTransactionEntity adjustedShareTx; + @JoinColumn(name = "revertedsharetxuuid") + private HsOfficeCoopSharesTransactionEntity revertedShareTx; - @OneToOne(mappedBy = "adjustedShareTx") - private HsOfficeCoopSharesTransactionEntity adjustmentShareTx; + @OneToOne(mappedBy = "revertedShareTx") + private HsOfficeCoopSharesTransactionEntity reversalShareTx; @Override public HsOfficeCoopSharesTransactionEntity load() { diff --git a/src/main/resources/api-definition/hs-office/hs-office-coopshares-schemas.yaml b/src/main/resources/api-definition/hs-office/hs-office-coopshares-schemas.yaml index c9a10377..ce5b25cc 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-coopshares-schemas.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-coopshares-schemas.yaml @@ -35,7 +35,7 @@ components: HsOfficeReferencedCoopSharesTransaction: description: Similar to `HsOfficeCoopSharesTransaction` but without the self-referencing properties - (`adjustedShareTx` and `adjustmentShareTx`), to avoid recursive JSON. + (`revertedShareTx` and `reversalShareTx`), to avoid recursive JSON. type: object properties: uuid: diff --git a/src/main/resources/api-definition/hs-office/hs-office-coopshares-with-uuid.yaml b/src/main/resources/api-definition/hs-office/hs-office-coopshares-with-uuid.yaml index a37dbf7e..87d3da86 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-coopshares-with-uuid.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-coopshares-with-uuid.yaml @@ -2,7 +2,7 @@ get: tags: - hs-office-coopShares description: 'Fetch a single share transaction by its uuid, if visible for the current subject.' - operationId: getCoopShareTransactionByUuid + operationId: geSingletCoopShareTransactionByUuid parameters: - $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/assumedRoles' diff --git a/src/main/resources/api-definition/hs-office/hs-office-coopshares.yaml b/src/main/resources/api-definition/hs-office/hs-office-coopshares.yaml index f2a03445..69dad5ad 100644 --- a/src/main/resources/api-definition/hs-office/hs-office-coopshares.yaml +++ b/src/main/resources/api-definition/hs-office/hs-office-coopshares.yaml @@ -3,7 +3,7 @@ get: description: Returns the list of (optionally filtered) cooperative share transactions which are visible to the current subject or any of it's assumed roles. tags: - hs-office-coopShares - operationId: listCoopShares + operationId: getListOfCoopShares parameters: - $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/assumedRoles' @@ -46,7 +46,7 @@ post: summary: Adds a new cooperative share transaction. tags: - hs-office-coopShares - operationId: postCoopSharesTransaction + operationId: postNewCoopSharesTransaction parameters: - $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/assumedRoles' diff --git a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql index 213dd1cb..e8845f51 100644 --- a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql +++ b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5110-hs-office-coopshares.sql @@ -17,7 +17,7 @@ create table if not exists hs_office.coopsharetx valueDate date not null, shareCount integer not null, reference varchar(48) not null, - adjustedShareTxUuid uuid unique REFERENCES hs_office.coopsharetx(uuid) DEFERRABLE INITIALLY DEFERRED, + revertedShareTxUuid uuid unique REFERENCES hs_office.coopsharetx(uuid) DEFERRABLE INITIALLY DEFERRED, comment varchar(512) ); --// @@ -28,8 +28,8 @@ create table if not exists hs_office.coopsharetx alter table hs_office.coopsharetx add constraint reverse_entry_missing - check ( transactionType = 'ADJUSTMENT' and adjustedShareTxUuid is not null - or transactionType <> 'ADJUSTMENT' and adjustedShareTxUuid is null); + check ( transactionType = 'ADJUSTMENT' and revertedShareTxUuid is not null + or transactionType <> 'ADJUSTMENT' and revertedShareTxUuid is null); --// -- ============================================================================ diff --git a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5118-hs-office-coopshares-test-data.sql b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5118-hs-office-coopshares-test-data.sql index 0f148a90..0050e244 100644 --- a/src/main/resources/db/changelog/5-hs-office/511-coopshares/5118-hs-office-coopshares-test-data.sql +++ b/src/main/resources/db/changelog/5-hs-office/511-coopshares/5118-hs-office-coopshares-test-data.sql @@ -27,7 +27,7 @@ begin raise notice 'creating test coopSharesTransaction: %', givenPartnerNumber::text || givenMemberNumberSuffix; subscriptionEntryUuid := uuid_generate_v4(); insert - into hs_office.coopsharetx(uuid, membershipuuid, transactiontype, valuedate, sharecount, reference, comment, adjustedShareTxUuid) + into hs_office.coopsharetx(uuid, membershipuuid, transactiontype, valuedate, sharecount, reference, comment, revertedShareTxUuid) values (uuid_generate_v4(), membership.uuid, 'SUBSCRIPTION', '2010-03-15', 4, 'ref '||givenPartnerNumber::text || givenMemberNumberSuffix||'-1', 'initial subscription', null), (uuid_generate_v4(), membership.uuid, 'CANCELLATION', '2021-09-01', -2, 'ref '||givenPartnerNumber::text || givenMemberNumberSuffix||'-2', 'cancelling some', null), diff --git a/src/test/java/net/hostsharing/hsadminng/hs/migration/BaseOfficeDataImport.java b/src/test/java/net/hostsharing/hsadminng/hs/migration/BaseOfficeDataImport.java index 70f21e11..ec4c7fec 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/migration/BaseOfficeDataImport.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/migration/BaseOfficeDataImport.java @@ -804,14 +804,14 @@ public abstract class BaseOfficeDataImport extends CsvDataImport { if (shareTransaction.getTransactionType() == HsOfficeCoopSharesTransactionType.ADJUSTMENT) { final var negativeValue = -shareTransaction.getShareCount(); - final var adjustedShareTx = coopShares.values().stream().filter(a -> + final var revertedShareTx = coopShares.values().stream().filter(a -> a.getTransactionType() != HsOfficeCoopSharesTransactionType.ADJUSTMENT && a.getMembership() == shareTransaction.getMembership() && a.getShareCount() == negativeValue) .findAny() .orElseThrow(() -> new IllegalStateException( "cannot determine share reverse entry for adjustment " + shareTransaction)); - shareTransaction.setAdjustedShareTx(adjustedShareTx); + shareTransaction.setRevertedShareTx(revertedShareTx); } coopShares.put(rec.getInteger("member_share_id"), shareTransaction); }); diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionControllerAcceptanceTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionControllerAcceptanceTest.java index a1e8a675..e07ac85b 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionControllerAcceptanceTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionControllerAcceptanceTest.java @@ -62,7 +62,7 @@ class HsOfficeCoopSharesTransactionControllerAcceptanceTest extends ContextBased } @Nested - class ListCoopSharesTransactions { + class getListOfCoopSharesTransactions { @Test void globalAdmin_canViewAllCoopSharesTransactions() { @@ -108,7 +108,7 @@ class HsOfficeCoopSharesTransactionControllerAcceptanceTest extends ContextBased "valueDate": "2022-10-20", "reference": "ref 1000202-3", "comment": "some subscription", - "adjustmentShareTx": { + "reversalShareTx": { "transactionType": "ADJUSTMENT", "shareCount": -2, "valueDate": "2022-10-21", @@ -122,7 +122,7 @@ class HsOfficeCoopSharesTransactionControllerAcceptanceTest extends ContextBased "valueDate": "2022-10-21", "reference": "ref 1000202-4", "comment": "some adjustment", - "adjustedShareTx": { + "revertedShareTx": { "transactionType": "SUBSCRIPTION", "shareCount": 2, "valueDate": "2022-10-20", @@ -213,16 +213,16 @@ class HsOfficeCoopSharesTransactionControllerAcceptanceTest extends ContextBased .header("current-subject", "superuser-alex@hostsharing.net") .contentType(ContentType.JSON) .body(""" - { - "membership.uuid": "%s", - "transactionType": "ADJUSTMENT", - "shareCount": %s, - "valueDate": "2022-10-30", - "reference": "test ref adjustment", - "comment": "some coop shares adjustment transaction", - "adjustedShareTx.uuid": "%s" - } - """.formatted( + { + "membership.uuid": "%s", + "transactionType": "ADJUSTMENT", + "shareCount": %s, + "valueDate": "2022-10-30", + "reference": "test ref adjustment", + "comment": "some coop shares adjustment transaction", + "revertedShareTx.uuid": "%s" + } + """.formatted( givenMembership.getUuid(), -givenTransaction.getShareCount(), givenTransaction.getUuid())) @@ -240,7 +240,7 @@ class HsOfficeCoopSharesTransactionControllerAcceptanceTest extends ContextBased "valueDate": "2022-10-30", "reference": "test ref adjustment", "comment": "some coop shares adjustment transaction", - "adjustedShareTx": { + "revertedShareTx": { "transactionType": "SUBSCRIPTION", "shareCount": 13, "valueDate": "2022-10-20", diff --git a/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntityUnitTest.java b/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntityUnitTest.java index 6d15cb78..8179f40e 100644 --- a/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntityUnitTest.java +++ b/src/test/java/net/hostsharing/hsadminng/hs/office/coopshares/HsOfficeCoopSharesTransactionEntityUnitTest.java @@ -27,7 +27,7 @@ class HsOfficeCoopSharesTransactionEntityUnitTest { .transactionType(HsOfficeCoopSharesTransactionType.ADJUSTMENT) .shareCount(-4) .comment("some comment") - .adjustedShareTx(givenCoopSharesTransaction) + .revertedShareTx(givenCoopSharesTransaction) .build(); final HsOfficeCoopSharesTransactionEntity givenEmptyCoopSharesTransaction = HsOfficeCoopSharesTransactionEntity.builder().build(); @@ -41,7 +41,7 @@ class HsOfficeCoopSharesTransactionEntityUnitTest { @Test void toStringWithReverseEntryContainsReverseEntry() { - givenCoopSharesTransaction.setAdjustedShareTx(givenCoopShareAdjustmentTransaction); + givenCoopSharesTransaction.setRevertedShareTx(givenCoopShareAdjustmentTransaction); final var result = givenCoopSharesTransaction.toString();