Skip to content

Commit 2a4edb0

Browse files
Use Case completed
1 parent c661bb2 commit 2a4edb0

7 files changed

Lines changed: 51 additions & 59 deletions

File tree

Java_FullStack/UseCase_examples/WebContent/fundTransfer.jsp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,23 @@
1414
customerId = request.getSession().getAttribute("cusId").toString();
1515
%>
1616

17-
Username: <%=username%><br />
18-
cus_id: <%=customerId %>
17+
<strong>Enter amount and account username transfer fund !</strong>
18+
19+
<br />
1920

2021

2122
<form action="${pageContext.request.contextPath}/operation" method="post">
2223
<p><font color="red">${errorMessage}</font></p>
2324
Amount: <input type="number" name="transferAmount" placeholder="transferAmount" required="required">
2425
<br/>
26+
<br/>
2527
Username: <input type="text" name="toUsername" placeholder="Username of another account" required="required">
2628
<br/>
29+
<br/>
2730

2831
<input type="hidden" name="action" value="transferFund">
2932
<input type="hidden" name="cusId" value="<%= customerId %>">
3033
<input type="hidden" name="username" value="<%= username %>">
31-
<input type="hidden" name="action" value="receiveFund">
3234
<input type="submit" name="transfer" id="transfer" value="Transfer"/>
3335
</form>
3436

Java_FullStack/UseCase_examples/WebContent/listTransactions.jsp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
</head>
1111
<body>
1212

13-
<p><font color="red">${successMessage}</font></p>
13+
<p><font color="red">${fundTransferMessage}</font></p>
1414
<strong>List Of Transactions</strong>
1515
<hr>
1616
<table border="1">
1717
<thead>
18-
<th>Transaction Amount</th>
19-
<th>Transaction Type</th>
18+
<th>Transfer to</th>
2019
<th>Transaction Date</th>
20+
<th>Transaction Amount</th>
2121
</thead>
2222

2323
<%
@@ -29,7 +29,7 @@
2929
if(size > 5) {
3030
for(int i=size -1;i>= (size-5) ;i--) {
3131
out.print("<tr>");
32-
out.print("<td>" +listTransactions.get(i).getTransc_type()+ "</td>");
32+
out.print("<td>" +listTransactions.get(i).getAccount_name()+ "</td>");
3333
out.print("<td>" +listTransactions.get(i).getTransc_date() + "</td>");
3434
out.print("<td>" +listTransactions.get(i).getTransc_amt() + "</td>");
3535
out.print("</tr>");
@@ -43,9 +43,9 @@
4343
} else {
4444
for(int i=size-1;i>=0;i--) {
4545
out.print("<tr>");
46-
out.print("<td>" +listTransactions.get(i).getTransc_amt() + "</td>");
47-
out.print("<td>" +listTransactions.get(i).getTransc_type()+ "</td>");
46+
out.print("<td>" +listTransactions.get(i).getAccount_name()+ "</td>");
4847
out.print("<td>" +listTransactions.get(i).getTransc_date() + "</td>");
48+
out.print("<td>" +listTransactions.get(i).getTransc_amt() + "</td>");
4949
out.print("</tr>");
5050
5151
}

Java_FullStack/UseCase_examples/WebContent/welcome.jsp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
sessionID = request.getSession().getId();
1919
%>
2020

21-
Username: <%=username%><br />
22-
cus_id: <%=customerId %><br />
23-
sessionID: <%=sessionID%>
21+
Welcome <%=username%> !<br />
22+
2423

2524
<ul>
2625
<li><a href="${pageContext.request.contextPath}/operation?page=history&cusId=<%= customerId %>">Transactions History</a></li>

Java_FullStack/UseCase_examples/src/divya/controller/OperationController.java

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
5050
request.getSession().invalidate();
5151
request.getRequestDispatcher("login.jsp").forward(request, response);
5252
break;
53-
case "receivefund":
54-
55-
String username = request.getParameter("username");
56-
int transferId = getCustomerId(username);
57-
int transferAmount = Integer.parseInt(request.getParameter("transferAmount"));
58-
crediToAccount(transferId, transferAmount, username);
59-
break;
53+
6054
default:
6155
errorPage(request, response);
6256
break;
@@ -70,11 +64,13 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
7064

7165
switch (action) {
7266
case "transferfund":
73-
String cusId = request.getParameter("cusId");
67+
int cusId = Integer.parseInt(request.getParameter("cusId"));
7468
transferFund(request, response);
7569

70+
String username = request.getParameter("username");
71+
request.setAttribute("fundTransferMessage", "Funds transferred to" + username);
7672
response.sendRedirect(request.getContextPath()+"/operation?page=history&cusId=" + cusId);
77-
73+
//crediToAccount(request, response);
7874
break;
7975

8076
default:
@@ -85,18 +81,18 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
8581

8682

8783
private void transferFund(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
88-
int transferAmount = Integer.parseInt(request.getParameter("transferAmount"));
8984

90-
String username = request.getParameter("toUsername");
85+
int transferAmount = Integer.parseInt(request.getParameter("transferAmount"));
9186

87+
String toUsername = request.getParameter("toUsername");
9288
int cusId = Integer.parseInt(request.getParameter("cusId"));
93-
9489
int balance = getBalanceById(cusId);
9590

96-
97-
String type = "debit";
9891

99-
if(balance < transferAmount) {
92+
String username = request.getParameter("username");
93+
int transferId = getCustomerId(username);
94+
95+
if((balance - 500) < transferAmount) {
10096
// implement if balance is < transfer amount
10197
request.setAttribute("errorMessage", "Insufficient balance");
10298
request.getRequestDispatcher("fundTransfer.jsp").forward(request, response);
@@ -108,15 +104,24 @@ private void transferFund(HttpServletRequest request, HttpServletResponse respon
108104
Customers newBalance = new Customers(cusId, balance);
109105
updateBalance(newBalance);
110106

111-
Transactions newTransaction1 = new Transactions(cusId, transferAmount, type, username);
107+
Transactions newTransaction1 = new Transactions(cusId, transferAmount, toUsername);
112108
addTransaction(newTransaction1);
113109

110+
//crediToAccount(transferId, transferAmount, username, cusId);
114111
}
115112
return;
116113
}
117114

118-
119-
public void crediToAccount(int transferId, int transferAmount, String username){
115+
// response.sendRedirect(request.getContextPath()+"/operation?page=history&cusId=" + cusId);
116+
/*
117+
public void crediToAccount(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
118+
119+
String username = request.getParameter("username");
120+
int transferId = getCustomerId(username);
121+
122+
123+
int transferAmount = Integer.parseInt(request.getParameter("transferAmount"));
124+
120125
121126
int balance = getBalanceById(transferId);
122127
balance = balance + transferAmount;
@@ -128,9 +133,12 @@ public void crediToAccount(int transferId, int transferAmount, String username){
128133
129134
Transactions newTransaction = new Transactions(transferId, transferAmount, type, username);
130135
addTransaction(newTransaction);
136+
131137
return;
132138
}
133139
140+
*/
141+
134142
private void addTransaction(Transactions newTransaction) {
135143

136144
new TransactionsModel().addTransaction(newTransaction, dataSource);
@@ -169,7 +177,8 @@ private void getBalance(HttpServletRequest request, HttpServletResponse response
169177

170178
request.setAttribute("balanceRemained", getBalance);
171179
request.getRequestDispatcher("balance.jsp").forward(request, response);
172-
180+
181+
return;
173182
}
174183

175184
//getting balance

Java_FullStack/UseCase_examples/src/divya/entity/Transactions.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,31 @@ public class Transactions {
99
private int tranc_id;
1010
private int cus_id;
1111
private int transc_amt;
12-
private String transc_type;
1312
private Date transc_date;
1413
private String account_name;
1514

16-
public Transactions(int tranc_id, int cus_id, int transc_amt, String transc_type, Date transc_date) {
15+
public Transactions(int tranc_id, int cus_id, int transc_amt, Date transc_date) {
1716
this.tranc_id = tranc_id;
1817
this.cus_id = cus_id;
1918
this.transc_amt = transc_amt;
20-
this.transc_type = transc_type;
2119
this.transc_date = transc_date;
2220
}
2321

2422

25-
public Transactions(int cus_id, int transc_amt, String transc_type, String account_name) {
23+
public Transactions(int cus_id, int transc_amt, String account_name) {
2624
this.cus_id = cus_id;
2725
this.transc_amt = transc_amt;
28-
this.transc_type = transc_type;
2926
this.account_name = account_name;
3027
}
3128

3229

33-
public Transactions(int transc_amt, String transc_type, Date transc_date, String account_name) {
30+
public Transactions(int transc_amt, Date transc_date, String account_name) {
3431
this.transc_amt = transc_amt;
35-
this.transc_type = transc_type;
3632
this.transc_date = transc_date;
3733
this.account_name = account_name;
3834
}
3935

4036

41-
public Transactions(int transc_amt, String transc_type) {
42-
43-
this.transc_amt = transc_amt;
44-
this.transc_type = transc_type;
45-
}
46-
47-
4837
public int getTranc_id() {
4938
return tranc_id;
5039
}
@@ -63,12 +52,7 @@ public int getTransc_amt() {
6352
public void setTransc_amt(int transc_amt) {
6453
this.transc_amt = transc_amt;
6554
}
66-
public String getTransc_type() {
67-
return transc_type;
68-
}
69-
public void setTransc_type(String transc_type) {
70-
this.transc_type = transc_type;
71-
}
55+
7256
public Date getTransc_date() {
7357
return transc_date;
7458
}

Java_FullStack/UseCase_examples/src/divya/model/CustomersModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public HashMap<String, String> listCustomers(DataSource dataSource) {
5050
try {
5151
connect = dataSource.getConnection();
5252

53-
String query = "select cus_id, username, password from customers";
53+
String query = "select username, password from customers";
5454
stmt = connect.createStatement();
5555

5656
rs = stmt.executeQuery(query);

Java_FullStack/UseCase_examples/src/divya/model/TransactionsModel.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ public List<Transactions> listTransactionsById(int customerId, DataSource dataSo
2828
connect = dataSource.getConnection();
2929
int cus_id = customerId;
3030
//2. create sql query
31-
String query = "select tranc_amt, tranc_type, tranc_date, account_name from transactions where cus_id =" + cus_id;
31+
String query = "select tranc_amt, tranc_date, account_name from transactions where cus_id =" + cus_id;
3232
stmt = connect.createStatement();
3333

3434
rs = stmt.executeQuery(query);
3535
while(rs.next()) {
36-
listUsers.add(new Transactions(rs.getInt("tranc_amt"), rs.getString("tranc_type"), rs.getDate("tranc_date"), rs.getString("account_name")));
36+
listUsers.add(new Transactions(rs.getInt("tranc_amt"), rs.getDate("tranc_date"), rs.getString("account_name")));
3737

3838
}
3939
} catch (SQLException e) {
@@ -52,7 +52,6 @@ public void addTransaction(Transactions newTransaction, DataSource dataSource )
5252

5353
int cus_id = newTransaction.getCus_id();
5454
int tranc_amt = newTransaction.getTransc_amt();
55-
String tranc_type = newTransaction.getTransc_type();
5655
String account_name = newTransaction.getAccount_name();
5756

5857
java.util.Date date=new java.util.Date();
@@ -61,13 +60,12 @@ public void addTransaction(Transactions newTransaction, DataSource dataSource )
6160
java.sql.Date tranc_date = new java.sql.Date(calendar.getTime().getTime());
6261

6362

64-
String query = "insert into transactions (cus_id, tranc_amt, tranc_type, tranc_date, account_name) values (?, ?, ?, ?, ?)";
63+
String query = "insert into transactions (cus_id, tranc_amt, tranc_date, account_name) values (?, ?, ?, ?)";
6564
mySt = conn.prepareStatement(query);
6665
mySt.setInt(1, cus_id);
6766
mySt.setInt(2, tranc_amt);
68-
mySt.setString(3, tranc_type);
69-
mySt.setDate(4, tranc_date);
70-
mySt.setString(5, account_name);
67+
mySt.setDate(3, tranc_date);
68+
mySt.setString(4, account_name);
7169

7270
mySt.executeUpdate();
7371

0 commit comments

Comments
 (0)