@Timed for bankAccounts and sepaMandates and Controller method name refactoring

This commit is contained in:
Michael Hoennig 2024-12-04 09:26:35 +01:00
parent 0559c8de97
commit 551537f1b1
11 changed files with 47 additions and 22 deletions

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.hs.office.bankaccount; package net.hostsharing.hsadminng.hs.office.bankaccount;
import io.micrometer.core.annotation.Timed;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficeBankAccountsApi; import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficeBankAccountsApi;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeBankAccountInsertResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeBankAccountInsertResource;
@ -31,7 +32,8 @@ public class HsOfficeBankAccountController implements HsOfficeBankAccountsApi {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public ResponseEntity<List<HsOfficeBankAccountResource>> listBankAccounts( @Timed("app.bankAccounts.api.patchDebitor")
public ResponseEntity<List<HsOfficeBankAccountResource>> getListOfBankAccounts(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final String holder) { final String holder) {
@ -45,7 +47,8 @@ public class HsOfficeBankAccountController implements HsOfficeBankAccountsApi {
@Override @Override
@Transactional @Transactional
public ResponseEntity<HsOfficeBankAccountResource> addBankAccount( @Timed("app.bankAccounts.api.postNewBankAccount")
public ResponseEntity<HsOfficeBankAccountResource> postNewBankAccount(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final HsOfficeBankAccountInsertResource body) { final HsOfficeBankAccountInsertResource body) {
@ -71,7 +74,8 @@ public class HsOfficeBankAccountController implements HsOfficeBankAccountsApi {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public ResponseEntity<HsOfficeBankAccountResource> getBankAccountByUuid( @Timed("app.bankAccounts.api.getSingleBankAccountByUuid")
public ResponseEntity<HsOfficeBankAccountResource> getSingleBankAccountByUuid(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final UUID bankAccountUuid) { final UUID bankAccountUuid) {
@ -87,6 +91,7 @@ public class HsOfficeBankAccountController implements HsOfficeBankAccountsApi {
@Override @Override
@Transactional @Transactional
@Timed("app.bankAccounts.api.deleteBankAccountByUuid")
public ResponseEntity<Void> deleteBankAccountByUuid( public ResponseEntity<Void> deleteBankAccountByUuid(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.hs.office.bankaccount; package net.hostsharing.hsadminng.hs.office.bankaccount;
import io.micrometer.core.annotation.Timed;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository; import org.springframework.data.repository.Repository;
@ -9,6 +10,7 @@ import java.util.UUID;
public interface HsOfficeBankAccountRepository extends Repository<HsOfficeBankAccountEntity, UUID> { public interface HsOfficeBankAccountRepository extends Repository<HsOfficeBankAccountEntity, UUID> {
@Timed("app.bankAccounts.repo.findByUuid")
Optional<HsOfficeBankAccountEntity> findByUuid(UUID id); Optional<HsOfficeBankAccountEntity> findByUuid(UUID id);
@Query(""" @Query("""
@ -16,16 +18,22 @@ public interface HsOfficeBankAccountRepository extends Repository<HsOfficeBankAc
WHERE lower(c.holder) like lower(concat(:holder, '%')) WHERE lower(c.holder) like lower(concat(:holder, '%'))
ORDER BY c.holder ORDER BY c.holder
""") """)
@Timed("app.bankAccounts.repo.findByOptionalHolderLikeImpl")
List<HsOfficeBankAccountEntity> findByOptionalHolderLikeImpl(String holder); List<HsOfficeBankAccountEntity> findByOptionalHolderLikeImpl(String holder);
default List<HsOfficeBankAccountEntity> findByOptionalHolderLike(String holder) { default List<HsOfficeBankAccountEntity> findByOptionalHolderLike(String holder) {
return findByOptionalHolderLikeImpl(holder == null ? "" : holder); return findByOptionalHolderLikeImpl(holder == null ? "" : holder);
} }
@Timed("app.bankAccounts.repo.findByIbanOrderByIbanAsc")
List<HsOfficeBankAccountEntity> findByIbanOrderByIbanAsc(String iban); List<HsOfficeBankAccountEntity> findByIbanOrderByIbanAsc(String iban);
@Timed("app.bankAccounts.repo.save")
<S extends HsOfficeBankAccountEntity> S save(S entity); <S extends HsOfficeBankAccountEntity> S save(S entity);
@Timed("app.bankAccounts.repo.deleteByUuid")
int deleteByUuid(final UUID uuid); int deleteByUuid(final UUID uuid);
@Timed("app.bankAccounts.repo.count")
long count(); long count();
} }

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.hs.office.sepamandate; package net.hostsharing.hsadminng.hs.office.sepamandate;
import io.micrometer.core.annotation.Timed;
import net.hostsharing.hsadminng.context.Context; import net.hostsharing.hsadminng.context.Context;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficeSepaMandatesApi; import net.hostsharing.hsadminng.hs.office.generated.api.v1.api.HsOfficeSepaMandatesApi;
import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeSepaMandateInsertResource; import net.hostsharing.hsadminng.hs.office.generated.api.v1.model.HsOfficeSepaMandateInsertResource;
@ -38,7 +39,8 @@ public class HsOfficeSepaMandateController implements HsOfficeSepaMandatesApi {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public ResponseEntity<List<HsOfficeSepaMandateResource>> listSepaMandatesByIban( @Timed("app.sepaMandates.api.getListOfSepaMandates")
public ResponseEntity<List<HsOfficeSepaMandateResource>> getListOfSepaMandates(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final String iban) { final String iban) {
@ -53,7 +55,8 @@ public class HsOfficeSepaMandateController implements HsOfficeSepaMandatesApi {
@Override @Override
@Transactional @Transactional
public ResponseEntity<HsOfficeSepaMandateResource> addSepaMandate( @Timed("app.sepaMandates.api.postNewSepaMandate")
public ResponseEntity<HsOfficeSepaMandateResource> postNewSepaMandate(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final HsOfficeSepaMandateInsertResource body) { final HsOfficeSepaMandateInsertResource body) {
@ -76,7 +79,8 @@ public class HsOfficeSepaMandateController implements HsOfficeSepaMandatesApi {
@Override @Override
@Transactional(readOnly = true) @Transactional(readOnly = true)
public ResponseEntity<HsOfficeSepaMandateResource> getSepaMandateByUuid( @Timed("app.sepaMandates.api.getSingleSepaMandateByUuid")
public ResponseEntity<HsOfficeSepaMandateResource> getSingleSepaMandateByUuid(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
final UUID sepaMandateUuid) { final UUID sepaMandateUuid) {
@ -93,6 +97,7 @@ public class HsOfficeSepaMandateController implements HsOfficeSepaMandatesApi {
@Override @Override
@Transactional @Transactional
@Timed("app.sepaMandates.api.deleteSepaMandateByUuid")
public ResponseEntity<Void> deleteSepaMandateByUuid( public ResponseEntity<Void> deleteSepaMandateByUuid(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,
@ -109,6 +114,7 @@ public class HsOfficeSepaMandateController implements HsOfficeSepaMandatesApi {
@Override @Override
@Transactional @Transactional
@Timed("app.sepaMandates.api.patchSepaMandate")
public ResponseEntity<HsOfficeSepaMandateResource> patchSepaMandate( public ResponseEntity<HsOfficeSepaMandateResource> patchSepaMandate(
final String currentSubject, final String currentSubject,
final String assumedRoles, final String assumedRoles,

View File

@ -1,5 +1,6 @@
package net.hostsharing.hsadminng.hs.office.sepamandate; package net.hostsharing.hsadminng.hs.office.sepamandate;
import io.micrometer.core.annotation.Timed;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository; import org.springframework.data.repository.Repository;
@ -9,6 +10,7 @@ import java.util.UUID;
public interface HsOfficeSepaMandateRepository extends Repository<HsOfficeSepaMandateEntity, UUID> { public interface HsOfficeSepaMandateRepository extends Repository<HsOfficeSepaMandateEntity, UUID> {
@Timed("app.sepaMandates.repo.findByUuid")
Optional<HsOfficeSepaMandateEntity> findByUuid(UUID id); Optional<HsOfficeSepaMandateEntity> findByUuid(UUID id);
@Query(""" @Query("""
@ -17,11 +19,15 @@ public interface HsOfficeSepaMandateRepository extends Repository<HsOfficeSepaMa
OR mandate.bankAccount.iban like concat(cast(:iban as text), '%') OR mandate.bankAccount.iban like concat(cast(:iban as text), '%')
ORDER BY mandate.bankAccount.iban ORDER BY mandate.bankAccount.iban
""") """)
@Timed("app.sepaMandates.repo.findSepaMandateByOptionalIban")
List<HsOfficeSepaMandateEntity> findSepaMandateByOptionalIban(String iban); List<HsOfficeSepaMandateEntity> findSepaMandateByOptionalIban(String iban);
@Timed("app.sepaMandates.repo.save")
HsOfficeSepaMandateEntity save(final HsOfficeSepaMandateEntity entity); HsOfficeSepaMandateEntity save(final HsOfficeSepaMandateEntity entity);
@Timed("app.sepaMandates.repo.count")
long count(); long count();
@Timed("app.sepaMandates.repo.deleteByUuid")
int deleteByUuid(UUID uuid); int deleteByUuid(UUID uuid);
} }

View File

@ -2,7 +2,7 @@ get:
tags: tags:
- hs-office-bank-accounts - hs-office-bank-accounts
description: 'Fetch a single bank account by its uuid, if visible for the current subject.' description: 'Fetch a single bank account by its uuid, if visible for the current subject.'
operationId: getBankAccountByUuid operationId: getSingleBankAccountByUuid
parameters: parameters:
- $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/currentSubject'
- $ref: 'auth.yaml#/components/parameters/assumedRoles' - $ref: 'auth.yaml#/components/parameters/assumedRoles'

View File

@ -3,7 +3,7 @@ get:
description: Returns the list of (optionally filtered) bankaccounts which are visible to the current subject or any of it's assumed roles. description: Returns the list of (optionally filtered) bankaccounts which are visible to the current subject or any of it's assumed roles.
tags: tags:
- hs-office-bank-accounts - hs-office-bank-accounts
operationId: listBankAccounts operationId: getListOfBankAccounts
parameters: parameters:
- $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/currentSubject'
- $ref: 'auth.yaml#/components/parameters/assumedRoles' - $ref: 'auth.yaml#/components/parameters/assumedRoles'
@ -31,7 +31,7 @@ post:
summary: Adds a new bank account. summary: Adds a new bank account.
tags: tags:
- hs-office-bank-accounts - hs-office-bank-accounts
operationId: addBankAccount operationId: postNewBankAccount
parameters: parameters:
- $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/currentSubject'
- $ref: 'auth.yaml#/components/parameters/assumedRoles' - $ref: 'auth.yaml#/components/parameters/assumedRoles'

View File

@ -2,7 +2,7 @@ get:
tags: tags:
- hs-office-sepaMandates - hs-office-sepaMandates
description: 'Fetch a single SEPA Mandate by its uuid, if visible for the current subject.' description: 'Fetch a single SEPA Mandate by its uuid, if visible for the current subject.'
operationId: getSepaMandateByUuid operationId: getSingleSepaMandateByUuid
parameters: parameters:
- $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/currentSubject'
- $ref: 'auth.yaml#/components/parameters/assumedRoles' - $ref: 'auth.yaml#/components/parameters/assumedRoles'

View File

@ -3,7 +3,7 @@ get:
description: Returns the list of (optionally filtered) SEPA Mandates which are visible to the current subject or any of it's assumed roles. description: Returns the list of (optionally filtered) SEPA Mandates which are visible to the current subject or any of it's assumed roles.
tags: tags:
- hs-office-sepaMandates - hs-office-sepaMandates
operationId: listSepaMandatesByIBAN operationId: getListOfSepaMandates
parameters: parameters:
- $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/currentSubject'
- $ref: 'auth.yaml#/components/parameters/assumedRoles' - $ref: 'auth.yaml#/components/parameters/assumedRoles'
@ -31,7 +31,7 @@ post:
summary: Adds a new SEPA Mandate. summary: Adds a new SEPA Mandate.
tags: tags:
- hs-office-sepaMandates - hs-office-sepaMandates
operationId: addSepaMandate operationId: postNewSepaMandate
parameters: parameters:
- $ref: 'auth.yaml#/components/parameters/currentSubject' - $ref: 'auth.yaml#/components/parameters/currentSubject'
- $ref: 'auth.yaml#/components/parameters/assumedRoles' - $ref: 'auth.yaml#/components/parameters/assumedRoles'

View File

@ -50,7 +50,7 @@ class HsOfficeBankAccountControllerAcceptanceTest extends ContextBasedTestWithCl
EntityManager em; EntityManager em;
@Nested @Nested
class ListBankAccounts { class GetListOfBankAccounts {
@Test @Test
void globalAdmin_withoutAssumedRoles_canViewAllBankAccounts_ifNoCriteriaGiven() throws JSONException { void globalAdmin_withoutAssumedRoles_canViewAllBankAccounts_ifNoCriteriaGiven() throws JSONException {
@ -117,7 +117,7 @@ class HsOfficeBankAccountControllerAcceptanceTest extends ContextBasedTestWithCl
class CreateBankAccount { class CreateBankAccount {
@Test @Test
void globalAdmin_withoutAssumedRole_canAddBankAccount() { void globalAdmin_withoutAssumedRole_canPostNewBankAccount() {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");

View File

@ -128,7 +128,7 @@ class HsOfficeBankAccountRepositoryIntegrationTest extends ContextBasedTestWithC
} }
@Nested @Nested
class ListBankAccounts { class GetListOfBankAccounts {
@Test @Test
public void globalAdmin_canViewAllBankAccounts() { public void globalAdmin_canViewAllBankAccounts() {

View File

@ -132,10 +132,10 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
} }
@Nested @Nested
class AddSepaMandate { class PostNewSepaMandate {
@Test @Test
void globalAdmin_canAddSepaMandate() { void globalAdmin_canPostNewSepaMandate() {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("Third").get(0); final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("Third").get(0);
@ -177,7 +177,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
// TODO.test: move validation tests to a ...WebMvcTest // TODO.test: move validation tests to a ...WebMvcTest
@Test @Test
void globalAdmin_canNotAddSepaMandateWhenDebitorUuidIsMissing() { void globalAdmin_canNotPostNewSepaMandateWhenDebitorUuidIsMissing() {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("Third").get(0); final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("Third").get(0);
@ -202,7 +202,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
} }
@Test @Test
void globalAdmin_canNotAddSepaMandate_ifBankAccountDoesNotExist() { void globalAdmin_canNotPostNewSepaMandate_ifBankAccountDoesNotExist() {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("Third").get(0); final var givenDebitor = debitorRepo.findDebitorByOptionalNameLike("Third").get(0);
@ -232,7 +232,7 @@ class HsOfficeSepaMandateControllerAcceptanceTest extends ContextBasedTestWithCl
} }
@Test @Test
void globalAdmin_canNotAddSepaMandate_ifPersonDoesNotExist() { void globalAdmin_canNotPostNewSepaMandate_ifPersonDoesNotExist() {
context.define("superuser-alex@hostsharing.net"); context.define("superuser-alex@hostsharing.net");
final var givenDebitorUuid = UUID.fromString("00000000-0000-0000-0000-000000000000"); final var givenDebitorUuid = UUID.fromString("00000000-0000-0000-0000-000000000000");