diff --git a/src/main/java/de/financer/controller/AccountController.java b/src/main/java/de/financer/controller/AccountController.java index 9cff5f9..12e318f 100644 --- a/src/main/java/de/financer/controller/AccountController.java +++ b/src/main/java/de/financer/controller/AccountController.java @@ -10,6 +10,9 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; + @RestController @RequestMapping("accounts") public class AccountController { @@ -21,7 +24,13 @@ public class AccountController { @RequestMapping("getByKey") public Account getAccountByKey(String key) { - return this.accountService.getAccountByKey(key); + final String decoded = URLDecoder.decode(key, StandardCharsets.UTF_8); + + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(String.format("/accounts/getAccountByKey got parameter: %s", decoded)); + } + + return this.accountService.getAccountByKey(decoded); } @RequestMapping("getAll") @@ -31,11 +40,13 @@ public class AccountController { @RequestMapping("createAccount") public ResponseEntity createAccount(String key, String type) { + final String decoded = URLDecoder.decode(key, StandardCharsets.UTF_8); + if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("/accounts/createAccount got parameters: %s, %s", key, type)); + LOGGER.debug(String.format("/accounts/createAccount got parameters: %s, %s", decoded, type)); } - final ResponseReason responseReason = this.accountService.createAccount(key, type); + final ResponseReason responseReason = this.accountService.createAccount(decoded, type); if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("/accounts/createAccount returns with %s", responseReason.name())); @@ -46,11 +57,13 @@ public class AccountController { @RequestMapping("closeAccount") public ResponseEntity closeAccount(String key) { + final String decoded = URLDecoder.decode(key, StandardCharsets.UTF_8); + if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("/accounts/closeAccount got parameters: %s", key)); + LOGGER.debug(String.format("/accounts/closeAccount got parameters: %s", decoded)); } - final ResponseReason responseReason = this.accountService.closeAccount(key); + final ResponseReason responseReason = this.accountService.closeAccount(decoded); if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("/accounts/closeAccount returns with %s", responseReason.name())); @@ -61,11 +74,13 @@ public class AccountController { @RequestMapping("openAccount") public ResponseEntity openAccount(String key) { + final String decoded = URLDecoder.decode(key, StandardCharsets.UTF_8); + if (LOGGER.isDebugEnabled()) { - LOGGER.debug(String.format("/accounts/openAccount got parameters: %s", key)); + LOGGER.debug(String.format("/accounts/openAccount got parameters: %s", decoded)); } - final ResponseReason responseReason = this.accountService.openAccount(key); + final ResponseReason responseReason = this.accountService.openAccount(decoded); if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("/accounts/openAccount returns with %s", responseReason.name())); diff --git a/src/main/java/de/financer/controller/RecurringTransactionController.java b/src/main/java/de/financer/controller/RecurringTransactionController.java index 2d495d8..dc8ba26 100644 --- a/src/main/java/de/financer/controller/RecurringTransactionController.java +++ b/src/main/java/de/financer/controller/RecurringTransactionController.java @@ -10,6 +10,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.util.Optional; @RestController @@ -33,7 +35,13 @@ public class RecurringTransactionController { @RequestMapping("getAllForAccount") public Iterable getAllForAccount(String accountKey) { - return this.recurringTransactionService.getAllForAccount(accountKey); + final String decoded = URLDecoder.decode(accountKey, StandardCharsets.UTF_8); + + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(String.format("/recurringTransactions/getAllForAccount got parameter: %s", decoded)); + } + + return this.recurringTransactionService.getAllForAccount(decoded); } @RequestMapping("getAllDueToday") @@ -47,15 +55,18 @@ public class RecurringTransactionController { String intervalType, String firstOccurrence, String lastOccurrence ) { + final String decodedFrom = URLDecoder.decode(fromAccountKey, StandardCharsets.UTF_8); + final String decodedTo = URLDecoder.decode(toAccountKey, StandardCharsets.UTF_8); + if (LOGGER.isDebugEnabled()) { LOGGER.debug(String .format("/recurringTransactions/createRecurringTransaction got parameters: %s, %s, %s, %s, %s, " + - "%s, %s, %s", fromAccountKey, toAccountKey, amount, description, holidayWeekendType, + "%s, %s, %s", decodedFrom, decodedTo, amount, description, holidayWeekendType, intervalType, firstOccurrence, lastOccurrence)); } final ResponseReason responseReason = this.recurringTransactionService - .createRecurringTransaction(fromAccountKey, toAccountKey, amount, description, holidayWeekendType, + .createRecurringTransaction(decodedFrom, decodedTo, amount, description, holidayWeekendType, intervalType, firstOccurrence, lastOccurrence); if (LOGGER.isDebugEnabled()) { diff --git a/src/main/java/de/financer/controller/TransactionController.java b/src/main/java/de/financer/controller/TransactionController.java index 276a3f4..bce51d3 100644 --- a/src/main/java/de/financer/controller/TransactionController.java +++ b/src/main/java/de/financer/controller/TransactionController.java @@ -10,6 +10,9 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; + @RestController @RequestMapping("transactions") public class TransactionController { @@ -25,21 +28,30 @@ public class TransactionController { @RequestMapping("getAllForAccount") public Iterable getAllForAccount(String accountKey) { - return this.transactionService.getAllForAccount(accountKey); + final String decoded = URLDecoder.decode(accountKey, StandardCharsets.UTF_8); + + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(String.format("/transactions/getAllForAccount got parameter: %s", decoded)); + } + + return this.transactionService.getAllForAccount(decoded); } @RequestMapping(value = "createTransaction") public ResponseEntity createTransaction(String fromAccountKey, String toAccountKey, Long amount, String date, String description ) { + final String decodedFrom = URLDecoder.decode(fromAccountKey, StandardCharsets.UTF_8); + final String decodedTo = URLDecoder.decode(toAccountKey, StandardCharsets.UTF_8); + if (LOGGER.isDebugEnabled()) { LOGGER.debug(String .format("/transactions/createTransaction got parameters: %s, %s, %s, %s, %s", - fromAccountKey, toAccountKey, amount, date, description)); + decodedFrom, decodedTo, amount, date, description)); } final ResponseReason responseReason = this.transactionService - .createTransaction(fromAccountKey, toAccountKey, amount, date, description); + .createTransaction(decodedFrom, decodedTo, amount, date, description); if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("/transactions/createTransaction returns with %s", responseReason.name()));