Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
update profile user (history buy)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakaqc committed Nov 28, 2023
1 parent d451432 commit 55b7d8a
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 139 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.bakaqc.flower.controller;

import com.bakaqc.flower.dao.OrderDAO;
import com.bakaqc.flower.model.HistoryBuy;
import com.bakaqc.flower.model.User;
import java.io.*;
import java.util.List;
import javax.servlet.*;
import javax.servlet.http.*;

Expand All @@ -18,9 +20,11 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
User us = (User) session.getAttribute("user");
int amountSold = OrderDAO.getInstance().quantitySold(us.getId());
int amountCan = OrderDAO.getInstance().amountCanceled(us.getId());
List<HistoryBuy> list = OrderDAO.getInstance().historyBuy(us.getId());

request.setAttribute("amountS", amountSold);
request.setAttribute("amountC", amountCan);
request.setAttribute("listBuy", list);
request.getRequestDispatcher("/view/user_profile.jsp").forward(request, response);
}

Expand Down
42 changes: 38 additions & 4 deletions src/main/java/com/bakaqc/flower/dao/OrderDAO.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.bakaqc.flower.dao;

import com.bakaqc.flower.model.HistoryBuy;
import com.bakaqc.flower.model.Order;
import com.bakaqc.flower.model.option.OrderStatus;
import com.bakaqc.flower.model.option.Payment;
Expand Down Expand Up @@ -82,7 +83,7 @@ public List<Order> selectById(String id) {
return list;
}

public int quantitySold(int userID ) {
public int quantitySold(int userID) {
int amount = 0;

try {
Expand All @@ -104,8 +105,8 @@ public int quantitySold(int userID ) {

return amount;
}
public int amountCanceled(int userID ) {

public int amountCanceled(int userID) {
int amount = 0;

try {
Expand Down Expand Up @@ -186,8 +187,41 @@ public void delete(String id) {
}
}

public List<HistoryBuy> historyBuy(int userId) {

List<HistoryBuy> list = new ArrayList<>();
try {
Connection conn = JDBC.getConnection();

PreparedStatement smt = conn.prepareStatement("SELECT o.user_id, p.banners, p.name, d.amount, o.total_price, o.payment, o.status, o.create_at "
+ "FROM `data_order` d JOIN `order` o ON d.order_id = o.id JOIN `product` p ON d.product_id = p.id WHERE o.user_id = ? ORDER BY o.id DESC");
smt.setInt(1, userId);

ResultSet rs = smt.executeQuery();

while (rs.next()) {
HistoryBuy hb = new HistoryBuy();
hb.setBannersP(rs.getString("banners"));
hb.setNameP(rs.getString("name"));
hb.setAmountP(rs.getInt("amount"));
hb.setTotalPriceP(rs.getInt("total_price"));
hb.setPaymentP(Payment.create(rs.getString("payment")));
hb.setStatusP(OrderStatus.create(rs.getString("status")));
hb.setCreateAtP(Convert.convert(rs.getTimestamp("create_at")));

list.add(hb);
}

JDBC.closeConnection(conn);
} catch (SQLException ex) {
System.err.println(ex.getMessage());
}
System.out.println(list);
return list;
}

public static void main(String[] args) {
System.out.println(getInstance().amountCanceled(4));
getInstance().historyBuy(2);

}
}
111 changes: 111 additions & 0 deletions src/main/java/com/bakaqc/flower/model/HistoryBuy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.bakaqc.flower.model;

import com.bakaqc.flower.model.option.OrderStatus;
import com.bakaqc.flower.model.option.Payment;
import java.time.LocalDateTime;

public class HistoryBuy {
private int userID;
private String bannersP;
private String nameP;
private int amountP;
private int totalPriceP;
private Payment paymentP;
private OrderStatus statusP;
private LocalDateTime createAtP;

public HistoryBuy() {
}

public HistoryBuy(int userID, String bannersP, String nameP, int amountP, int totalPriceP, Payment paymentP, OrderStatus statusP, LocalDateTime createAtP) {
this.userID = userID;
this.bannersP = bannersP;
this.nameP = nameP;
this.amountP = amountP;
this.totalPriceP = totalPriceP;
this.paymentP = paymentP;
this.statusP = statusP;
this.createAtP = createAtP;
}

public HistoryBuy(String bannersP, String nameP, int amountP, int totalPriceP, Payment paymentP, OrderStatus statusP, LocalDateTime createAtP) {
this.bannersP = bannersP;
this.nameP = nameP;
this.amountP = amountP;
this.totalPriceP = totalPriceP;
this.paymentP = paymentP;
this.statusP = statusP;
this.createAtP = createAtP;
}

public int getUserID() {
return userID;
}

public void setUserID(int userID) {
this.userID = userID;
}

public String getBannersP() {
return bannersP;
}

public void setBannersP(String bannersP) {
this.bannersP = bannersP;
}

public String getNameP() {
return nameP;
}

public void setNameP(String nameP) {
this.nameP = nameP;
}

public int getAmountP() {
return amountP;
}

public void setAmountP(int amountP) {
this.amountP = amountP;
}

public int getTotalPriceP() {
return totalPriceP;
}

public void setTotalPriceP(int totalPriceP) {
this.totalPriceP = totalPriceP;
}

public Payment getPaymentP() {
return paymentP;
}

public void setPaymentP(Payment paymentP) {
this.paymentP = paymentP;
}

public OrderStatus getStatusP() {
return statusP;
}

public void setStatusP(OrderStatus statusP) {
this.statusP = statusP;
}

public LocalDateTime getCreateAtP() {
return createAtP;
}

public void setCreateAtP(LocalDateTime createAtP) {
this.createAtP = createAtP;
}

@Override
public String toString() {
return "HistoryBuy{" + "userID=" + userID + ", bannersP=" + bannersP + ", nameP=" + nameP + ", amountP=" + amountP + ", totalPriceP=" + totalPriceP + ", paymentP=" + paymentP + ", statusP=" + statusP + ", createAtP=" + createAtP + '}';
}


}
3 changes: 3 additions & 0 deletions src/main/webapp/js/profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function activateTab(tab){
$('.nav-tabs a[href="#' + tab + '"]').tab('show');
};
Loading

0 comments on commit 55b7d8a

Please sign in to comment.