You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
191 lines
8.3 KiB
Java
191 lines
8.3 KiB
Java
package com.mfsys.uco.controller;
|
|
|
|
import com.itextpdf.kernel.pdf.PdfDocument;
|
|
import com.itextpdf.kernel.pdf.PdfWriter;
|
|
import com.itextpdf.layout.element.Paragraph;
|
|
import com.itextpdf.layout.Document;
|
|
import com.mfsys.uco.constants.UCOURI;
|
|
import com.mfsys.uco.model.AccountDetail;
|
|
import com.mfsys.uco.model.CustomerProfile;
|
|
import com.mfsys.uco.request.*;
|
|
import com.mfsys.uco.response.*;
|
|
import com.mfsys.uco.service.*;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.util.ArrayList;
|
|
import java.util.Base64;
|
|
import java.util.List;
|
|
|
|
@RestController
|
|
@RequestMapping
|
|
public class UserController {
|
|
|
|
private final UcoAccountService ucoAccountService;
|
|
private final CustomerProfileService customerProfileService;
|
|
private final TransactionPinService transactionPinService;
|
|
private final CustomerAccountActivityService customerAccountActivityService;
|
|
private final NotificationService notificationService;
|
|
|
|
public UserController(
|
|
UcoAccountService ucoAccountService,
|
|
CustomerProfileService customerProfileService,
|
|
TransactionPinService transactionPinService,
|
|
CustomerAccountActivityService customerAccountActivityService,
|
|
NotificationService notificationService) {
|
|
this.ucoAccountService = ucoAccountService;
|
|
this.customerProfileService = customerProfileService;
|
|
this.transactionPinService = transactionPinService;
|
|
this.customerAccountActivityService = customerAccountActivityService;
|
|
this.notificationService = notificationService;
|
|
}
|
|
|
|
@PostMapping(UCOURI.ONBOARD_CUSTOMER)
|
|
public ResponseEntity<HttpStatus> customerOnBoarding(@RequestBody SignupStep3Request signupStep3Request) {
|
|
ucoAccountService.onBoardCustomer(signupStep3Request);
|
|
return ResponseEntity.ok(HttpStatus.OK);
|
|
}
|
|
|
|
@PostMapping(UCOURI.VIEW_BALANCE)
|
|
public ViewBalanceResponse viewBalance(@RequestBody ViewBalanceRequest viewBalanceRequest) {
|
|
ViewBalanceResponse viewBalanceResponse = new ViewBalanceResponse();
|
|
viewBalanceResponse.setMbmBkmsbalance(ucoAccountService.fetchAccountBalance(viewBalanceRequest.getPorOrgacode(), viewBalanceRequest.getMbmBkmsNumber()));
|
|
return viewBalanceResponse;
|
|
}
|
|
|
|
@GetMapping(UCOURI.FETCH_LOGIIN_DATA)
|
|
public CustomerProfile fetchlogindata(@RequestParam String porOrgacode, @RequestParam String email) {
|
|
return customerProfileService.fetchCustcodeBasedOnEmail(porOrgacode, email);
|
|
}
|
|
|
|
@GetMapping(UCOURI.FETCH_DEPOSITACCOUNTS)
|
|
public List<AccountDetail> getDepositAccounts(
|
|
@RequestParam String porOrgacode,
|
|
@RequestParam String cmpCustcode,
|
|
@RequestParam String pctCstycode) {
|
|
return ucoAccountService.fetchdepositAccountFromCiihive(porOrgacode, cmpCustcode);
|
|
}
|
|
|
|
@GetMapping(UCOURI.FETCH_ACCOUNT_STATEMENT)
|
|
public List<DepositAccountTransactionResponse> getAccountStatement(
|
|
@RequestParam String porOrgacode,
|
|
@RequestParam String mbmBkmsnumber,
|
|
@RequestParam String sgtGntrvaluedatefrom,
|
|
@RequestParam String sgtGntrvaluedateto
|
|
) {
|
|
|
|
List<DepositAccountTransactionResponse> transactions = new ArrayList<>();
|
|
DepositAccountTransactionResponse transaction = new DepositAccountTransactionResponse();
|
|
transaction.setTranID("12345");
|
|
transaction.setSgtGntrCreatedAt("2024-03-17");
|
|
transaction.setSgtGntrNarration("Sample Transaction");
|
|
transaction.setSgtGntrvaluedate("2024-03-17");
|
|
transaction.setDeposit("100.00");
|
|
transaction.setWithdrawal("0.00");
|
|
transaction.setStatus("approved");
|
|
transaction.setSgtGntramt("1000.00");
|
|
transactions.add(transaction);
|
|
return transactions;
|
|
}
|
|
|
|
@GetMapping(UCOURI.FETCH_ACCOUNT_INQUIRY)
|
|
public List<AccountInquiryResponse> getAccountInquiry(
|
|
@RequestParam String acntTypeCode,
|
|
@RequestParam String acntTypeValue,
|
|
@RequestParam String porOrgacode,
|
|
@RequestParam String channelCode) {
|
|
return ucoAccountService.fetchAccountTitile(porOrgacode, acntTypeCode, acntTypeValue);
|
|
}
|
|
|
|
@PostMapping(UCOURI.GENERATE_TRANSACTIONS_REPORT)
|
|
public String generateReport(@RequestBody TransactionHistoryRequest request) {
|
|
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
|
|
PdfWriter writer = new PdfWriter(baos);
|
|
PdfDocument pdf = new PdfDocument(writer);
|
|
Document document = new Document(pdf);
|
|
document.add(new Paragraph("Account Transaction History Report"));
|
|
document.add(new Paragraph("Organization Code: " + request.getPorOrgacode()));
|
|
document.add(new Paragraph("Account Number: " + request.getMbmBkmsnumber()));
|
|
document.add(new Paragraph("From: " + request.getSgtGntrvaluedatefrom() + " To: " + request.getSgtGntrvaluedateto()));
|
|
document.close();
|
|
return Base64.getEncoder().encodeToString(baos.toByteArray());
|
|
} catch (Exception e) {
|
|
return "Error generating report";
|
|
}
|
|
}
|
|
|
|
@PostMapping(UCOURI.CREATE_TRAN_PIN)
|
|
public ResponseEntity<HttpStatus> createTransactionPin(@RequestBody CreateTransactionPinRequest request) {
|
|
transactionPinService.createTransactionPin(request);
|
|
return ResponseEntity.ok(HttpStatus.OK);
|
|
}
|
|
|
|
@PostMapping(UCOURI.VERIFY_TRAN_PIN)
|
|
public ResponseEntity<?> verifyPin(@RequestBody VerifyPinRequest request) {
|
|
transactionPinService.verifyOTPAndSavePin(request);
|
|
return ResponseEntity.ok(HttpStatus.OK);
|
|
}
|
|
|
|
@PutMapping(UCOURI.CHANGE_TRAN_PIN)
|
|
public ResponseEntity<String> updateTransactionPin(@RequestBody ChangeTransactionPinRequest request) {
|
|
transactionPinService.updateTransactionPin(request);
|
|
return ResponseEntity.ok("OTP sent");
|
|
}
|
|
|
|
@GetMapping(UCOURI.FETCH_EXCHANGE_RATE)
|
|
public Object fetchExchangeRate(@RequestParam String porOrgacode) {
|
|
return ucoAccountService.fetchExchangeRate(porOrgacode);
|
|
}
|
|
|
|
@GetMapping(UCOURI.ACCOUNT_ACTIVITY)
|
|
public ResponseEntity<List<CustomerAccountActivityResponse>> getCustomerAccountActivity(
|
|
@PathVariable String porOrgacode,
|
|
@PathVariable String cmpCustcode,
|
|
@PathVariable String fdate,
|
|
@PathVariable String tdate) {
|
|
return new ResponseEntity<>(customerAccountActivityService.getCustomerAccountActivity(porOrgacode, cmpCustcode, fdate, tdate), HttpStatus.OK);
|
|
}
|
|
|
|
@PostMapping(UCOURI.RESEND_OTP)
|
|
@ResponseStatus(HttpStatus.OK)
|
|
public ResponseEntity<String> sendSignUpOtp(@RequestBody OTPRequest otpRequest) {
|
|
notificationService.sendOtp(otpRequest);
|
|
return ResponseEntity.ok("OTP sent");
|
|
}
|
|
|
|
@PostMapping(UCOURI.ADD_UCO_CUSTOMER_ACCOUNT)
|
|
public ResponseEntity<HttpStatus> addUcoCustomerAccount(@RequestBody AddAccountRequest addAccountRequest) {
|
|
ucoAccountService.addUcoAccount(addAccountRequest);
|
|
return ResponseEntity.ok(HttpStatus.OK);
|
|
}
|
|
|
|
@PostMapping(UCOURI.UPDATE_CUSTOMER_PROFILE)
|
|
public ResponseEntity<HttpStatus> updateCustomerProfile(@RequestBody UpdateProfileRequest updateProfileRequest) {
|
|
customerProfileService.updateCustomerProfile(updateProfileRequest);
|
|
return ResponseEntity.ok(HttpStatus.OK);
|
|
}
|
|
|
|
@PostMapping(UCOURI.ADD_BENEFICIARY)
|
|
public ResponseEntity<HttpStatus> updateCustomerProfile(@RequestBody BeneficiaryRequest beneficiaryRequest) {
|
|
customerProfileService.addBeneficiary(beneficiaryRequest);
|
|
return ResponseEntity.ok(HttpStatus.OK);
|
|
}
|
|
|
|
@GetMapping(UCOURI.GET_BENEFICIARY)
|
|
public List<BeneficiaryResponse> updateCustomerProfile(@RequestParam String porOrgacode, @RequestParam String email) {
|
|
return customerProfileService.fetchBeneficiaryBasedOnEmail(porOrgacode,email);
|
|
}
|
|
|
|
@DeleteMapping(UCOURI.DELETE_BENEFICIARY)
|
|
public ResponseEntity<Void> deleteBeneficiary(
|
|
@RequestParam String mbmBkmsnumberRef,
|
|
@RequestParam String porOrgacode,
|
|
@RequestParam String email) {
|
|
customerProfileService.deleteBeneficiary(porOrgacode,email,mbmBkmsnumberRef);
|
|
return ResponseEntity.noContent().build();
|
|
}
|
|
}
|