-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MMCA-4972 : Implement search by a specific payment and View transacti…
…ons on the Cash Account dashboard (#180) * MMCA-4972 : Implemented search by a specific payment * MMCa-4972 : fixed test case 01 * MMCA-4972 : fixed PR comments 01 * MMCA-4972 : changed from valueDate to postingDate to match Acc31 * MMCA-4972 : PR Comment fixes 02
- Loading branch information
Showing
27 changed files
with
1,674 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright 2023 HM Revenue & Customs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package controllers | ||
|
||
import config.{AppConfig, ErrorHandler} | ||
import connectors.CustomsFinancialsApiConnector | ||
import controllers.actions.{EmailAction, IdentifierAction} | ||
import models.response.CashAccountTransactionSearchResponseDetail | ||
import models.CashAccount | ||
import models.request.IdentifierRequest | ||
import play.api.Logging | ||
import play.api.i18n.I18nSupport | ||
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} | ||
import repositories.CashAccountSearchRepository | ||
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController | ||
import utils.Utils.{buildCacheId, extractNumericValue} | ||
import viewmodels.PaymentSearchResultsViewModel | ||
import views.html.{cash_account_declaration_details_search_no_result, cash_account_payment_search} | ||
|
||
import javax.inject.Inject | ||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
class CashAccountPaymentSearchController @Inject()(authenticate: IdentifierAction, | ||
verifyEmail: EmailAction, | ||
apiConnector: CustomsFinancialsApiConnector, | ||
errorHandler: ErrorHandler, | ||
mcc: MessagesControllerComponents, | ||
paymentSearchView: cash_account_payment_search, | ||
searchRepository: CashAccountSearchRepository, | ||
noSearchResultView: cash_account_declaration_details_search_no_result | ||
)(implicit executionContext: ExecutionContext, | ||
appConfig: AppConfig | ||
) extends FrontendController(mcc) with I18nSupport with Logging { | ||
|
||
def search(searchValue: String, | ||
page: Option[Int]): Action[AnyContent] = (authenticate andThen verifyEmail).async { implicit request => | ||
|
||
apiConnector.getCashAccount(request.eori).flatMap { | ||
case Some(account) => processCashAccountDetails(searchValue, account, page) | ||
case None => Future.successful(NotFound(errorHandler.notFoundTemplate)) | ||
} | ||
} | ||
|
||
private def processCashAccountDetails(searchValue: String, | ||
account: CashAccount, | ||
page: Option[Int])(implicit request: IdentifierRequest[AnyContent]) = { | ||
|
||
searchRepository.get(buildCacheId(account.number, extractNumericValue(searchValue))).flatMap { | ||
case Some(paymentTransfers) => processPaymentTransfersAndDisplayView(searchValue, account, paymentTransfers, page) | ||
case None => Future.successful(Ok(noSearchResultView(page, account.number, searchValue))) | ||
} | ||
} | ||
|
||
private def processPaymentTransfersAndDisplayView(searchValue: String, | ||
account: CashAccount, | ||
paymentTransfers: CashAccountTransactionSearchResponseDetail, | ||
page: Option[Int]) | ||
(implicit request: IdentifierRequest[AnyContent]) = { | ||
|
||
paymentTransfers.paymentsWithdrawalsAndTransfers match { | ||
case Some(paymentsWithdrawalsAndTransfers) => | ||
val paymentTransfersList = paymentsWithdrawalsAndTransfers.map(_.paymentsWithdrawalsAndTransfer) | ||
|
||
Future.successful( | ||
Ok(paymentSearchView(PaymentSearchResultsViewModel(searchValue, account, paymentTransfersList, page))) | ||
) | ||
|
||
case None => Future.successful(Ok(noSearchResultView(page, account.number, searchValue))) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
app/crypto/CashAccountTransactionSearchResponseDetailEncrypter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2023 HM Revenue & Customs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package crypto | ||
|
||
import models.* | ||
import models.response.CashAccountTransactionSearchResponseDetail | ||
import play.api.libs.json.Json | ||
import javax.inject.Inject | ||
|
||
class CashAccountTransactionSearchResponseDetailEncrypter @Inject()(crypto: AesGCMCrypto) { | ||
|
||
def encryptSearchResponseDetail(cashTransactions: CashAccountTransactionSearchResponseDetail, | ||
key: String): EncryptedValue = { | ||
val json = Json.toJson(cashTransactions).toString() | ||
crypto.encrypt(json, key) | ||
} | ||
|
||
def decryptSearchResponseDetail(encryptedData: EncryptedValue, | ||
key: String): CashAccountTransactionSearchResponseDetail = { | ||
val decryptedJson = crypto.decrypt(encryptedData, key) | ||
Json.parse(decryptedJson).as[CashAccountTransactionSearchResponseDetail] | ||
} | ||
|
||
} |
Oops, something went wrong.