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

Commit

Permalink
Merge pull request #22 from bakaqc/dev
Browse files Browse the repository at this point in the history
Merge DEV
  • Loading branch information
bakaqc authored Dec 8, 2023
2 parents e380abf + 357ce3d commit 9ea9bd9
Show file tree
Hide file tree
Showing 149 changed files with 27,062 additions and 250 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: 'Build with Maven'

on: [push, pull_request]

jobs:
build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]

name: 'Build with Maven'
runs-on: ${{ matrix.os }}

steps:
- name: 'Checkout repository'
uses: actions/checkout@v4

- name: 'Set up JDK 8'
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
architecture: 'x64'

- name: 'Build project with Maven'
run: mvn verify
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Flower Shop
[![build](https://github.com/bakaqc/flower/actions/workflows/build.yml/badge.svg)](https://github.com/bakaqc/flower/actions/workflows/build.yml)
![GitHub top language](https://img.shields.io/github/languages/top/bakaqc/flower)
![GitHub repo size](https://img.shields.io/github/repo-size/bakaqc/flower)
![GitHub License](https://img.shields.io/github/license/bakaqc/flower)
Expand Down
449 changes: 449 additions & 0 deletions flower_shop.sql

Large diffs are not rendered by default.

32 changes: 2 additions & 30 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,48 +46,20 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<version>3.11.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<version>3.4.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/bakaqc/flower/controller/AboutController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.bakaqc.flower.controller;

import com.bakaqc.flower.dao.CategoriesDAO;
import com.bakaqc.flower.model.Categories;
import java.io.*;
import java.util.List;
import javax.servlet.*;
import javax.servlet.http.*;

public class AboutController extends HttpServlet {

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
List<Categories> listCAT = CategoriesDAO.getInstance().selectAll();

request.setAttribute("listCAT", listCAT);
request.getRequestDispatcher("/view/about.jsp").forward(request, response);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.bakaqc.flower.controller;

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.*;

@WebServlet(name = "AddToCartController", urlPatterns = {"/addcart"})
public class AddToCartController extends HttpServlet {

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");

int pid = Integer.parseInt(request.getParameter("id"));
int amount = Integer.parseInt(request.getParameter("amount"));

addItem(request, pid, amount);

response.sendRedirect("cart");
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}

public void addItem(HttpServletRequest request, int pid, int amount) {
HttpSession session = request.getSession();
Map<Integer, Integer> cart = (Map<Integer, Integer>) session.getAttribute("cart");

if (cart == null) {
return;
}

if (cart.containsKey(pid)) {
cart.put(pid, cart.get(pid) + amount);
} else {
cart.put(pid, amount);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.bakaqc.flower.controller;

import com.bakaqc.flower.dao.UserDAO;
import com.bakaqc.flower.model.User;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AdminAccountController extends HttpServlet {

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
String error = request.getParameter("error");
String status = request.getParameter("status");
if (error != null) {
request.setAttribute("error", error);
}
UserDAO userDAO = new UserDAO();
List<User> users = userDAO.selectAll();
if (status != null && !status.equals("0")) {
request.setAttribute("status", status);
String statusCode = status.equals("1") ? "activate" : "deactivate";
users = users.stream().filter((t) -> t.getStatus().toString().equals(statusCode)).collect(Collectors.toList());
}
request.setAttribute("users", users);
request.getSession().setAttribute("isActive", 1);
request.getRequestDispatcher("/view/AccountAdmin.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");

}

}
42 changes: 38 additions & 4 deletions src/main/java/com/bakaqc/flower/controller/AdminController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,50 @@
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.bakaqc.flower.dao.OrderDAO;
import com.bakaqc.flower.dao.ProductDAO;
import com.bakaqc.flower.dao.UserDAO;
import com.bakaqc.flower.model.Order;
import com.bakaqc.flower.model.User;
import java.util.*;

public class AdminController extends HttpServlet {

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
OrderDAO orderDAO = new OrderDAO();
List<Order> orders = orderDAO.selectAll();

List<Order> process = orderDAO.selectProcess();
List<Order> ship = orderDAO.selectShip();
List<Order> done = orderDAO.selectDone();
List<Order> cancel = orderDAO.selectCancel();

UserDAO userDAO = new UserDAO();
List<User> users = userDAO.selectAll();
ProductDAO productDAO = new ProductDAO();
int productNum = productDAO.selectAll().size();
request.setAttribute("numPro", productNum);
request.setAttribute("users", users);
request.setAttribute("orders", orders);
request.setAttribute("process", process);
request.setAttribute("ship", ship);
request.setAttribute("done", done);
request.setAttribute("cancel", cancel);
request.getSession().setAttribute("isActive", 0);

RequestDispatcher rd = request.getRequestDispatcher("/view/admin.jsp");
rd.forward(request, response);
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.bakaqc.flower.controller;

import com.bakaqc.flower.dao.AdminDAO;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AdminDeleteController extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
String id = request.getParameter("id");
AdminDAO adminDAO = new AdminDAO();
adminDAO.delete(id);
}
}

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.bakaqc.flower.controller;

import com.bakaqc.flower.dao.AdminDAO;
import com.bakaqc.flower.model.Admin;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AdminListController extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
AdminDAO adminDAO = new AdminDAO();
List<Admin> list = adminDAO.selectAll();
request.setAttribute("list", list);
request.getSession().setAttribute("isActive", 4);
request.getRequestDispatcher("/view/manageAdmin.jsp").forward(request, response);
}
}

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
}
}
Loading

0 comments on commit 9ea9bd9

Please sign in to comment.