Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #25

Merged
merged 88 commits into from
Dec 6, 2023
Merged
Changes from 1 commit
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
17c2e5a
add model - User.java file
nguyenkhanhquy Nov 11, 2023
1950adf
add model - Role.java file
nguyenkhanhquy Nov 11, 2023
011969a
add models
Bisoo12300 Nov 11, 2023
32fbad0
add models
NguyenDink Nov 11, 2023
4819e9d
add model - Cart.java file
nguyenkhanhquy Nov 11, 2023
a8e48f4
add entity
nguyenkhanhquy Nov 11, 2023
fa10ad6
update entities
nguyenkhanhquy Nov 16, 2023
42dfb80
edit entities
nguyenkhanhquy Nov 16, 2023
ae813fb
edit entities, add entityDB
nguyenkhanhquy Nov 16, 2023
8d6a640
add register
NguyenDink Nov 16, 2023
8e4a01e
add folders
nguyenkhanhquy Nov 17, 2023
28f2352
change package data -> dao
nguyenkhanhquy Nov 17, 2023
2b38c9a
add view
nguyenkhanhquy Nov 17, 2023
8356802
Merge pull request #1 from nguyenkhanhquy/feature/Login
nguyenkhanhquy Nov 17, 2023
dae4b92
fix view register
nguyenkhanhquy Nov 17, 2023
2775a5c
add dao
NguyenDink Nov 17, 2023
a7a820d
add dao
nguyenkhanhquy Nov 17, 2023
df07deb
add dao - LineItemDB.java file
Bisoo12300 Nov 17, 2023
d227dcc
fix input radio - registerView.jsp file
nguyenkhanhquy Nov 17, 2023
c4d0985
Merge pull request #2 from nguyenkhanhquy/develop
nguyenkhanhquy Nov 17, 2023
bde0ca1
edit model - User.java file
nguyenkhanhquy Nov 17, 2023
85b4ff8
edit registerView.jsp file
nguyenkhanhquy Nov 18, 2023
0fdf3e2
Merge pull request #3 from nguyenkhanhquy/feature/Register
nguyenkhanhquy Nov 18, 2023
a1982d9
Merge pull request #4 from nguyenkhanhquy/develop
nguyenkhanhquy Nov 18, 2023
95b14ec
add feature - login
nguyenkhanhquy Nov 18, 2023
01717da
update entities
nguyenkhanhquy Nov 18, 2023
0969d6d
update home page
nguyenkhanhquy Nov 18, 2023
02c78cf
add PasswordEncryptorUtil
nguyenkhanhquy Nov 18, 2023
2d60bbf
Merge pull request #5 from nguyenkhanhquy/feature/Login
nguyenkhanhquy Nov 18, 2023
b2c41c5
add show category
NguyenDink Nov 18, 2023
43c93a1
add show product
nguyenkhanhquy Nov 18, 2023
fff0545
Merge pull request #6 from nguyenkhanhquy/feature/ShowProduct
nguyenkhanhquy Nov 18, 2023
3256d22
add filter - EncodingFilter.java file
nguyenkhanhquy Nov 18, 2023
d79326d
add filter - CookieFilter.java file
nguyenkhanhquy Nov 18, 2023
ba8c6b6
add feature update password
nguyenkhanhquy Nov 18, 2023
ea6b815
add feature update user info
nguyenkhanhquy Nov 19, 2023
44d3747
add includes folder - layout web
nguyenkhanhquy Nov 19, 2023
8b9c6c3
Merge pull request #7 from nguyenkhanhquy/feature/AccountSettings
nguyenkhanhquy Nov 19, 2023
140f285
fix updatePasswordView.jsp file
nguyenkhanhquy Nov 19, 2023
8d9550a
fix successView.jsp file
nguyenkhanhquy Nov 19, 2023
3dd8b29
add LoadMoreController.java file
NguyenDink Nov 19, 2023
d75720d
update LoadMoreController.java file
nguyenkhanhquy Nov 19, 2023
5de344b
add logo vs product image
Bisoo12300 Nov 19, 2023
9246378
logo again
Bisoo12300 Nov 19, 2023
9f7cabe
add logo
Bisoo12300 Nov 19, 2023
f7e4715
fix EncodingFilter.java file
nguyenkhanhquy Nov 20, 2023
3e56855
update image data
nguyenkhanhquy Nov 20, 2023
63339fa
edit register.css file
nguyenkhanhquy Nov 20, 2023
6d01308
remove dependency
nguyenkhanhquy Nov 20, 2023
92fe8cc
Merge pull request #9 from nguyenkhanhquy/feature/LoadProduct
nguyenkhanhquy Nov 20, 2023
04a0a7f
add CategoryController.java file
NguyenDink Nov 20, 2023
9b9a2fb
edit controllers
nguyenkhanhquy Nov 21, 2023
cda7bcf
add "all categories" option
nguyenkhanhquy Nov 21, 2023
c5278fc
add show role name
nguyenkhanhquy Nov 21, 2023
bb4ee9e
update model - Product.java file
nguyenkhanhquy Nov 21, 2023
43c0404
Merge pull request #10 from nguyenkhanhquy/feature/Category
nguyenkhanhquy Nov 21, 2023
4e08f60
add send email
nguyenkhanhquy Nov 21, 2023
fb3d844
Merge pull request #11 from nguyenkhanhquy/feature/SendMail
nguyenkhanhquy Nov 21, 2023
567dfb5
fix LoadMore Category
NguyenDink Nov 21, 2023
cf0b31e
a
Bisoo12300 Nov 23, 2023
b755db5
fix search product
NguyenDink Nov 23, 2023
52d44e5
Merge pull request #12 from nguyenkhanhquy/feature/Category
nguyenkhanhquy Nov 23, 2023
c4c1cec
edit dao - ProductDB.java file
NguyenDink Nov 23, 2023
ca2051f
Merge pull request #13 from nguyenkhanhquy/feature/SearchProduct
nguyenkhanhquy Nov 23, 2023
0f2e714
add feature - manager product
nguyenkhanhquy Nov 23, 2023
ea4d8bd
add feature - add product
nguyenkhanhquy Nov 24, 2023
4eb27b4
add feature - pagination
nguyenkhanhquy Nov 25, 2023
3e14ee4
add feature - show detail product
NguyenDink Nov 25, 2023
ea6aff0
add feature - CRUD product
nguyenkhanhquy Nov 25, 2023
f575f1d
Merge branch 'develop' into feature/LoadMore
nguyenkhanhquy Nov 25, 2023
33fc90b
Merge pull request #15 from nguyenkhanhquy/feature/LoadMore
nguyenkhanhquy Nov 25, 2023
79780b2
add view - cartView.jsp file
nguyenkhanhquy Nov 25, 2023
2ace529
code optimization
nguyenkhanhquy Nov 26, 2023
d269391
feature bug fix - update user info
nguyenkhanhquy Nov 26, 2023
a554729
add feature - CRUD user
nguyenkhanhquy Nov 26, 2023
4f52225
Merge pull request #17 from nguyenkhanhquy/feature/UserManagement
nguyenkhanhquy Nov 26, 2023
a117f3f
add CRUD of Category in Admin
Bisoo12300 Nov 26, 2023
3063469
fix bug - CRUD category
nguyenkhanhquy Nov 27, 2023
02e3566
Merge pull request #18 from nguyenkhanhquy/feature/CategoryManagement
nguyenkhanhquy Nov 27, 2023
b9b9b56
add controller - CartController.java file
nguyenkhanhquy Nov 28, 2023
1fcc92c
update feature cart
nguyenkhanhquy Nov 30, 2023
ef39298
add feature - view order
nguyenkhanhquy Dec 1, 2023
3561dc8
add feature - view detail order
nguyenkhanhquy Dec 2, 2023
4e7fd46
update feature - view detail order
nguyenkhanhquy Dec 2, 2023
0703410
add error page
nguyenkhanhquy Dec 5, 2023
c814154
edit LoadMoreController
NguyenDink Dec 5, 2023
89bc7d3
fix feature - load more
nguyenkhanhquy Dec 6, 2023
8dfe073
add feature - OTP
nguyenkhanhquy Dec 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add feature - CRUD product
nguyenkhanhquy committed Nov 25, 2023
commit ea6aff0897f07d936b512452a9a5de57cf02fd86
Original file line number Diff line number Diff line change
@@ -51,9 +51,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
String description = req.getParameter("description");
String size = req.getParameter("size");
String categoryIdString = req.getParameter("category");

int categoryId = Integer.parseInt(categoryIdString);

Category category = CategoryDB.selectCategoryById(categoryId);

List<Product> listP = ProductDB.selectProductByIdDesc();
@@ -77,7 +75,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)

S3Util.uploadFile(fileName, part.getInputStream());

String url = "https://" + S3Util.AWS_BUCKET + ".s3.amazonaws.com/" + fileName;
String urlImage = "https://" + S3Util.AWS_BUCKET + ".s3.amazonaws.com/" + fileName;

Product product = new Product();
product.setName(name);
@@ -86,10 +84,13 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp)
product.setDescription(description);
product.setSize(size);
product.setCategory(category);
product.setImage(url);
product.setImage(urlImage);

ProductDB.insert(product);

String message = "Thêm thành công sản phẩm có mã: " + idP;
req.setAttribute("message", message);

doGet(req, resp);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package com.jacobin.controllers.admin;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

import com.jacobin.dao.CategoryDB;
import com.jacobin.dao.ProductDB;
import com.jacobin.models.Category;
import com.jacobin.models.Product;
import com.jacobin.utils.S3Util;

@WebServlet(urlPatterns = { "/admin/edit-product" })
@MultipartConfig(
fileSizeThreshold = 1024 * 1024, // 1MB
maxFileSize = 1024 * 1024 * 10, // 10MB
maxRequestSize = 1024 * 1024 * 11 // 11MB
)
public class EditProductController extends HttpServlet {

private static final long serialVersionUID = 1L;

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

List<Category> listC = CategoryDB.selectAllCategory();
req.setAttribute("ListC", listC);

String editIdString = req.getParameter("editId");
if (editIdString == null) {
editIdString = (String) req.getAttribute("editId");
}

int editId = Integer.parseInt(editIdString);
Product product = ProductDB.selectProductById(editId);
req.setAttribute("product", product);

RequestDispatcher dispatcher = this.getServletContext()
.getRequestDispatcher("/WEB-INF/views/admin/editProductView.jsp");

dispatcher.forward(req, resp);
}

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {

String idString = req.getParameter("id");
int id = Integer.parseInt(idString);
String name = req.getParameter("name");
String price = req.getParameter("price");
String title = req.getParameter("title");
String description = req.getParameter("description");
String size = req.getParameter("size");
String categoryIdString = req.getParameter("category");
int categoryId = Integer.parseInt(categoryIdString);
Category category = CategoryDB.selectCategoryById(categoryId);


String urlImage = req.getParameter("imageOld");

Part part = req.getPart("file");

if (part != null && part.getSize() > 0) {
String originalFileName = S3Util.getFileName(part);

String newFileName = idString + originalFileName.substring(originalFileName.lastIndexOf('.'));

String fileName = S3Util.AWS_URL_FOLDER + newFileName;

S3Util.uploadFile(fileName, part.getInputStream());

urlImage = "https://" + S3Util.AWS_BUCKET + ".s3.amazonaws.com/" + fileName;
}

Product product = new Product();
product.setProductId(id);
product.setName(name); product.setPrice(Double.parseDouble(price));
product.setTitle(title); product.setDescription(description);
product.setSize(size); product.setCategory(category);
product.setImage(urlImage);

ProductDB.update(product);

String message = "Chỉnh sửa thành công sản phẩm có mã: " + idString;
req.setAttribute("message", message);
req.setAttribute("editId", idString);

doGet(req, resp);
}
}
Original file line number Diff line number Diff line change
@@ -3,20 +3,17 @@
import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.jacobin.dao.CategoryDB;
import com.jacobin.dao.ProductDB;
import com.jacobin.models.Category;
import com.jacobin.models.Product;
import com.jacobin.models.User;
import com.jacobin.utils.SessionUtil;
import com.jacobin.utils.S3Util;

@WebServlet(urlPatterns = {"/admin/manager-product"})
public class ManagerProductController extends HttpServlet {
@@ -27,39 +24,60 @@ public class ManagerProductController extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {

String message = "";

String deleteIdString = req.getParameter("deleteId");
if (deleteIdString != null) {
int deleteId = Integer.parseInt(deleteIdString);
Product product = ProductDB.selectProductById(deleteId);
if (product != null) {
String urlImage = product.getImage();
int index = urlImage.indexOf(S3Util.AWS_URL_FOLDER);
if (index != -1) {
urlImage = urlImage.substring(index);
S3Util.deleteFile(urlImage);
}

ProductDB.delete(product);
message = "Xoá thành công sản phẩm có mã: " + deleteId;
}
}

int count = ProductDB.getTotalProduct();
int endPage = count/4;
int endPage = count/4;
if (count % 4 != 0) {
endPage ++;
}
req.setAttribute("endP", endPage);

int index;
String indexPage = req.getParameter("index");
try {
index = Integer.parseInt(indexPage);
if (count != 0) {
int index;
String indexPage = req.getParameter("index");
try {
index = Integer.parseInt(indexPage);
}
catch (NumberFormatException nfe) {
index = 1;
}

if (index <= 0) {
index = 1;
} else if (index > endPage) {
index = endPage;
}
req.setAttribute("tag", index);

List<Category> listC = CategoryDB.selectAllCategory();
req.setAttribute("ListC", listC);
List<Product> listP = ProductDB.pagingProduct(index);
req.setAttribute("ListP", listP);
}
catch (NumberFormatException nfe) {
index = 1;
}

if (index <= 0) {
index = 1;
} else if (index > endPage) {
index = endPage;
}
req.setAttribute("tag", index);

List<Category> listC = CategoryDB.selectAllCategory();
req.setAttribute("ListC", listC);
List<Product> listP = ProductDB.pagingProduct(index);
req.setAttribute("ListP", listP);

// List<Product> list = ProductDB.pagingProduct(1);
// for (Product o: list ) {
// System.out.println(o);
// }

req.setAttribute("message", message);
String url = "/WEB-INF/views/admin/managerProductView.jsp";
req.getRequestDispatcher(url).forward(req, resp);
}
4 changes: 2 additions & 2 deletions src/main/java/com/jacobin/dao/ProductDB.java
Original file line number Diff line number Diff line change
@@ -59,9 +59,9 @@ public static void delete(Product product) {
public static Product selectProductById(int productId) {
EntityManager em = DBUtil.getEmFactory().createEntityManager();
String qString = "SELECT p FROM Product p " +
"WHERE p.productID = :productID";
"WHERE p.productId = :productId";
TypedQuery<Product> q = em.createQuery(qString, Product.class);
q.setParameter("productID", productId);
q.setParameter("productId", productId);
try {
Product product = q.getSingleResult();
return product;
4 changes: 2 additions & 2 deletions src/main/webapp/WEB-INF/views/admin/addProductView.jsp
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@
</div>
</div>
</div>

<strong class="text-success">${message}</strong>
<form action="add-product" method="post" enctype="multipart/form-data">

<div class="row">
@@ -85,7 +85,7 @@

<div class="form-group mb-4" align="center">
<label id="file-input-label" for="file-input">
<img id="image-preview" src="https://upload.wikimedia.org/wikipedia/commons/6/65/No-Image-Placeholder.svg" alt="Ảnh hiển thị">
<img id="image-preview" src="https://upload.wikimedia.org/wikipedia/commons/6/65/No-Image-Placeholder.svg" alt="Ảnh sản phẩm">
<br><span class="btn btn-secondary mt-4">Thêm ảnh</span>
<input type="file" id="file-input" name="file" accept="image/*" style="display:none;" required>
</label>
124 changes: 124 additions & 0 deletions src/main/webapp/WEB-INF/views/admin/editProductView.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html lang="vi">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Chỉnh sửa sản phẩm</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto|Varela+Round">

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">

<link href="../resources/css/managerProduct.css" rel="stylesheet" type="text/css" />

<style>
#image-preview {
max-width: 100%;
max-height: 300px;
border: 1px solid #ddd;
}

#file-input-label {
cursor: pointer;
}
</style>
</head>

<body>
<div class="container">
<div class="table-wrapper">
<div class="table-title">
<div class="row">
<div class="col-sm-6">
<h2>Chỉnh sửa <b>Sản Phẩm</b></h2>
</div>
<div class="col-sm-6">
<a href="manager-product"><button type="button" class="btn btn-primary">Về trang quản lý sản phẩm</button></a>
</div>
</div>
</div>
<strong class="text-success">${message}</strong>
<form action="edit-product" method="post" enctype="multipart/form-data">

<div class="row">
<div class="col-sm-6">
<div class="form-group mb-4">
<label>Mã:</label>
<input name="id" type="text" class="form-control" value="${product.productId}" readonly>
</div>

<div class="form-group mb-4">
<label>Tên:</label>
<input name="name" type="text" class="form-control" value="${product.name}" required>
</div>

<div class="form-group mb-4">
<label>Size:</label>
<input name="size" type="text" class="form-control" value="${product.size}" required>
</div>

<div class="form-group mb-4">
<label>Giá:</label>
<input name="price" type="text" class="form-control" value="${product.price}" required>
</div>

<div class="form-group mb-4">
<label>Tiêu đề:</label>
<textarea name="title" class="form-control" required>${product.title}</textarea>
</div>

<div class="form-group mb-4">
<label>Mô tả:</label>
<textarea name="description" class="form-control" required>${product.description}</textarea>
</div>
</div>

<div class="col-sm-6">
<div class="form-group mb-4">
<label>Danh mục:</label>
<select name="category" class="form-select" required>
<c:forEach items="${ListC}" var="c">
<c:if test="${product.getCategory().getCategoryId() == c.categoryId}">
<option value="${c.categoryId}" selected>${c.name}</option>
</c:if>
<c:if test="${product.getCategory().getCategoryId() != c.categoryId}">
<option value="${c.categoryId}">${c.name}</option>
</c:if>
</c:forEach>
</select>
</div>

<div class="form-group mb-4" align="center">
<input type="hidden" name="imageOld" value="${product.image}">
<label id="file-input-label" for="file-input">
<img id="image-preview" src="${product.image}" alt="Ảnh sản phẩm">
<br><span class="btn btn-secondary mt-4">Thêm ảnh</span>
<input type="file" id="file-input" name="file" accept="image/*" style="display:none;">
</label>
</div>
<hr/>
<button class="w-100 btn btn-lg btn-success mb-2" type="submit">Xác nhận</button>
</div>
</div>
</form>
</div>
</div>

<script>
document.getElementById('file-input').addEventListener('change', function(event) {
const file = event.target.files[0];
if (file) {
const imageUrl = URL.createObjectURL(file);
document.getElementById('image-preview').src = imageUrl;
}
});
</script>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
</body>

</html>
Loading