This repository has been archived by the owner on Dec 31, 2023. It is now read-only.
-
-
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.
Merge pull request #87 from hardingadonis/hotfix_admin
Create admin page
- Loading branch information
Showing
37 changed files
with
3,875 additions
and
16 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
src/main/java/io/hardingadonis/miu/controller/admin/AddNewProduct.java
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,68 @@ | ||
package io.hardingadonis.miu.controller.admin; | ||
|
||
import io.hardingadonis.miu.model.Product; | ||
import io.hardingadonis.miu.services.Singleton; | ||
import java.io.*; | ||
import java.time.LocalDateTime; | ||
import java.util.Collections; | ||
import javax.servlet.*; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.*; | ||
|
||
@WebServlet(name = "AddNewProduct", urlPatterns = {"/admin/new-product"}) | ||
public class AddNewProduct extends HttpServlet { | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
request.setCharacterEncoding("UTF-8"); | ||
response.setContentType("text/html; charset=UTF-8"); | ||
|
||
request.getRequestDispatcher("/view/admin/add-new-product.jsp").forward(request, response); | ||
|
||
} | ||
|
||
@Override | ||
protected void doPost(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
request.setCharacterEncoding("UTF-8"); | ||
response.setContentType("text/html; charset=UTF-8"); | ||
|
||
String nameProduct = request.getParameter("productName"); | ||
|
||
String productBrand = request.getParameter("productBrand"); | ||
|
||
int Category_ID = Integer.parseInt(request.getParameter("productCategoryID")); | ||
|
||
String productOrigin = request.getParameter("productOrigin"); | ||
|
||
String productExpiry = request.getParameter("productExpiry"); | ||
|
||
String productWeight = request.getParameter("productWeight"); | ||
|
||
String productPreservation = request.getParameter("productPreservation"); | ||
|
||
long productPrice = Long.parseLong(request.getParameter("productPrice")); | ||
|
||
int productAmount = Integer.parseInt(request.getParameter("productAmount")); | ||
|
||
Product product = new Product(); | ||
|
||
product.setName(nameProduct); | ||
product.setBrand(productBrand); | ||
product.setCategoryID(Category_ID); | ||
|
||
product.setOrigin(productOrigin); | ||
product.setExpiryDate(productExpiry); | ||
product.setWeight(productWeight); | ||
product.setPreservation(productPreservation); | ||
product.setPrice(productPrice); | ||
product.setAmount(productAmount); | ||
product.setThumbnail(""); | ||
product.setImages(Collections.EMPTY_LIST); | ||
|
||
Singleton.productDAO.insert(product); | ||
response.sendRedirect(request.getContextPath()+ "/admin/product"); | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/io/hardingadonis/miu/controller/admin/CategoryAdmin.java
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,64 @@ | ||
package io.hardingadonis.miu.controller.admin; | ||
|
||
import io.hardingadonis.miu.model.*; | ||
import io.hardingadonis.miu.services.*; | ||
import java.io.*; | ||
import javax.servlet.*; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.*; | ||
import org.json.simple.*; | ||
|
||
@WebServlet(name = "CategoryAdmin", urlPatterns = {"/admin/category"}) | ||
public class CategoryAdmin extends HttpServlet { | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
request.setCharacterEncoding("UTF-8"); | ||
response.setContentType("text/html; charset=UTF-8"); | ||
|
||
HttpSession session = request.getSession(); | ||
|
||
Admin admin = (Admin) session.getAttribute("admin"); | ||
|
||
if (admin == null) { | ||
response.sendRedirect(request.getContextPath() + "/admin/login"); | ||
return; | ||
} | ||
request.getRequestDispatcher("/view/admin/category-admin.jsp").forward(request, response); | ||
} | ||
|
||
@Override | ||
protected void doPost(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
request.setCharacterEncoding("UTF-8"); | ||
response.setContentType("text/html; charset=UTF-8"); | ||
|
||
String name = request.getParameter("name"); | ||
|
||
try { | ||
int id = Integer.parseInt(request.getParameter("id")); | ||
|
||
Category category = Singleton.categoryDAO.get(id); | ||
|
||
if (category != null) { | ||
category.setName(name); | ||
|
||
Singleton.categoryDAO.update(category); | ||
} | ||
} catch (NumberFormatException ex) { | ||
Category category = new Category(name); | ||
|
||
Singleton.categoryDAO.insert(category); | ||
} | ||
|
||
JSONObject jsonResponse = new JSONObject(); | ||
jsonResponse.put("status", "success"); | ||
jsonResponse.put("message", "Order canceled successfully"); | ||
|
||
response.setContentType("application/json"); | ||
response.getWriter().write(jsonResponse.toString()); | ||
|
||
response.setStatus(HttpServletResponse.SC_OK); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/io/hardingadonis/miu/controller/admin/DashboardAdmin.java
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,34 @@ | ||
package io.hardingadonis.miu.controller.admin; | ||
|
||
import io.hardingadonis.miu.model.*; | ||
import java.io.*; | ||
import javax.servlet.*; | ||
import javax.servlet.annotation.*; | ||
import javax.servlet.http.*; | ||
|
||
@WebServlet(name = "DashboardAdmin", urlPatterns = {"/admin"}) | ||
public class DashboardAdmin extends HttpServlet { | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
request.setCharacterEncoding("UTF-8"); | ||
response.setContentType("text/html; charset=UTF-8"); | ||
|
||
HttpSession session = request.getSession(); | ||
|
||
Admin admin = (Admin) session.getAttribute("admin"); | ||
|
||
if (admin == null) { | ||
response.sendRedirect(request.getContextPath() + "/admin/login"); | ||
return; | ||
} | ||
|
||
request.getRequestDispatcher("/view/admin/dashboard-admin.jsp").forward(request, response); | ||
} | ||
|
||
@Override | ||
protected void doPost(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
} | ||
} |
7 changes: 3 additions & 4 deletions
7
src/main/java/io/hardingadonis/miu/controller/admin/LoginAdmin.java
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
25 changes: 25 additions & 0 deletions
25
src/main/java/io/hardingadonis/miu/controller/admin/LogoutAdmin.java
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,25 @@ | ||
package io.hardingadonis.miu.controller.admin; | ||
|
||
import java.io.*; | ||
import javax.servlet.*; | ||
import javax.servlet.annotation.*; | ||
import javax.servlet.http.*; | ||
|
||
@WebServlet(name = "LogoutAdmin", urlPatterns = {"/admin/logout"}) | ||
public class LogoutAdmin extends HttpServlet { | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
request.setCharacterEncoding("UTF-8"); | ||
response.setContentType("text/html; charset=UTF-8"); | ||
|
||
HttpSession session = request.getSession(false); | ||
|
||
if (session != null) { | ||
session.invalidate(); | ||
} | ||
|
||
response.sendRedirect(request.getContextPath() + "/admin"); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
src/main/java/io/hardingadonis/miu/controller/admin/OrderAdmin.java
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,67 @@ | ||
package io.hardingadonis.miu.controller.admin; | ||
|
||
import io.hardingadonis.miu.model.*; | ||
import io.hardingadonis.miu.model.detail.OrderStatus; | ||
import io.hardingadonis.miu.services.Singleton; | ||
import java.io.IOException; | ||
import javax.servlet.*; | ||
import javax.servlet.annotation.*; | ||
import javax.servlet.http.*; | ||
import org.json.simple.JSONObject; | ||
|
||
@WebServlet(name = "OrderAdmin", urlPatterns = {"/admin/order"}) | ||
public class OrderAdmin extends HttpServlet { | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
request.setCharacterEncoding("UTF-8"); | ||
response.setContentType("text/html; charset=UTF-8"); | ||
|
||
HttpSession session = request.getSession(); | ||
|
||
Admin admin = (Admin) session.getAttribute("admin"); | ||
|
||
if (admin == null) { | ||
response.sendRedirect(request.getContextPath() + "/admin/login"); | ||
return; | ||
} | ||
|
||
request.getRequestDispatcher("/view/admin/order-admin.jsp").forward(request, response); | ||
} | ||
|
||
@Override | ||
protected void doPost(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
request.setCharacterEncoding("UTF-8"); | ||
response.setContentType("text/html; charset=UTF-8"); | ||
|
||
OrderStatus orderStatus = OrderStatus.create(request.getParameter("status")); | ||
|
||
try { | ||
int id = Integer.parseInt(request.getParameter("id")); | ||
|
||
Order order = Singleton.orderDAO.get(id); | ||
|
||
if (order != null) { | ||
order.setStatus(orderStatus); | ||
|
||
Singleton.orderDAO.update(order); | ||
} | ||
} catch (NumberFormatException ex) { | ||
response.setStatus(HttpServletResponse.SC_BAD_REQUEST); | ||
|
||
return; | ||
} | ||
|
||
JSONObject jsonResponse = new JSONObject(); | ||
jsonResponse.put("status", "success"); | ||
jsonResponse.put("message", "Status updated successfully"); | ||
|
||
response.setContentType("application/json"); | ||
response.getWriter().write(jsonResponse.toString()); | ||
|
||
response.setStatus(HttpServletResponse.SC_OK); | ||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/io/hardingadonis/miu/controller/admin/ProductAdmin.java
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,59 @@ | ||
package io.hardingadonis.miu.controller.admin; | ||
|
||
import io.hardingadonis.miu.model.*; | ||
import io.hardingadonis.miu.services.*; | ||
import java.io.*; | ||
import javax.servlet.*; | ||
import javax.servlet.annotation.*; | ||
import javax.servlet.http.*; | ||
import org.json.simple.*; | ||
|
||
@WebServlet(name = "ProductAdmin", urlPatterns = {"/admin/product"}) | ||
public class ProductAdmin extends HttpServlet { | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
request.setCharacterEncoding("UTF-8"); | ||
response.setContentType("text/html; charset=UTF-8"); | ||
|
||
HttpSession session = request.getSession(); | ||
|
||
Admin admin = (Admin) session.getAttribute("admin"); | ||
|
||
if (admin == null) { | ||
response.sendRedirect(request.getContextPath() + "/admin/login"); | ||
return; | ||
} | ||
|
||
request.getRequestDispatcher("/view/admin/product-admin.jsp").forward(request, response); | ||
} | ||
|
||
@Override | ||
protected void doPost(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
// Handle form submission here | ||
} | ||
|
||
@Override | ||
protected void doDelete(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
try { | ||
int ID = Integer.parseInt(request.getParameter("id")); | ||
|
||
Singleton.productDAO.delete(ID); | ||
|
||
JSONObject jsonResponse = new JSONObject(); | ||
jsonResponse.put("status", "success"); | ||
jsonResponse.put("message", "User canceled successfully"); | ||
|
||
response.setContentType("application/json"); | ||
response.getWriter().write(jsonResponse.toString()); | ||
|
||
response.setStatus(HttpServletResponse.SC_OK); | ||
|
||
} catch (NumberFormatException ex) { | ||
System.err.println(ex.getMessage()); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/io/hardingadonis/miu/controller/admin/UserAdmin.java
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,53 @@ | ||
package io.hardingadonis.miu.controller.admin; | ||
|
||
import io.hardingadonis.miu.model.*; | ||
import io.hardingadonis.miu.services.*; | ||
import java.io.*; | ||
import javax.servlet.*; | ||
import javax.servlet.annotation.*; | ||
import javax.servlet.http.*; | ||
import org.json.simple.*; | ||
|
||
@WebServlet(name = "UserAdmin", urlPatterns = {"/admin/user"}) | ||
public class UserAdmin extends HttpServlet { | ||
|
||
@Override | ||
protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
request.setCharacterEncoding("UTF-8"); | ||
response.setContentType("text/html; charset=UTF-8"); | ||
|
||
HttpSession session = request.getSession(); | ||
|
||
Admin admin = (Admin) session.getAttribute("admin"); | ||
|
||
if (admin == null) { | ||
response.sendRedirect(request.getContextPath() + "/admin/login"); | ||
return; | ||
} | ||
|
||
request.getRequestDispatcher("/view/admin/user-admin.jsp").forward(request, response); | ||
} | ||
|
||
@Override | ||
protected void doDelete(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
try { | ||
int ID = Integer.parseInt(request.getParameter("id")); | ||
|
||
Singleton.userDAO.delete(ID); | ||
|
||
JSONObject jsonResponse = new JSONObject(); | ||
jsonResponse.put("status", "success"); | ||
jsonResponse.put("message", "User canceled successfully"); | ||
|
||
response.setContentType("application/json"); | ||
response.getWriter().write(jsonResponse.toString()); | ||
|
||
response.setStatus(HttpServletResponse.SC_OK); | ||
|
||
} catch (NumberFormatException ex) { | ||
System.err.println(ex.getMessage()); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.