-
© 2023 Perishable Shop. All rights reserved
-
-
-
-
-
-
\ No newline at end of file
diff --git a/JtProject/src/main/webapp/views/products.jsp b/JtProject/src/main/webapp/views/products.jsp
deleted file mode 100644
index 76253005..00000000
--- a/JtProject/src/main/webapp/views/products.jsp
+++ /dev/null
@@ -1,135 +0,0 @@
-<%@page import="java.sql.*"%>
-<%@page import="java.util.*"%>
-<%@page import="java.text.*"%>
-<%@page import ="java.io.FileOutputStream" %>
-<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
-
-<%@page import=" java.io.ObjectOutputStream" %>
-
-
-
-
-
-
-
-
-
Document
-
-
-
-
-
-
Add Product
-
-
-
- | Serial No. |
- Product Name |
- Category |
- Preview |
- Quantity |
- Price |
- Weight |
- Descrption |
- Delete |
- Update |
-
-
-
-
-
-
-
-
- |
- ${product.id}
- |
-
- ${product.name }
- |
-
- ${product.category.name}
-
- |
-
-  |
-
- ${product.quantity }
- |
- S
- ${product.price }
- |
-
- ${product.weight }
- |
-
- ${product.description }
- |
-
-
-
- |
-
-
-
- |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/JtProject/src/main/webapp/views/productsAdd.jsp b/JtProject/src/main/webapp/views/productsAdd.jsp
deleted file mode 100644
index f8293510..00000000
--- a/JtProject/src/main/webapp/views/productsAdd.jsp
+++ /dev/null
@@ -1,138 +0,0 @@
-<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
-
-
-
-<%@page import="java.sql.*"%>
-
-
-
-
-
-
-
-
Document
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/JtProject/src/main/webapp/views/productsUpdate.jsp b/JtProject/src/main/webapp/views/productsUpdate.jsp
deleted file mode 100644
index a0750b2d..00000000
--- a/JtProject/src/main/webapp/views/productsUpdate.jsp
+++ /dev/null
@@ -1,129 +0,0 @@
-<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
-
-
-<%@page import="java.sql.*"%>
-
-
-
-
-
-
-
-
Document
-
-
-
-
-
Update Existing Product
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/JtProject/src/main/webapp/views/register.jsp b/JtProject/src/main/webapp/views/register.jsp
deleted file mode 100644
index 2dc7244e..00000000
--- a/JtProject/src/main/webapp/views/register.jsp
+++ /dev/null
@@ -1,55 +0,0 @@
-
-
-
-
-
-
-
-
-
Document
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/JtProject/src/main/webapp/views/updateProfile.jsp b/JtProject/src/main/webapp/views/updateProfile.jsp
deleted file mode 100644
index db5747fa..00000000
--- a/JtProject/src/main/webapp/views/updateProfile.jsp
+++ /dev/null
@@ -1,55 +0,0 @@
-3
-
-
-
-
-
-
-
-
Document
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/JtProject/src/main/webapp/views/uproduct.jsp b/JtProject/src/main/webapp/views/uproduct.jsp
deleted file mode 100644
index f00ff084..00000000
--- a/JtProject/src/main/webapp/views/uproduct.jsp
+++ /dev/null
@@ -1,130 +0,0 @@
-<%@page import="java.sql.*"%>
-<%@page import="java.util.*"%>
-<%@page import="java.text.*"%>
-<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
-
-
-
-
-
-
-
-
-
-
Document
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/JtProject/src/main/webapp/views/userLogin.jsp b/JtProject/src/main/webapp/views/userLogin.jsp
deleted file mode 100644
index d55497e4..00000000
--- a/JtProject/src/main/webapp/views/userLogin.jsp
+++ /dev/null
@@ -1,79 +0,0 @@
-
-
-
-
-
-
-
-
-
User Login
-
-
-
-
-
-
-
User Login
-
-
-
-
-
-
-
-
-
diff --git a/README.md b/README.md
index 44c5fe36..f74b1b68 100644
--- a/README.md
+++ b/README.md
@@ -1,113 +1,177 @@

-## New Version ( what's new)
-- Hibernate configuration added( database and tables automatically create when run the project)
-- Service classes provide reusable services throughout project
-- dao classes interact with database
-- bug fixed ( product image, security , etc..)
-- support in both eclipse & intellij ide
-- overall redesign entire code that help reusability.
-- disclaimer: currently working on this branch so there may be some bug related to endpoint, and working on cart logic.
-
-## Quickstart
-
-1. Clone the repository
-2. Open the project in your IDE: IntelliJ IDEA (recommended) or Eclipse
- * If you are using IntelliJ IDEA, make sure the IDE opens project as **Maven** and recognizes the project as a Spring Boot project. Also, you must change the working directory of the project so that the views (the actual web pages to be shown) are found by Spring Boot (check out [Web Directories IntelliJ IDEA](#web-directories).
-3. Make sure you are in the `JtProject` directory
-4. Configure the database connection in `application.properties` file (check the [Database](#database) section below for more info)
-5. Run the project (by running the `main` method in `JtSpringProjectApplication.java`)
-6. Open http://localhost:8080/ in your browser!
- * If you ran the [`basedata.sql`](https://github.com/jaygajera17/E-commerce-project-springBoot/blob/master2/JtProject/basedata.sql)script on the database, you can log in with the following credentials as admin; otherwise you'll have to manually create an admin user in the database:
- * Username: `admin`
- * Password: `123`
- * Log in as a normal user:
- * Username: `lisa`
- * Password: `765`
-
-### Database
-
-MySQL or MariaDB can be used as the database for this project. The database connection can be configured in the `src/main/resources/application.properties` file, with the appropriate values for the following properties:
-
-**( You'd better use another username not root, and ensure that the user has the corresponding permissions for the database. )**
+# E-commerce Spring Boot Project
+
+Modernized Spring Boot + JSP e-commerce app with Spring Security, JPA, Flyway, Dockerized MySQL, and Maven wrapper support.
+
+## Quick Navigation
+
+- [What Changed Recently](#what-changed-recently)
+- [Prerequisites](#prerequisites)
+- [Project Setup](#project-setup)
+- [Run the Application](#run-the-application)
+- [Run Tests](#run-tests)
+- [Database Configuration](#database-configuration)
+- [Troubleshooting](#troubleshooting)
+- [Workflow and Architecture](#workflow-and-architecture)
+- [Useful Links](#useful-links)
+
+## What Changed Recently
+
+- Project structure moved from `JtProject/` to repository root.
+- Added Docker support with `Dockerfile` and `docker-compose.yml`.
+- Added Maven wrapper metadata in `.mvn/wrapper/`.
+- Updated Java target in `pom.xml` to Java 17.
+- Made datasource settings environment-overridable:
+ - `SPRING_DATASOURCE_URL`
+ - `SPRING_DATASOURCE_USERNAME`
+ - `SPRING_DATASOURCE_PASSWORD`
+- Aligned local defaults with Docker MySQL mapping (`localhost:3308`).
+- Added H2-based test config in `src/test/resources/application.properties`.
+- Added test dependency `com.h2database:h2` in `pom.xml`.
+- Ignored local DB runtime files via `Db_volumes/` in `.gitignore`.
+
+## Prerequisites
+
+- Java 17
+- Docker Desktop (for containerized MySQL)
+- Git
+- IntelliJ IDEA or Eclipse
+
+## Project Setup
+
+### 1) Clone and Open
+
+```powershell
+git clone
+Set-Location "E-commerce-project-springBoot-pr-work"
+```
+
+Open the repository root as a Maven project.
+
+### 2) Set Java in Current PowerShell Session
+
+```powershell
+$env:JAVA_HOME="C:\Path\To\Your\JDK17"
+$env:Path="$env:JAVA_HOME\bin;$env:Path"
+java -version
+```
+
+### 3) Start MySQL Container
+
+```powershell
+docker compose up -d ecom-mysql-db
+```
+
+## Run the Application
+
+```powershell
+Set-Location "E-commerce-project-springBoot-pr-work"
+./mvnw.cmd spring-boot:run
+```
+
+Open these endpoints in your browser:
+
+- `http://localhost:8080/`
+- `http://localhost:8080/register`
+- `http://localhost:8080/admin/products`
+
+## Run Tests
+
+```powershell
+./mvnw.cmd test
+```
+
+Tests use H2 in-memory DB from `src/test/resources/application.properties`, so local MySQL is not required for test execution.
+
+## Database Configuration
+
+Runtime file: `src/main/resources/application.properties`
```properties
- db.url=jdbc:mysql://[ip address of db]:[port of db]/ecommjava?createDatabaseIfNotExist=true
- db.username=[username]
- db.password=[password, if any]
+spring.datasource.url=${SPRING_DATASOURCE_URL:jdbc:mysql://localhost:3308/db?createDatabaseIfNotExist=true&allowPublicKeyRetrieval=true&useSSL=false}
+spring.datasource.username=${SPRING_DATASOURCE_USERNAME:user}
+spring.datasource.password=${SPRING_DATASOURCE_PASSWORD:password}
```
-if you met the error `java.lang.IllegalArgumentException: Could not resolve placeholder 'db.driver' in value "${db.driver}"`, maybe you should change your `mysql-connector-java` version in `pom.xml` file according to your mysql version, don't forget to reload your Maven project.
+If you use local (non-Docker) MySQL, set values before running:
-Having done that, you must create some base data in the database. You can do that by running the `basedata.sql` script on the database. Check out Google for how to do that, because it depends on what tool you are using to access said database.
+```powershell
+$env:SPRING_DATASOURCE_URL="jdbc:mysql://localhost:3306/db?createDatabaseIfNotExist=true&allowPublicKeyRetrieval=true&useSSL=false"
+$env:SPRING_DATASOURCE_USERNAME="root"
+$env:SPRING_DATASOURCE_PASSWORD="root"
+```
+
+## Seed Data
-### Web Directories
+- Base SQL file: `basedata.sql`
+- Flyway migrations: `src/main/resources/db/migration/`
-The views are located in `src/main/webapp/views`, but for some reason, Spring Boot doesn't recognize that directory. To remedy this, you must change the working directory of the project in your IDE. If you're using IntelliJ IDEA, follow these steps:
+## Troubleshooting
-1. Click on the "Edit Configurations..." button in the top right corner of the IDE
-2. Click on the `JtSpringProjectApplication` configuration
-3. Change the "Working directory" option (if not present, click on "Modify Options" and select from the list) to the `$MODULE_WORKING_DIR$` macro
-4. Click "Apply" and "OK"
+- `JAVA_HOME not found`: set `JAVA_HOME` to a JDK (not JRE), then restart terminal.
+- `release version 21 not supported`: run with Java 17.
+- `Communications link failure`: ensure MySQL is up and port matches datasource URL (`3308` in current compose).
+- JSP not loading in IDE: run from repository root so `src/main/webapp/WEB-INF/views` resolves correctly.
+## Workflow and Architecture
-When you run the project, the views should be found by Spring Boot and you should see a login page in http://localhost:8080/ (if not logged in previously)!
-
+
-# Workflow
-- 
### Controller
-- control the endpoint and also send data to view( we use ModelAndView method)
-- ``` @GetMapping("login")
- public String adminlogin() {
-
- return "adminlogin";
- }```
-- whenever /login url is hit , src->main->webapp-> adminlogin.jsp file execute
+
+- Handles endpoints and passes model data to JSP views (`ModelAndView`).
+
+```java
+@GetMapping("login")
+public String adminlogin() {
+ return "adminlogin";
+}
+```
+
+- When `/login` is accessed, `src/main/webapp/views/adminlogin.jsp` is rendered.
+
### Models
-- represent data as entity and relationship among them.
+
+- Represent entities and their relationships.
### View
-- receive data from controller and show with frontend.
-## Endpoints
-- http://localhost:8080/
-- http://localhost:8080/register
-- http://localhost:8080/admin/products
-- http://localhost:8080/admin/customers
-- http://localhost:8080/admin/categories
-- http://localhost:8080/admin/Dashboard
+- Renders UI with data received from controllers.
+## Common Endpoints
-## Spring Boot
+- `http://localhost:8080/`
+- `http://localhost:8080/register`
+- `http://localhost:8080/admin/products`
+- `http://localhost:8080/admin/customers`
+- `http://localhost:8080/admin/categories`
+- `http://localhost:8080/admin/Dashboard`
-For any information about Spring Boot, here are some useful links!
+## Useful Links
-### Reference Documentation
-For further reference, please consider the following sections:
+### Spring Boot References
-* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html)
-* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.6.4/maven-plugin/reference/html/)
-* [Create an OCI image](https://docs.spring.io/spring-boot/docs/2.6.4/maven-plugin/reference/html/#build-image)
-* [Spring Web](https://docs.spring.io/spring-boot/docs/2.6.4/reference/htmlsingle/#boot-features-developing-web-applications)
+- [Official Apache Maven Documentation](https://maven.apache.org/guides/index.html)
+- [Spring Boot Maven Plugin Reference](https://docs.spring.io/spring-boot/docs/2.6.4/maven-plugin/reference/html/)
+- [Create an OCI Image](https://docs.spring.io/spring-boot/docs/2.6.4/maven-plugin/reference/html/#build-image)
+- [Spring Web Reference](https://docs.spring.io/spring-boot/docs/2.6.4/reference/htmlsingle/#boot-features-developing-web-applications)
### Guides
-The following guides illustrate how to use some features concretely:
-* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/)
-* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/)
-* [Building REST services with Spring](https://spring.io/guides/tutorials/bookmarks/)
+- [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/)
+- [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/)
+- [Building REST Services with Spring](https://spring.io/guides/tutorials/bookmarks/)
-## Preview
-
-
-
-
+### Project Demo
+- [YouTube project walkthrough (legacy version)](https://youtu.be/c6WWdINWSlI) [![youtube][youtube-shield]][youtube-url]
-## Link
+## Preview
-- 𝗬𝗼𝘂𝘁𝘂𝗯𝗲 𝗽𝗿𝗼𝗷𝗲𝗰𝘁 𝘃𝗶𝗱𝗲𝗼 𝗪𝗼𝗿𝗸𝗶𝗻𝗴 𝗗𝗲𝗺𝗼 + 𝘀𝘁𝗲𝗽 𝗯𝘆 𝘀𝘁𝗲𝗽 𝗲𝘅𝗲𝗰𝘂𝘁𝗶𝗼𝗻 𝗹𝗶𝗻𝗸 ( old version )::--- [ click here ](https://youtu.be/c6WWdINWSlI) [![youtube][youtube-shield]][youtube-url]
+
+
+
-[youtube-shield]:https://img.shields.io/youtube/views/c6WWdINWSlI?style=social
-[youtube-url]: https://youtu.be/c6WWdINWSlI
+[youtube-shield]: https://img.shields.io/youtube/views/c6WWdINWSlI?style=social
+[youtube-url]: https://youtu.be/c6WWdINWSlI
diff --git a/JtProject/basedata.sql b/basedata.sql
similarity index 100%
rename from JtProject/basedata.sql
rename to basedata.sql
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 00000000..d46b09ea
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,40 @@
+services:
+ # MySQL Database Service
+ ecom-mysql-db:
+ image: mysql:8.0
+ container_name: ecom-mysql-db
+ restart: unless-stopped
+ environment:
+ MYSQL_ROOT_PASSWORD: root
+ MYSQL_DATABASE: db
+ MYSQL_USER: user
+ MYSQL_PASSWORD: password
+ ports:
+ - "3308:3306"
+ volumes:
+ - ecom-db-data:/var/lib/mysql
+ command: --default-authentication-plugin=mysql_native_password
+ healthcheck:
+ test: ["CMD-SHELL", "mysqladmin ping -h localhost -u$$MYSQL_USER -p$$MYSQL_PASSWORD --silent"]
+ interval: 10s
+ timeout: 5s
+ retries: 10
+ start_period: 20s
+
+ # Spring Boot Application Service
+ ecom-app:
+ build: .
+ container_name: ecom-app
+ restart: unless-stopped
+ ports:
+ - "8080:8080"
+ environment:
+ SPRING_DATASOURCE_URL: jdbc:mysql://ecom-mysql-db:3306/db?createDatabaseIfNotExist=true&allowPublicKeyRetrieval=true&useSSL=false
+ SPRING_DATASOURCE_USERNAME: user
+ SPRING_DATASOURCE_PASSWORD: password
+ depends_on:
+ ecom-mysql-db:
+ condition: service_healthy
+
+volumes:
+ ecom-db-data:
diff --git a/JtProject/mvnw b/mvnw
similarity index 100%
rename from JtProject/mvnw
rename to mvnw
diff --git a/JtProject/mvnw.cmd b/mvnw.cmd
similarity index 100%
rename from JtProject/mvnw.cmd
rename to mvnw.cmd
diff --git a/JtProject/pom.xml b/pom.xml
similarity index 52%
rename from JtProject/pom.xml
rename to pom.xml
index f3314f61..f9b1d2fa 100644
--- a/JtProject/pom.xml
+++ b/pom.xml
@@ -1,57 +1,56 @@
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
+
org.springframework.boot
spring-boot-starter-parent
- 2.6.4
-
+ 3.2.4
+
com.jtspringproject
JtSpringProject
0.0.1-SNAPSHOT
+ war
JtSpringProject
- Spring project for Java Technology
+ Modernized Spring Boot 3 E-commerce Project
+
- 11
+ 17
-
-
+
- org.junit.jupiter
- junit-jupiter
- 5.10.0
- test
+ org.springframework.boot
+ spring-boot-starter-web
-
org.springframework.boot
- spring-boot-starter-web
+ spring-boot-starter-data-jpa
-
org.springframework.boot
- spring-boot-starter-test
- test
+ spring-boot-starter-security
- org.springframework.boot
- spring-boot-devtools
+ com.mysql
+ mysql-connector-j
+ runtime
+
- javax.servlet
- jstl
+ org.flywaydb
+ flyway-core
- org.springframework.boot
- spring-boot-starter-data-jpa
+ org.flywaydb
+ flyway-mysql
@@ -59,18 +58,37 @@
tomcat-embed-jasper
-
- mysql
- mysql-connector-java
- 8.0.33
+ jakarta.servlet.jsp.jstl
+ jakarta.servlet.jsp.jstl-api
-
- org.springframework.boot
- spring-boot-starter-security
+ org.glassfish.web
+ jakarta.servlet.jsp.jstl
+
+ org.springframework.boot
+ spring-boot-devtools
+ true
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ com.h2database
+ h2
+ test
+
+
+ org.projectlombok
+ lombok
+ 1.18.36
+ provided
+
@@ -81,5 +99,4 @@
-
\ No newline at end of file
diff --git a/src/main/java/com/jtspringproject/JtSpringProject/JtSpringProjectApplication.java b/src/main/java/com/jtspringproject/JtSpringProject/JtSpringProjectApplication.java
new file mode 100644
index 00000000..16736c35
--- /dev/null
+++ b/src/main/java/com/jtspringproject/JtSpringProject/JtSpringProjectApplication.java
@@ -0,0 +1,24 @@
+package com.jtspringproject.JtSpringProject;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.domain.EntityScan;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+
+@SpringBootApplication
+@EntityScan("com.jtspringproject.JtSpringProject.models")
+@EnableJpaRepositories("com.jtspringproject.JtSpringProject.repository")
+public class JtSpringProjectApplication extends SpringBootServletInitializer {
+
+ @Override
+ protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
+ return application.sources(JtSpringProjectApplication.class);
+ }
+
+ public static void main(String[] args) {
+ SpringApplication.run(JtSpringProjectApplication.class, args);
+ }
+
+}
diff --git a/src/main/java/com/jtspringproject/JtSpringProject/configuration/PasswordConfiguration.java b/src/main/java/com/jtspringproject/JtSpringProject/configuration/PasswordConfiguration.java
new file mode 100644
index 00000000..c637de09
--- /dev/null
+++ b/src/main/java/com/jtspringproject/JtSpringProject/configuration/PasswordConfiguration.java
@@ -0,0 +1,15 @@
+package com.jtspringproject.JtSpringProject.configuration;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
+import org.springframework.security.crypto.password.PasswordEncoder;
+
+@Configuration
+public class PasswordConfiguration {
+
+ @Bean
+ public PasswordEncoder passwordEncoder() {
+ return new BCryptPasswordEncoder();
+ }
+}
diff --git a/src/main/java/com/jtspringproject/JtSpringProject/configuration/SecurityConfiguration.java b/src/main/java/com/jtspringproject/JtSpringProject/configuration/SecurityConfiguration.java
new file mode 100644
index 00000000..8423ba9d
--- /dev/null
+++ b/src/main/java/com/jtspringproject/JtSpringProject/configuration/SecurityConfiguration.java
@@ -0,0 +1,127 @@
+package com.jtspringproject.JtSpringProject.configuration;
+
+import com.jtspringproject.JtSpringProject.services.UserService;
+import jakarta.servlet.DispatcherType;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.annotation.Order;
+import org.springframework.security.config.annotation.web.builders.HttpSecurity;
+import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
+import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
+import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
+import org.springframework.security.core.userdetails.UserDetailsService;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+import org.springframework.security.crypto.password.PasswordEncoder;
+import org.springframework.security.web.SecurityFilterChain;
+
+@Configuration
+@EnableWebSecurity
+public class SecurityConfiguration {
+
+ private final UserService userService;
+ private final PasswordEncoder passwordEncoder;
+
+ public SecurityConfiguration(UserService userService, PasswordEncoder passwordEncoder) {
+ this.userService = userService;
+ this.passwordEncoder = passwordEncoder;
+ }
+
+ // ==========================================
+ // ADMIN SECURITY FILTER CHAIN
+ // ==========================================
+ @Bean
+ @Order(1)
+ public SecurityFilterChain adminFilterChain(HttpSecurity http) throws Exception {
+ http.securityMatcher("/admin/**")
+ .authenticationProvider(authenticationProvider())
+ .authorizeHttpRequests(auth -> auth
+ .dispatcherTypeMatchers(DispatcherType.FORWARD, DispatcherType.ERROR).permitAll()
+ .requestMatchers("/admin/login", "/admin/loginvalidate").permitAll()
+ .requestMatchers("/admin/**").hasRole("ADMIN")
+ )
+ .formLogin(form -> form
+ .loginPage("/admin/login")
+ .loginProcessingUrl("/admin/loginvalidate")
+ .defaultSuccessUrl("/admin/", true)
+ .failureUrl("/admin/login?error=true")
+ .permitAll()
+ )
+ .logout(logout -> logout
+ .logoutUrl("/admin/logout")
+ .logoutSuccessUrl("/admin/login")
+ .deleteCookies("JSESSIONID")
+ .invalidateHttpSession(true)
+ )
+ .exceptionHandling(ex -> ex.accessDeniedPage("/403"))
+ .csrf(AbstractHttpConfigurer::disable);
+
+ return http.build();
+ }
+
+ // ==========================================
+ // USER SECURITY FILTER CHAIN
+ // ==========================================
+ @Bean
+ @Order(2)
+ public SecurityFilterChain userFilterChain(HttpSecurity http) throws Exception {
+ http.authenticationProvider(authenticationProvider())
+ .authorizeHttpRequests(auth -> auth
+ .dispatcherTypeMatchers(DispatcherType.FORWARD, DispatcherType.ERROR).permitAll()
+
+ .requestMatchers("/css/**", "/js/**", "/images/**", "/views/**").permitAll()
+ .requestMatchers("/", "/login", "/register", "/newuserregister").permitAll()
+
+ .anyRequest().hasAnyRole("ADMIN", "NORMAL")
+ )
+ .formLogin(form -> form
+ .loginPage("/login")
+ .loginProcessingUrl("/userloginvalidate")
+ .defaultSuccessUrl("/", true)
+ .failureUrl("/login?error=true")
+ .permitAll()
+ )
+ .logout(logout -> logout
+ .logoutUrl("/logout")
+ .logoutSuccessUrl("/login")
+ .deleteCookies("JSESSIONID")
+ .invalidateHttpSession(true)
+ )
+ .exceptionHandling(ex -> ex.accessDeniedPage("/403"))
+ .csrf(AbstractHttpConfigurer::disable);
+
+ return http.build();
+ }
+
+ // ==========================================
+ // USER DETAILS SERVICE (FIXED ROLE MAPPING)
+ // ==========================================
+ @Bean
+ public UserDetailsService userDetailsService() {
+ return username -> {
+ com.jtspringproject.JtSpringProject.models.User user =
+ userService.getUserByUsername(username);
+
+ if (user == null) {
+ throw new UsernameNotFoundException("User not found: " + username);
+ }
+
+ // 🔥 FIX: dynamic role mapping
+ // Map stored ROLE_* values to Spring Security role names.
+ String role = user.getRole().replace("ROLE_", "");
+
+ return org.springframework.security.core.userdetails.User
+ .withUsername(user.getUsername())
+ .password(user.getPassword())
+ .roles(role) // Spring adds ROLE_ automatically
+ .build();
+ };
+ }
+
+ @Bean
+ public DaoAuthenticationProvider authenticationProvider() {
+ DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
+ provider.setUserDetailsService(userDetailsService());
+ provider.setPasswordEncoder(passwordEncoder);
+ return provider;
+ }
+}
diff --git a/src/main/java/com/jtspringproject/JtSpringProject/controller/AdminController.java b/src/main/java/com/jtspringproject/JtSpringProject/controller/AdminController.java
new file mode 100644
index 00000000..b20223bd
--- /dev/null
+++ b/src/main/java/com/jtspringproject/JtSpringProject/controller/AdminController.java
@@ -0,0 +1,241 @@
+package com.jtspringproject.JtSpringProject.controller;
+
+import java.util.List;
+
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.servlet.ModelAndView;
+
+import com.jtspringproject.JtSpringProject.models.Category;
+import com.jtspringproject.JtSpringProject.models.Product;
+import com.jtspringproject.JtSpringProject.models.User;
+import com.jtspringproject.JtSpringProject.services.CategoryService;
+import com.jtspringproject.JtSpringProject.services.ProductService;
+import com.jtspringproject.JtSpringProject.services.UserService;
+
+@Controller
+@RequestMapping("/admin")
+public class AdminController {
+
+ private final UserService userService;
+ private final CategoryService categoryService;
+ private final ProductService productService;
+
+ // Professional Constructor Injection
+ public AdminController(UserService userService, CategoryService categoryService, ProductService productService) {
+ this.userService = userService;
+ this.categoryService = categoryService;
+ this.productService = productService;
+ }
+
+ // ==========================================
+ // DASHBOARD & AUTHENTICATION
+ // ==========================================
+
+ @GetMapping(value = {"/index", "/", "/Dashboard"})
+ public ModelAndView adminHome() {
+ Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+ ModelAndView mv = new ModelAndView("adminHome");
+ mv.addObject("admin", authentication.getName());
+ return mv;
+ }
+
+ @GetMapping("/login")
+ public ModelAndView adminlogin(@RequestParam(required = false) String error) {
+ ModelAndView mv = new ModelAndView("adminlogin");
+ if ("true".equals(error)) {
+ mv.addObject("msg", "Invalid username or password. Please try again.");
+ }
+ return mv;
+ }
+
+ @GetMapping("/profileDisplay")
+ public String profileDisplay(Model model) {
+ String username = SecurityContextHolder.getContext().getAuthentication().getName();
+
+ // FIXED: Replaced raw JDBC with Service call
+ User user = userService.getUserByUsername(username);
+
+ if (user != null) {
+ model.addAttribute("userid", user.getId());
+ model.addAttribute("username", user.getUsername());
+ model.addAttribute("email", user.getEmail());
+ model.addAttribute("address", user.getAddress());
+ model.addAttribute("formAction", "/admin/updateuser");
+ model.addAttribute("backLink", "/admin/");
+ model.addAttribute("pageTitle", "Admin Profile");
+ }
+ return "updateProfile";
+ }
+
+ @PostMapping("/updateuser")
+ public String updateUserProfile(@RequestParam("userid") int userid,
+ @RequestParam("username") String username,
+ @RequestParam("email") String email,
+ @RequestParam(value = "password", required = false) String password,
+ @RequestParam("address") String address,
+ Model model) {
+
+ try {
+ User updatedUser = userService.updateProfile(userid, username, email, password, address);
+ Authentication currentAuth = SecurityContextHolder.getContext().getAuthentication();
+ Authentication newAuth = new UsernamePasswordAuthenticationToken(
+ updatedUser.getUsername(),
+ currentAuth.getCredentials(),
+ currentAuth.getAuthorities()
+ );
+ SecurityContextHolder.getContext().setAuthentication(newAuth);
+ return "redirect:/admin/profileDisplay";
+ } catch (RuntimeException ex) {
+ model.addAttribute("userid", userid);
+ model.addAttribute("username", username);
+ model.addAttribute("email", email);
+ model.addAttribute("address", address);
+ model.addAttribute("formAction", "/admin/updateuser");
+ model.addAttribute("backLink", "/admin/");
+ model.addAttribute("pageTitle", "Admin Profile");
+ model.addAttribute("msg", ex.getMessage());
+ return "updateProfile";
+ }
+ }
+
+ // ==========================================
+ // CATEGORY MANAGEMENT
+ // ==========================================
+
+ @GetMapping("/categories")
+ public ModelAndView getcategory() {
+ ModelAndView mView = new ModelAndView("categories");
+ mView.addObject("categories", this.categoryService.getCategories());
+ return mView;
+ }
+
+ @PostMapping("/categories")
+ public String addCategory(@RequestParam("categoryname") String categoryName) {
+ this.categoryService.addCategory(categoryName);
+ return "redirect:/admin/categories";
+ }
+
+ @GetMapping("/categories/delete")
+ public String removeCategoryDb(@RequestParam("id") int id) {
+ this.categoryService.deleteCategory(id);
+ return "redirect:/admin/categories";
+ }
+
+ @GetMapping("/categories/update")
+ public String updateCategory(@RequestParam("categoryid") int id, @RequestParam("categoryname") String categoryName) {
+ this.categoryService.updateCategory(id, categoryName);
+ return "redirect:/admin/categories";
+ }
+
+ // ==========================================
+ // PRODUCT MANAGEMENT
+ // ==========================================
+
+ @GetMapping("/products")
+ public ModelAndView getproduct() {
+ ModelAndView mView = new ModelAndView("products");
+ List products = this.productService.getProducts();
+
+ if (products.isEmpty()) {
+ mView.addObject("msg", "No products are available");
+ } else {
+ mView.addObject("products", products);
+ }
+ return mView;
+ }
+
+ @GetMapping("/products/add")
+ public ModelAndView addProductForm() {
+ ModelAndView mView = new ModelAndView("productsAdd");
+ mView.addObject("categories", this.categoryService.getCategories());
+ return mView;
+ }
+
+ @PostMapping("/products/add")
+ public String addProduct(@RequestParam("name") String name,
+ @RequestParam("categoryid") int categoryId,
+ @RequestParam("price") int price,
+ @RequestParam("weight") int weight,
+ @RequestParam("quantity") int quantity,
+ @RequestParam("description") String description,
+ @RequestParam("productImage") String productImage) {
+
+ Category category = this.categoryService.getCategory(categoryId);
+ Product product = new Product();
+ // FIXED: Removed the buggy product.setId(categoryId)
+ product.setName(name);
+ product.setCategory(category);
+ product.setDescription(description);
+ product.setPrice(price);
+ product.setImage(productImage);
+ product.setWeight(weight);
+ product.setQuantity(quantity);
+
+ this.productService.addProduct(product);
+ return "redirect:/admin/products";
+ }
+
+ @GetMapping("/products/update/{id}")
+ public ModelAndView updateproductForm(@PathVariable("id") int id) {
+ ModelAndView mView = new ModelAndView("productsUpdate");
+ mView.addObject("categories", this.categoryService.getCategories());
+ mView.addObject("product", this.productService.getProduct(id));
+ return mView;
+ }
+
+ @PostMapping("/products/update/{id}")
+ public String updateProduct(@PathVariable("id") int id,
+ @RequestParam("name") String name,
+ @RequestParam("categoryid") int categoryId,
+ @RequestParam("price") int price,
+ @RequestParam("weight") int weight,
+ @RequestParam("quantity") int quantity,
+ @RequestParam("description") String description,
+ @RequestParam(value = "productImage", required = false) String productImage) {
+
+ Product product = this.productService.getProduct(id);
+
+ if (product != null) {
+ product.setName(name);
+ product.setCategory(this.categoryService.getCategory(categoryId));
+ product.setPrice(price);
+ product.setWeight(weight);
+ product.setQuantity(quantity);
+ product.setDescription(description);
+
+ // FIXED: Only update image if a new one is provided
+ if (productImage != null && !productImage.trim().isEmpty()) {
+ product.setImage(productImage);
+ }
+
+ this.productService.updateProduct(id, product);
+ }
+ return "redirect:/admin/products";
+ }
+
+ @GetMapping("/products/delete")
+ public String removeProduct(@RequestParam("id") int id) {
+ this.productService.deleteProduct(id);
+ return "redirect:/admin/products";
+ }
+
+ // ==========================================
+ // CUSTOMER MANAGEMENT
+ // ==========================================
+
+ @GetMapping("/customers")
+ public ModelAndView getCustomerDetail() {
+ ModelAndView mView = new ModelAndView("displayCustomers");
+ mView.addObject("customers", this.userService.getUsers());
+ return mView;
+ }
+}
diff --git a/src/main/java/com/jtspringproject/JtSpringProject/controller/UserController.java b/src/main/java/com/jtspringproject/JtSpringProject/controller/UserController.java
new file mode 100644
index 00000000..d8e4b72e
--- /dev/null
+++ b/src/main/java/com/jtspringproject/JtSpringProject/controller/UserController.java
@@ -0,0 +1,235 @@
+package com.jtspringproject.JtSpringProject.controller;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.springframework.security.authentication.AnonymousAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.servlet.ModelAndView;
+
+import com.jtspringproject.JtSpringProject.models.Cart;
+import com.jtspringproject.JtSpringProject.models.Product;
+import com.jtspringproject.JtSpringProject.models.User;
+import com.jtspringproject.JtSpringProject.models.CartProduct;
+import com.jtspringproject.JtSpringProject.models.CartProductId;
+import com.jtspringproject.JtSpringProject.repository.CartProductRepository;
+import com.jtspringproject.JtSpringProject.services.CartService;
+import com.jtspringproject.JtSpringProject.services.ProductService;
+import com.jtspringproject.JtSpringProject.services.UserService;
+
+@Controller
+public class UserController {
+
+ // Dependencies marked as final for immutability
+ private final UserService userService;
+ private final ProductService productService;
+ private final CartService cartService;
+ private final CartProductRepository cartProductRepository;
+
+ // Professional Constructor Injection
+ public UserController(UserService userService, ProductService productService, CartService cartService, CartProductRepository cartProductRepository) {
+ this.userService = userService;
+ this.productService = productService;
+ this.cartService = cartService;
+ this.cartProductRepository = cartProductRepository;
+ }
+
+ @GetMapping("/register")
+ public String registerUser() {
+ return "register";
+ }
+
+ @GetMapping("/buy")
+ public String buy() {
+ return "buy";
+ }
+
+ @GetMapping("/403")
+ public ModelAndView accessDenied() {
+ return new ModelAndView("403");
+ }
+
+ @GetMapping("/login")
+ public ModelAndView userlogin(@RequestParam(required = false) String error) {
+ ModelAndView mv = new ModelAndView("userLogin");
+ if ("true".equals(error)) {
+ mv.addObject("msg", "Invalid username or password. Please try again.");
+ }
+ return mv;
+ }
+
+ @GetMapping("/")
+ public ModelAndView indexPage() {
+ ModelAndView mView = new ModelAndView("index");
+ Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
+ String username = (authentication == null || authentication instanceof AnonymousAuthenticationToken)
+ ? "Guest"
+ : authentication.getName();
+ mView.addObject("username", username);
+
+ List products = this.productService.getProducts();
+ if (products.isEmpty()) {
+ mView.addObject("msg", "No products are available");
+ } else {
+ mView.addObject("products", products);
+ }
+ return mView;
+ }
+
+ @GetMapping("/user/products")
+ public ModelAndView getproduct() {
+ ModelAndView mView = new ModelAndView("uproduct");
+ List products = this.productService.getProducts();
+
+ if(products.isEmpty()) {
+ mView.addObject("msg","No products are available");
+ } else {
+ mView.addObject("products", products);
+ }
+ return mView;
+ }
+
+ // Modernized to @PostMapping
+ @PostMapping("/newuserregister")
+ public ModelAndView newUseRegister(@ModelAttribute User user) {
+ try {
+ this.userService.registerUser(user);
+ ModelAndView mView = new ModelAndView("userLogin");
+ mView.addObject("msg", "Account created. Sign in with your new credentials.");
+ return mView;
+ } catch (RuntimeException ex) {
+ ModelAndView mView = new ModelAndView("register");
+ mView.addObject("msg", ex.getMessage());
+ return mView;
+ }
+ }
+
+ @GetMapping("/profileDisplay")
+ public String profileDisplay(Model model) {
+ String username = SecurityContextHolder.getContext().getAuthentication().getName();
+ User user = userService.getUserByUsername(username);
+
+ if (user != null) {
+ model.addAttribute("userid", user.getId());
+ model.addAttribute("username", user.getUsername());
+ model.addAttribute("email", user.getEmail());
+ model.addAttribute("address", user.getAddress());
+ model.addAttribute("formAction", "/updateuser");
+ model.addAttribute("backLink", "/");
+ model.addAttribute("pageTitle", "Update Profile");
+ } else {
+ model.addAttribute("msg", "User not found");
+ }
+ return "updateProfile";
+ }
+
+ @PostMapping("/updateuser")
+ public String updateUserProfile(@RequestParam("userid") int userId,
+ @RequestParam("username") String username,
+ @RequestParam("email") String email,
+ @RequestParam(value = "password", required = false) String password,
+ @RequestParam("address") String address,
+ Model model) {
+
+ try {
+ User updatedUser = userService.updateProfile(userId, username, email, password, address);
+ Authentication currentAuth = SecurityContextHolder.getContext().getAuthentication();
+ Authentication newAuth = new org.springframework.security.authentication.UsernamePasswordAuthenticationToken(
+ updatedUser.getUsername(),
+ currentAuth.getCredentials(),
+ currentAuth.getAuthorities()
+ );
+ SecurityContextHolder.getContext().setAuthentication(newAuth);
+ return "redirect:/profileDisplay";
+ } catch (RuntimeException ex) {
+ model.addAttribute("userid", userId);
+ model.addAttribute("username", username);
+ model.addAttribute("email", email);
+ model.addAttribute("address", address);
+ model.addAttribute("formAction", "/updateuser");
+ model.addAttribute("backLink", "/");
+ model.addAttribute("pageTitle", "Update Profile");
+ model.addAttribute("msg", ex.getMessage());
+ return "updateProfile";
+ }
+ }
+
+ // FIXED: Uncommented and wired up the Cart endpoint properly
+ @GetMapping("/user/cartproducts")
+ public ModelAndView getCartDetail() {
+ ModelAndView mv = new ModelAndView("cartproduct");
+ String username = SecurityContextHolder.getContext().getAuthentication().getName();
+ User user = userService.getUserByUsername(username);
+
+ if (user != null) {
+ Cart userCart = cartService.getCartByUserId(user.getId());
+ if (userCart != null) {
+ List cpList = cartProductRepository.findByCart_Id(userCart.getId());
+ List prods = new ArrayList<>();
+ for(CartProduct cp : cpList) prods.add(cp.getProduct());
+ mv.addObject("cartProducts", prods);
+ }
+ }
+ return mv;
+ }
+
+ @PostMapping("/user/addtocart")
+ public String addToCart(@RequestParam("productId") int productId) {
+ String username = SecurityContextHolder.getContext().getAuthentication().getName();
+ User user = userService.getUserByUsername(username);
+ Product product = productService.getProduct(productId);
+
+ if (user == null || product == null) {
+ return "redirect:/";
+ }
+
+ Cart cart = cartService.getCartByUserId(user.getId());
+ if (cart == null) {
+ cart = new Cart();
+ cart.setCustomer(user);
+ cart = cartService.addCart(cart);
+ }
+
+ CartProductId cartProductId = new CartProductId(cart.getId(), product.getId());
+ if (!cartProductRepository.existsById(cartProductId)) {
+ cartProductRepository.save(new CartProduct(cart, product));
+ }
+
+ return "redirect:/user/cartproducts";
+ }
+
+ // ==========================================
+ // LEARNING & TEST ENDPOINTS
+ // ==========================================
+
+ @GetMapping("/test")
+ public String Test(Model model) {
+ model.addAttribute("author","jay gajera");
+ model.addAttribute("id",40);
+
+ List friends = new ArrayList<>();
+ friends.add("xyz");
+ friends.add("abc");
+ model.addAttribute("f", friends);
+
+ return "test";
+ }
+
+ @GetMapping("/test2")
+ public ModelAndView Test2() {
+ ModelAndView mv = new ModelAndView("test2");
+ mv.addObject("name","jay gajera 17");
+ mv.addObject("id",40);
+
+ List list = new ArrayList<>();
+ list.add(10);
+ list.add(25);
+ mv.addObject("marks", list);
+
+ return mv;
+ }
+}
diff --git a/JtProject/src/main/java/com/jtspringproject/JtSpringProject/models/Cart.java b/src/main/java/com/jtspringproject/JtSpringProject/models/Cart.java
similarity index 79%
rename from JtProject/src/main/java/com/jtspringproject/JtSpringProject/models/Cart.java
rename to src/main/java/com/jtspringproject/JtSpringProject/models/Cart.java
index 61fe66cd..33cfc840 100644
--- a/JtProject/src/main/java/com/jtspringproject/JtSpringProject/models/Cart.java
+++ b/src/main/java/com/jtspringproject/JtSpringProject/models/Cart.java
@@ -1,11 +1,14 @@
package com.jtspringproject.JtSpringProject.models;
-import javax.persistence.*;
+import jakarta.persistence.*;
+import lombok.Data;
+
import java.util.ArrayList;
import java.util.List;
@Entity(name="CART")
+@Data
public class Cart {
@Id
@@ -24,25 +27,6 @@ public class Cart {
// private List products;
- public Cart() {
- }
-
- public int getId() {
- return id;
- }
-
- public void setId(int id) {
- this.id = id;
- }
-
-
- public User getCustomer() {
- return customer;
- }
-
- public void setCustomer(User customer) {
- this.customer = customer;
- }
// public List getProducts() {
// return products;
diff --git a/JtProject/src/main/java/com/jtspringproject/JtSpringProject/models/CartProduct.java b/src/main/java/com/jtspringproject/JtSpringProject/models/CartProduct.java
similarity index 57%
rename from JtProject/src/main/java/com/jtspringproject/JtSpringProject/models/CartProduct.java
rename to src/main/java/com/jtspringproject/JtSpringProject/models/CartProduct.java
index aeb9ef7b..b956ad5b 100644
--- a/JtProject/src/main/java/com/jtspringproject/JtSpringProject/models/CartProduct.java
+++ b/src/main/java/com/jtspringproject/JtSpringProject/models/CartProduct.java
@@ -1,9 +1,11 @@
package com.jtspringproject.JtSpringProject.models;
-import javax.persistence.*;
+import jakarta.persistence.*;
+import lombok.Data;
@Entity
@Table(name = "CART_PRODUCT")
+@Data
public class CartProduct {
@EmbeddedId
@@ -27,27 +29,4 @@ public CartProduct(Cart cart, Product product) {
this.id = new CartProductId(cart.getId(), product.getId());
}
- public CartProductId getId() {
- return id;
- }
-
- public void setId(CartProductId id) {
- this.id = id;
- }
-
- public Cart getCart() {
- return cart;
- }
-
- public void setCart(Cart cart) {
- this.cart = cart;
- }
-
- public Product getProduct() {
- return product;
- }
-
- public void setProduct(Product product) {
- this.product = product;
- }
}
diff --git a/JtProject/src/main/java/com/jtspringproject/JtSpringProject/models/CartProductId.java b/src/main/java/com/jtspringproject/JtSpringProject/models/CartProductId.java
similarity index 70%
rename from JtProject/src/main/java/com/jtspringproject/JtSpringProject/models/CartProductId.java
rename to src/main/java/com/jtspringproject/JtSpringProject/models/CartProductId.java
index 84f84213..04930dc1 100644
--- a/JtProject/src/main/java/com/jtspringproject/JtSpringProject/models/CartProductId.java
+++ b/src/main/java/com/jtspringproject/JtSpringProject/models/CartProductId.java
@@ -1,11 +1,14 @@
package com.jtspringproject.JtSpringProject.models;
-import javax.persistence.Column;
-import javax.persistence.Embeddable;
+import jakarta.persistence.Column;
+import jakarta.persistence.Embeddable;
+import lombok.Data;
+
import java.io.Serializable;
import java.util.Objects;
@Embeddable
+@Data
public class CartProductId implements Serializable {
@Column(name = "cart_id")
@@ -21,21 +24,6 @@ public CartProductId(Integer cartId, Integer productId) {
this.productId = productId;
}
- public Integer getCartId() {
- return cartId;
- }
-
- public void setCartId(Integer cartId) {
- this.cartId = cartId;
- }
-
- public Integer getProductId() {
- return productId;
- }
-
- public void setProductId(Integer productId) {
- this.productId = productId;
- }
@Override
public boolean equals(Object o) {
diff --git a/src/main/java/com/jtspringproject/JtSpringProject/models/Category.java b/src/main/java/com/jtspringproject/JtSpringProject/models/Category.java
new file mode 100644
index 00000000..e726b9e6
--- /dev/null
+++ b/src/main/java/com/jtspringproject/JtSpringProject/models/Category.java
@@ -0,0 +1,21 @@
+package com.jtspringproject.JtSpringProject.models;
+
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.GeneratedValue;
+import jakarta.persistence.GenerationType;
+import jakarta.persistence.Id;
+import lombok.Data;
+
+@Entity(name="CATEGORY")
+@Data
+public class Category {
+ @Id
+ @Column(name = "category_id")
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ private int id;
+
+ private String name;
+
+
+}
diff --git a/src/main/java/com/jtspringproject/JtSpringProject/models/Product.java b/src/main/java/com/jtspringproject/JtSpringProject/models/Product.java
new file mode 100644
index 00000000..c38c752f
--- /dev/null
+++ b/src/main/java/com/jtspringproject/JtSpringProject/models/Product.java
@@ -0,0 +1,37 @@
+package com.jtspringproject.JtSpringProject.models;
+
+import jakarta.persistence.*;
+import lombok.Data;
+
+
+@Entity(name="PRODUCT")
+@Data
+public class Product {
+ @Id
+ @Column(name = "product_id")
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ private int id;
+
+ private String name;
+
+ private String image;
+
+ @ManyToOne(fetch = FetchType.EAGER)
+ @JoinColumn(name = "category_id")
+ private Category category;
+
+ private int quantity;
+
+ private int price;
+
+ private int weight;
+
+ private String description;
+
+
+ @ManyToOne
+ @JoinColumn(name = "customer_id")
+ private User customer;
+
+
+}
diff --git a/src/main/java/com/jtspringproject/JtSpringProject/models/User.java b/src/main/java/com/jtspringproject/JtSpringProject/models/User.java
new file mode 100644
index 00000000..46574d75
--- /dev/null
+++ b/src/main/java/com/jtspringproject/JtSpringProject/models/User.java
@@ -0,0 +1,31 @@
+package com.jtspringproject.JtSpringProject.models;
+import java.util.List;
+
+import jakarta.persistence.*;
+import lombok.Data;
+
+
+@Entity(name="CUSTOMER")
+@Table
+@Data
+public class User {
+
+ @Id
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ private int id;
+
+ @Column(unique = true)
+ private String username;
+
+ private String email;
+
+ private String password;
+
+ private String role;
+
+ private String address;
+
+
+
+
+}
diff --git a/JtProject/src/main/java/com/jtspringproject/JtSpringProject/repository/CartProductRepository.java b/src/main/java/com/jtspringproject/JtSpringProject/repository/CartProductRepository.java
similarity index 61%
rename from JtProject/src/main/java/com/jtspringproject/JtSpringProject/repository/CartProductRepository.java
rename to src/main/java/com/jtspringproject/JtSpringProject/repository/CartProductRepository.java
index c305f576..feda3fa2 100644
--- a/JtProject/src/main/java/com/jtspringproject/JtSpringProject/repository/CartProductRepository.java
+++ b/src/main/java/com/jtspringproject/JtSpringProject/repository/CartProductRepository.java
@@ -3,6 +3,13 @@
import com.jtspringproject.JtSpringProject.models.CartProduct;
import com.jtspringproject.JtSpringProject.models.CartProductId;
import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+import java.util.List;
+
+@Repository
public interface CartProductRepository extends JpaRepository {
-}
+
+ // Auto-generates the join required to find products in a specific cart
+ List findByCart_Id(int cartId);
+}
\ No newline at end of file
diff --git a/src/main/java/com/jtspringproject/JtSpringProject/repository/CartRepository.java b/src/main/java/com/jtspringproject/JtSpringProject/repository/CartRepository.java
new file mode 100644
index 00000000..764092ba
--- /dev/null
+++ b/src/main/java/com/jtspringproject/JtSpringProject/repository/CartRepository.java
@@ -0,0 +1,13 @@
+package com.jtspringproject.JtSpringProject.repository;
+
+import com.jtspringproject.JtSpringProject.models.Cart;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.Optional;
+
+@Repository
+public interface CartRepository extends JpaRepository {
+ // Finds a cart linked to a specific customer ID
+ Optional findByCustomer_Id(int customerId);
+}
\ No newline at end of file
diff --git a/src/main/java/com/jtspringproject/JtSpringProject/repository/CategoryRepository.java b/src/main/java/com/jtspringproject/JtSpringProject/repository/CategoryRepository.java
new file mode 100644
index 00000000..4f3d5f14
--- /dev/null
+++ b/src/main/java/com/jtspringproject/JtSpringProject/repository/CategoryRepository.java
@@ -0,0 +1,9 @@
+package com.jtspringproject.JtSpringProject.repository;
+
+import com.jtspringproject.JtSpringProject.models.Category;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface CategoryRepository extends JpaRepository {
+}
\ No newline at end of file
diff --git a/src/main/java/com/jtspringproject/JtSpringProject/repository/ProductRepository.java b/src/main/java/com/jtspringproject/JtSpringProject/repository/ProductRepository.java
new file mode 100644
index 00000000..ba4f6206
--- /dev/null
+++ b/src/main/java/com/jtspringproject/JtSpringProject/repository/ProductRepository.java
@@ -0,0 +1,9 @@
+package com.jtspringproject.JtSpringProject.repository;
+
+import com.jtspringproject.JtSpringProject.models.Product;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface ProductRepository extends JpaRepository {
+}
\ No newline at end of file
diff --git a/src/main/java/com/jtspringproject/JtSpringProject/repository/UserRepository.java b/src/main/java/com/jtspringproject/JtSpringProject/repository/UserRepository.java
new file mode 100644
index 00000000..5989e068
--- /dev/null
+++ b/src/main/java/com/jtspringproject/JtSpringProject/repository/UserRepository.java
@@ -0,0 +1,17 @@
+package com.jtspringproject.JtSpringProject.repository;
+
+import com.jtspringproject.JtSpringProject.models.User;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.Optional;
+
+@Repository
+public interface UserRepository extends JpaRepository {
+
+ // Auto-generates: SELECT * FROM CUSTOMER WHERE username = ?
+ Optional findByUsername(String username);
+
+ // Auto-generates: SELECT COUNT(*) > 0 FROM CUSTOMER WHERE username = ?
+ boolean existsByUsername(String username);
+}
\ No newline at end of file
diff --git a/src/main/java/com/jtspringproject/JtSpringProject/services/CartService.java b/src/main/java/com/jtspringproject/JtSpringProject/services/CartService.java
new file mode 100644
index 00000000..547a5a73
--- /dev/null
+++ b/src/main/java/com/jtspringproject/JtSpringProject/services/CartService.java
@@ -0,0 +1,36 @@
+package com.jtspringproject.JtSpringProject.services;
+
+import java.util.List;
+import org.springframework.stereotype.Service;
+import com.jtspringproject.JtSpringProject.repository.CartRepository;
+import com.jtspringproject.JtSpringProject.models.Cart;
+
+@Service
+public class CartService {
+
+ private final CartRepository cartRepository;
+
+ public CartService(CartRepository cartRepository) {
+ this.cartRepository = cartRepository;
+ }
+
+ public Cart addCart(Cart cart) {
+ return cartRepository.save(cart);
+ }
+
+ public List getCarts() {
+ return cartRepository.findAll();
+ }
+
+ public void updateCart(Cart cart) {
+ cartRepository.save(cart);
+ }
+
+ public void deleteCart(Cart cart) {
+ cartRepository.delete(cart);
+ }
+
+ public Cart getCartByUserId(int customerId) {
+ return cartRepository.findByCustomer_Id(customerId).orElse(null);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/jtspringproject/JtSpringProject/services/CategoryService.java b/src/main/java/com/jtspringproject/JtSpringProject/services/CategoryService.java
new file mode 100644
index 00000000..e218d6c7
--- /dev/null
+++ b/src/main/java/com/jtspringproject/JtSpringProject/services/CategoryService.java
@@ -0,0 +1,48 @@
+package com.jtspringproject.JtSpringProject.services;
+
+import java.util.List;
+import org.springframework.stereotype.Service;
+import com.jtspringproject.JtSpringProject.repository.CategoryRepository;
+import com.jtspringproject.JtSpringProject.models.Category;
+
+@Service
+public class CategoryService {
+
+ private final CategoryRepository categoryRepository;
+
+ // Constructor Injection (Enterprise Standard)
+ public CategoryService(CategoryRepository categoryRepository) {
+ this.categoryRepository = categoryRepository;
+ }
+
+ public Category addCategory(String name) {
+ Category category = new Category();
+ category.setName(name);
+ return categoryRepository.save(category);
+ }
+
+ public List getCategories() {
+ return categoryRepository.findAll();
+ }
+
+ public Boolean deleteCategory(int id) {
+ if (categoryRepository.existsById(id)) {
+ categoryRepository.deleteById(id);
+ return true;
+ }
+ return false;
+ }
+
+ public Category updateCategory(int id, String name) {
+ Category category = categoryRepository.findById(id).orElse(null);
+ if (category != null) {
+ category.setName(name);
+ return categoryRepository.save(category);
+ }
+ return null;
+ }
+
+ public Category getCategory(int id) {
+ return categoryRepository.findById(id).orElse(null);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/jtspringproject/JtSpringProject/services/ProductService.java b/src/main/java/com/jtspringproject/JtSpringProject/services/ProductService.java
new file mode 100644
index 00000000..47aeda33
--- /dev/null
+++ b/src/main/java/com/jtspringproject/JtSpringProject/services/ProductService.java
@@ -0,0 +1,41 @@
+package com.jtspringproject.JtSpringProject.services;
+
+import java.util.List;
+import org.springframework.stereotype.Service;
+import com.jtspringproject.JtSpringProject.repository.ProductRepository;
+import com.jtspringproject.JtSpringProject.models.Product;
+
+@Service
+public class ProductService {
+
+ private final ProductRepository productRepository;
+
+ public ProductService(ProductRepository productRepository) {
+ this.productRepository = productRepository;
+ }
+
+ public List getProducts() {
+ return productRepository.findAll();
+ }
+
+ public Product addProduct(Product product) {
+ return productRepository.save(product);
+ }
+
+ public Product getProduct(int id) {
+ return productRepository.findById(id).orElse(null);
+ }
+
+ public Product updateProduct(int id, Product product) {
+ product.setId(id);
+ return productRepository.save(product); // .save() acts as update when ID is present
+ }
+
+ public boolean deleteProduct(int id) {
+ if (productRepository.existsById(id)) {
+ productRepository.deleteById(id);
+ return true;
+ }
+ return false;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/jtspringproject/JtSpringProject/services/UserService.java b/src/main/java/com/jtspringproject/JtSpringProject/services/UserService.java
new file mode 100644
index 00000000..9db5cd3c
--- /dev/null
+++ b/src/main/java/com/jtspringproject/JtSpringProject/services/UserService.java
@@ -0,0 +1,84 @@
+package com.jtspringproject.JtSpringProject.services;
+
+import java.util.List;
+import org.springframework.dao.DataIntegrityViolationException;
+import org.springframework.security.crypto.password.PasswordEncoder;
+import org.springframework.stereotype.Service;
+import com.jtspringproject.JtSpringProject.repository.UserRepository;
+import com.jtspringproject.JtSpringProject.models.User;
+
+@Service
+public class UserService {
+
+ private final UserRepository userRepository;
+ private final PasswordEncoder passwordEncoder;
+
+ public UserService(UserRepository userRepository, PasswordEncoder passwordEncoder) {
+ this.userRepository = userRepository;
+ this.passwordEncoder = passwordEncoder;
+ }
+
+ public List getUsers() {
+ return userRepository.findAll();
+ }
+
+ public User addUser(User user) {
+ try {
+ return userRepository.save(user);
+ } catch (DataIntegrityViolationException e) {
+ throw new RuntimeException("Add user error: Username or Email already exists.");
+ }
+ }
+
+ public User checkLogin(String username, String password) {
+ User user = userRepository.findByUsername(username).orElse(null);
+
+ if (user != null && passwordEncoder.matches(password, user.getPassword())) {
+ return user;
+ }
+ return new User();
+ }
+
+ public boolean checkUserExists(String username) {
+ return userRepository.existsByUsername(username);
+ }
+
+ public User getUserByUsername(String username) {
+ return userRepository.findByUsername(username).orElse(null);
+ }
+
+ public User getUserById(int id) {
+ return userRepository.findById(id).orElse(null);
+ }
+
+ public User registerUser(User user) {
+ if (checkUserExists(user.getUsername())) {
+ throw new RuntimeException("Username already exists.");
+ }
+
+ user.setRole("ROLE_NORMAL");
+ user.setPassword(passwordEncoder.encode(user.getPassword()));
+ return addUser(user);
+ }
+
+ public User updateProfile(int userId, String username, String email, String rawPassword, String address) {
+ User user = getUserById(userId);
+ if (user == null) {
+ throw new RuntimeException("User not found.");
+ }
+
+ if (!user.getUsername().equals(username) && checkUserExists(username)) {
+ throw new RuntimeException("Username already exists.");
+ }
+
+ user.setUsername(username);
+ user.setEmail(email);
+ user.setAddress(address);
+
+ if (rawPassword != null && !rawPassword.isBlank()) {
+ user.setPassword(passwordEncoder.encode(rawPassword));
+ }
+
+ return addUser(user);
+ }
+}
diff --git a/JtProject/src/main/resources/Product Images/one.jpg b/src/main/resources/Product Images/one.jpg
similarity index 100%
rename from JtProject/src/main/resources/Product Images/one.jpg
rename to src/main/resources/Product Images/one.jpg
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
new file mode 100644
index 00000000..cd28ed98
--- /dev/null
+++ b/src/main/resources/application.properties
@@ -0,0 +1,34 @@
+# ==========================================
+# SERVER CONFIGURATION
+# ==========================================
+server.port=8080
+
+# ==========================================
+# JSP VIEW RESOLUTION
+# ==========================================
+spring.mvc.view.prefix=/WEB-INF/views/
+spring.mvc.view.suffix=.jsp
+
+# ==========================================
+# DATABASE CONNECTION
+# ==========================================
+spring.datasource.url=${SPRING_DATASOURCE_URL:jdbc:mysql://localhost:3308/db?createDatabaseIfNotExist=true&allowPublicKeyRetrieval=true&useSSL=false}
+spring.datasource.username=${SPRING_DATASOURCE_USERNAME:user}
+spring.datasource.password=${SPRING_DATASOURCE_PASSWORD:password}
+spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
+
+# ==========================================
+# SPRING DATA JPA & HIBERNATE 6
+# ==========================================
+spring.jpa.hibernate.ddl-auto=update
+spring.jpa.show-sql=true
+spring.jpa.properties.hibernate.format_sql=true
+spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
+spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
+
+# ==========================================
+# FLYWAY MIGRATION
+# ==========================================
+spring.flyway.enabled=true
+spring.flyway.baseline-on-migrate=true
+spring.flyway.baseline-version=1
\ No newline at end of file
diff --git a/src/main/resources/db/migration/V1__custom_setup.sql b/src/main/resources/db/migration/V1__custom_setup.sql
new file mode 100644
index 00000000..12ff0f7e
--- /dev/null
+++ b/src/main/resources/db/migration/V1__custom_setup.sql
@@ -0,0 +1,52 @@
+CREATE TABLE IF NOT EXISTS category (
+ category_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ name VARCHAR(255) NULL
+);
+
+INSERT INTO category (name)
+SELECT category_name
+FROM (
+ SELECT 'Fruits' AS category_name
+ UNION ALL SELECT 'Vegetables'
+ UNION ALL SELECT 'Meat'
+ UNION ALL SELECT 'Fish'
+ UNION ALL SELECT 'Dairy'
+ UNION ALL SELECT 'Bakery'
+ UNION ALL SELECT 'Drinks'
+ UNION ALL SELECT 'Sweets'
+ UNION ALL SELECT 'Other'
+) AS categories
+WHERE NOT EXISTS (SELECT 1 FROM category);
+
+CREATE TABLE IF NOT EXISTS customer (
+ id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ address VARCHAR(255) NULL,
+ email VARCHAR(255) NULL,
+ password VARCHAR(255) NULL,
+ role VARCHAR(255) NULL,
+ username VARCHAR(255) NULL,
+ CONSTRAINT uk_customer_username UNIQUE (username)
+);
+
+INSERT INTO customer (address, email, password, role, username)
+SELECT *
+FROM (
+ SELECT '123, Albany Street', 'admin@nyan.cat', '$2a$10$qSF.16A43bqxoWEnT.iywurQs/U.iM1p0Y6l.tg7bgSU.S/11xmXu', 'ROLE_ADMIN', 'admin'
+ UNION ALL
+ SELECT '765, 5th Avenue', 'lisa@gmail.com', '$2a$10$ZhgpbHQISdbx6MUTP6A6M.5dN1QRDQVQyYFxoCmAOMr/j5uURO0q2', 'ROLE_NORMAL', 'lisa'
+) AS customers
+WHERE NOT EXISTS (SELECT 1 FROM customer);
+
+CREATE TABLE IF NOT EXISTS product (
+ product_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ description VARCHAR(255) NULL,
+ image VARCHAR(255) NULL,
+ name VARCHAR(255) NULL,
+ price INT NULL,
+ quantity INT NULL,
+ weight INT NULL,
+ category_id INT NULL,
+ customer_id INT NULL,
+ CONSTRAINT fk_product_category FOREIGN KEY (category_id) REFERENCES category (category_id),
+ CONSTRAINT fk_product_customer FOREIGN KEY (customer_id) REFERENCES customer (id)
+);
diff --git a/src/main/resources/db/migration/V2__seed_product.sql b/src/main/resources/db/migration/V2__seed_product.sql
new file mode 100644
index 00000000..db7c000b
--- /dev/null
+++ b/src/main/resources/db/migration/V2__seed_product.sql
@@ -0,0 +1,9 @@
+INSERT INTO product(description, image, name, price, quantity, weight, category_id)
+SELECT * FROM (
+ SELECT 'Fresh red apples', 'https://freepngimg.com/save/9557-apple-fruit-transparent/744x744', 'Apple', 120, 100, 200, 1
+ ) AS tmp
+WHERE NOT EXISTS (
+ SELECT 1 FROM product WHERE name = 'Apple'
+);
+
+-- Repeat pattern for others
diff --git a/src/main/resources/db/migration/V3__seed_product_varieties.sql b/src/main/resources/db/migration/V3__seed_product_varieties.sql
new file mode 100644
index 00000000..dae2d0f1
--- /dev/null
+++ b/src/main/resources/db/migration/V3__seed_product_varieties.sql
@@ -0,0 +1,59 @@
+INSERT INTO product (description, image, name, price, quantity, weight, category_id)
+SELECT * FROM (
+ SELECT 'Sweet Alphonso mangoes with a rich aroma and buttery texture.', 'https://images.unsplash.com/photo-1553279768-865429fa0078?auto=format&fit=crop&w=900&q=80', 'Alphonso Mango', 249, 45, 350, 1
+) AS tmp
+WHERE NOT EXISTS (SELECT 1 FROM product WHERE name = 'Alphonso Mango');
+
+INSERT INTO product (description, image, name, price, quantity, weight, category_id)
+SELECT * FROM (
+ SELECT 'Crisp green grapes that work well for snacking and chilled fruit bowls.', 'https://images.unsplash.com/photo-1537640538966-79f369143f8f?auto=format&fit=crop&w=900&q=80', 'Green Grapes', 139, 80, 250, 1
+) AS tmp
+WHERE NOT EXISTS (SELECT 1 FROM product WHERE name = 'Green Grapes');
+
+INSERT INTO product (description, image, name, price, quantity, weight, category_id)
+SELECT * FROM (
+ SELECT 'Tender baby spinach leaves cleaned and packed for quick salads and sauteing.', 'https://images.unsplash.com/photo-1576045057995-568f588f82fb?auto=format&fit=crop&w=900&q=80', 'Baby Spinach', 89, 60, 180, 2
+) AS tmp
+WHERE NOT EXISTS (SELECT 1 FROM product WHERE name = 'Baby Spinach');
+
+INSERT INTO product (description, image, name, price, quantity, weight, category_id)
+SELECT * FROM (
+ SELECT 'Colorful bell peppers with a balanced crunch for stir fry and roasting.', 'https://images.unsplash.com/photo-1563565375-f3fdfdbefa83?auto=format&fit=crop&w=900&q=80', 'Rainbow Bell Pepper Pack', 119, 50, 300, 2
+) AS tmp
+WHERE NOT EXISTS (SELECT 1 FROM product WHERE name = 'Rainbow Bell Pepper Pack');
+
+INSERT INTO product (description, image, name, price, quantity, weight, category_id)
+SELECT * FROM (
+ SELECT 'Skinless chicken breast fillets trimmed for lean weekday meals.', 'https://images.unsplash.com/photo-1604503468506-a8da13d82791?auto=format&fit=crop&w=900&q=80', 'Chicken Breast Fillet', 299, 35, 500, 3
+) AS tmp
+WHERE NOT EXISTS (SELECT 1 FROM product WHERE name = 'Chicken Breast Fillet');
+
+INSERT INTO product (description, image, name, price, quantity, weight, category_id)
+SELECT * FROM (
+ SELECT 'Freshwater rohu cuts packed for curry, fry, or light steaming.', 'https://images.unsplash.com/photo-1544943910-4c1dc44aab44?auto=format&fit=crop&w=900&q=80', 'Rohu Curry Cut', 279, 28, 500, 4
+) AS tmp
+WHERE NOT EXISTS (SELECT 1 FROM product WHERE name = 'Rohu Curry Cut');
+
+INSERT INTO product (description, image, name, price, quantity, weight, category_id)
+SELECT * FROM (
+ SELECT 'Thick Greek yogurt with a smooth finish and high protein content.', 'https://images.unsplash.com/photo-1488477181946-6428a0291777?auto=format&fit=crop&w=900&q=80', 'Greek Yogurt Cup', 75, 70, 200, 5
+) AS tmp
+WHERE NOT EXISTS (SELECT 1 FROM product WHERE name = 'Greek Yogurt Cup');
+
+INSERT INTO product (description, image, name, price, quantity, weight, category_id)
+SELECT * FROM (
+ SELECT 'Stone-baked sourdough loaf with a chewy crust and airy crumb.', 'https://images.unsplash.com/photo-1509440159596-0249088772ff?auto=format&fit=crop&w=900&q=80', 'Sourdough Bread', 149, 32, 400, 6
+) AS tmp
+WHERE NOT EXISTS (SELECT 1 FROM product WHERE name = 'Sourdough Bread');
+
+INSERT INTO product (description, image, name, price, quantity, weight, category_id)
+SELECT * FROM (
+ SELECT 'Cold-pressed orange juice with no added sugar and bright citrus notes.', 'https://images.unsplash.com/photo-1600271886742-f049cd451bba?auto=format&fit=crop&w=900&q=80', 'Cold Pressed Orange Juice', 110, 40, 1000, 7
+) AS tmp
+WHERE NOT EXISTS (SELECT 1 FROM product WHERE name = 'Cold Pressed Orange Juice');
+
+INSERT INTO product (description, image, name, price, quantity, weight, category_id)
+SELECT * FROM (
+ SELECT 'Mini chocolate brownies for dessert platters and coffee breaks.', 'https://images.unsplash.com/photo-1606313564200-e75d5e30476c?auto=format&fit=crop&w=900&q=80', 'Mini Brownie Box', 189, 24, 240, 8
+) AS tmp
+WHERE NOT EXISTS (SELECT 1 FROM product WHERE name = 'Mini Brownie Box');
diff --git a/src/main/webapp/WEB-INF/views/403.jsp b/src/main/webapp/WEB-INF/views/403.jsp
new file mode 100644
index 00000000..7f2b5ddf
--- /dev/null
+++ b/src/main/webapp/WEB-INF/views/403.jsp
@@ -0,0 +1,36 @@
+
+
+
+
+
+ 403 Access Denied – ShopEase
+
+
+
+
+
+
+
+
+
+
+
+
403
+
Access Denied
+
You don't have permission to access this resource. Please contact an administrator if you believe this is a mistake.
+
Return to Homepage
+
+
+
+
diff --git a/src/main/webapp/WEB-INF/views/adminHome.jsp b/src/main/webapp/WEB-INF/views/adminHome.jsp
new file mode 100644
index 00000000..b41ce5c7
--- /dev/null
+++ b/src/main/webapp/WEB-INF/views/adminHome.jsp
@@ -0,0 +1,123 @@
+
+
+
+
+
+ Admin Dashboard – ShopEase
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/webapp/WEB-INF/views/adminlogin.jsp b/src/main/webapp/WEB-INF/views/adminlogin.jsp
new file mode 100644
index 00000000..26041922
--- /dev/null
+++ b/src/main/webapp/WEB-INF/views/adminlogin.jsp
@@ -0,0 +1,126 @@
+
+
+
+
+
+ Admin Login – ShopEase
+
+
+
+
+
+
+
+
+
+
+
+
+
Admin Portal
+
Secure administrative access
+
+
+
+
+
+
+
+
diff --git a/src/main/webapp/WEB-INF/views/cartproduct.jsp b/src/main/webapp/WEB-INF/views/cartproduct.jsp
new file mode 100644
index 00000000..cc155c4d
--- /dev/null
+++ b/src/main/webapp/WEB-INF/views/cartproduct.jsp
@@ -0,0 +1,172 @@
+<%@page import="java.sql.*"%>
+<%@page import="java.util.*"%>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
+
+
+
+ My Cart – ShopEase
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Your cart is empty
+
Start Shopping
+
+
+
+
+
+
+
+ | Product Name |
+ Category |
+ Price |
+ Action |
+
+
+
+
+
+ | ${item.name} |
+ ${item.category.name} |
+ $${item.price} |
+
+
+ Remove
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/webapp/WEB-INF/views/categories.jsp b/src/main/webapp/WEB-INF/views/categories.jsp
new file mode 100644
index 00000000..010acf83
--- /dev/null
+++ b/src/main/webapp/WEB-INF/views/categories.jsp
@@ -0,0 +1,151 @@
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
+
+
+
+ Categories – ShopEase Admin
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ | ID |
+ Category Name |
+ Actions |
+
+
+
+
+
+ | #${category.id} |
+ ${category.name} |
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/webapp/WEB-INF/views/displayCustomers.jsp b/src/main/webapp/WEB-INF/views/displayCustomers.jsp
new file mode 100644
index 00000000..0048fb28
--- /dev/null
+++ b/src/main/webapp/WEB-INF/views/displayCustomers.jsp
@@ -0,0 +1,92 @@
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
+
+
+
+ Customers – ShopEase Admin
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ | Avatar |
+ Customer Name |
+ Email Address |
+ Delivery Address |
+
+
+
+
+
+ |
+
+ ${customer.username.substring(0,1).toUpperCase()}
+
+ |
+ ${customer.username} |
+ ${customer.email} |
+ ${customer.address} |
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/webapp/WEB-INF/views/index.jsp b/src/main/webapp/WEB-INF/views/index.jsp
new file mode 100644
index 00000000..2aed7850
--- /dev/null
+++ b/src/main/webapp/WEB-INF/views/index.jsp
@@ -0,0 +1,425 @@
+<%@page import="java.util.*"%>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
+
+
+
+ ShopEase - Fresh Perishable Products
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Fresh picks for every basket
+
Discover fruit, vegetables, dairy, bakery, drinks, and more from a cleaner catalog with better product detail and daily-ready stock.
+
+ Seasonal produce
+ Perishable handled with care
+ Fast local delivery
+
+
+
+
+
+
+
+
+
Available now
+
Shop from the latest seeded product range and anything newly added from the admin catalog.
+
+
+
+
+
+
+
No products found
+
Check back later for fresh inventory.
+
+
+
+
+
+
+
+
+

+
+
+
+ ${product.category.name}
+ ${product.weight} g
+
+
${product.name}
+
${product.description}
+
+ ${product.quantity} in stock
+ Ready to dispatch
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/webapp/WEB-INF/views/products.jsp b/src/main/webapp/WEB-INF/views/products.jsp
new file mode 100644
index 00000000..ca862cae
--- /dev/null
+++ b/src/main/webapp/WEB-INF/views/products.jsp
@@ -0,0 +1,330 @@
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
+
+
+
+ Products - ShopEase Admin
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Product Catalog
+
Review stock, keep pricing sharp, and publish richer product cards that feel like a real marketplace instead of placeholder inventory.
+
+
New Product
+
+
+
+
+
+
+
+ All products
+ Manage every live item from one place.
+
+
${empty products ? '0 items' : products.size()} items
+
+
+
+
+
+
+
No products yet
+
Start by adding your first product to populate the storefront.
+
+
+
+
+
+
+
+ | Item |
+ Category |
+ Price |
+ Weight |
+ Stock |
+ Actions |
+
+
+
+
+
+
+
+ 
+
+ ${product.name}
+ ${product.description}
+
+
+ |
+ ${product.category.name} |
+ Rs. ${product.price} |
+ ${product.weight} g |
+
+
+ ${product.quantity} units
+
+ |
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/webapp/WEB-INF/views/productsAdd.jsp b/src/main/webapp/WEB-INF/views/productsAdd.jsp
new file mode 100644
index 00000000..78279a52
--- /dev/null
+++ b/src/main/webapp/WEB-INF/views/productsAdd.jsp
@@ -0,0 +1,345 @@
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
+
+
+
+ Add Product - ShopEase Admin
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Preview
+
Product card snapshot
+
+
+
+
+ Paste an image URL to preview the storefront card.
+
+
![Preview]()
+
+
+
+
+ Use descriptive names
+ Example: "Cold Pressed Orange Juice" is stronger than a generic product title.
+
+
+ Write shopper-facing copy
+ Call out freshness, taste, pack size, or the best use case in one compact paragraph.
+
+
+ Keep inventory believable
+ Weight, price, and stock should align so the catalog feels curated instead of placeholder-driven.
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/webapp/WEB-INF/views/productsUpdate.jsp b/src/main/webapp/WEB-INF/views/productsUpdate.jsp
new file mode 100644
index 00000000..39ebbee7
--- /dev/null
+++ b/src/main/webapp/WEB-INF/views/productsUpdate.jsp
@@ -0,0 +1,137 @@
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
+
+
+
+ Edit Product – ShopEase Admin
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/webapp/WEB-INF/views/register.jsp b/src/main/webapp/WEB-INF/views/register.jsp
new file mode 100644
index 00000000..41a575b8
--- /dev/null
+++ b/src/main/webapp/WEB-INF/views/register.jsp
@@ -0,0 +1,133 @@
+
+
+
+
+
+ Register – ShopEase
+
+
+
+
+
+
+
+
+
+
+
+
Create an Account
+
Join ShopEase and start shopping
+
+
+
${msg}
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/JtProject/src/main/webapp/views/test.jsp b/src/main/webapp/WEB-INF/views/test.jsp
similarity index 100%
rename from JtProject/src/main/webapp/views/test.jsp
rename to src/main/webapp/WEB-INF/views/test.jsp
diff --git a/JtProject/src/main/webapp/views/test2.jsp b/src/main/webapp/WEB-INF/views/test2.jsp
similarity index 100%
rename from JtProject/src/main/webapp/views/test2.jsp
rename to src/main/webapp/WEB-INF/views/test2.jsp
diff --git a/src/main/webapp/WEB-INF/views/updateProfile.jsp b/src/main/webapp/WEB-INF/views/updateProfile.jsp
new file mode 100644
index 00000000..7a40b67c
--- /dev/null
+++ b/src/main/webapp/WEB-INF/views/updateProfile.jsp
@@ -0,0 +1,174 @@
+
+
+
+
+
+ ${empty pageTitle ? 'Update Profile' : pageTitle} - ShopEase
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
${empty pageTitle ? 'Update Profile' : pageTitle}
+
Keep your account details current. Leave the password field blank if you do not want to change it.
+
+
${msg}
+
+
+
+
+
+
+
+
diff --git a/src/main/webapp/WEB-INF/views/uproduct.jsp b/src/main/webapp/WEB-INF/views/uproduct.jsp
new file mode 100644
index 00000000..2fe469a1
--- /dev/null
+++ b/src/main/webapp/WEB-INF/views/uproduct.jsp
@@ -0,0 +1,214 @@
+<%@page import="java.sql.*"%>
+<%@page import="java.util.*"%>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
+
+
+
+ Products – ShopEase
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ No products available at the moment.
+
+
+
+
+
+
+
+
${product.quantity} in stock
+

+
+
+
${product.category.name}
+
${product.name}
+
${product.description}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/webapp/WEB-INF/views/userLogin.jsp b/src/main/webapp/WEB-INF/views/userLogin.jsp
new file mode 100644
index 00000000..131be72b
--- /dev/null
+++ b/src/main/webapp/WEB-INF/views/userLogin.jsp
@@ -0,0 +1,142 @@
+
+
+
+
+
+ User Login – ShopEase
+
+
+
+
+
+
+
+
+
+
+
+
+
Welcome back
+
Sign in to your account
+
+
+
+
+
+
+
+
diff --git a/src/main/webapp/views/403.jsp b/src/main/webapp/views/403.jsp
new file mode 100644
index 00000000..f5541846
--- /dev/null
+++ b/src/main/webapp/views/403.jsp
@@ -0,0 +1,114 @@
+
+
+
+
+
+ 403 – Access Forbidden | ShopEase
+
+
+
+
+
+
+
+
+
+
+
+
403
+
Access Forbidden
+
You don't have permission to view this page. Please contact your administrator if you believe this is a mistake.
+
+ Go to Homepage
+
+
+
Error code: HTTP 403 Forbidden
+
+
+
+
+
diff --git a/src/main/webapp/views/adminHome.jsp b/src/main/webapp/views/adminHome.jsp
new file mode 100644
index 00000000..d2ec57b5
--- /dev/null
+++ b/src/main/webapp/views/adminHome.jsp
@@ -0,0 +1,198 @@
+
+
+
+
+
+ Admin Dashboard – ShopEase
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Admin Dashboard
+
Manage your ShopEase store from one central place
+
+
+
+
+
+
+
+
+
+
Manage
+
Categories
+
Add, update, or remove product categories available on the store.
+
+ Manage Categories
+
+
+
+
+
+
+
+
Manage
+
Products
+
View, add, update pricing and stock for all available products.
+
+ Manage Products
+
+
+
+
+
+
+
+
Manage
+
Customers
+
View all registered customers and their account details.
+
+ Manage Customers
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/webapp/views/adminlogin.jsp b/src/main/webapp/views/adminlogin.jsp
new file mode 100644
index 00000000..81d024d0
--- /dev/null
+++ b/src/main/webapp/views/adminlogin.jsp
@@ -0,0 +1,165 @@
+
+
+
+
+
+ Admin Login – ShopEase
+
+
+
+
+
+
+
+
+
+
+
+
+
Admin Portal
+
Secure access to ShopEase administration. Authorised personnel only.
+
+
+
+
+
+
+
+
diff --git a/src/main/webapp/views/cartproduct.jsp b/src/main/webapp/views/cartproduct.jsp
new file mode 100644
index 00000000..e7e127c2
--- /dev/null
+++ b/src/main/webapp/views/cartproduct.jsp
@@ -0,0 +1,188 @@
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
+
+
+
+ My Cart – ShopEase
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ | # |
+ Product Name |
+ Price |
+ Description |
+ Action |
+
+
+
+
+
+ | ${item.id} |
+ ${item.name} |
+ $${item.price} |
+ ${item.description} |
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/webapp/views/categories.jsp b/src/main/webapp/views/categories.jsp
new file mode 100644
index 00000000..6fc121f4
--- /dev/null
+++ b/src/main/webapp/views/categories.jsp
@@ -0,0 +1,255 @@
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
+
+
+
+ Categories – ShopEase Admin
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
All Categories
+
+
+
+
+
+
+
+ | ID |
+ Category Name |
+ Actions |
+
+
+
+
+
+ | #${category.id} |
+ ${category.name} |
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/webapp/views/displayCustomers.jsp b/src/main/webapp/views/displayCustomers.jsp
new file mode 100644
index 00000000..131b7b23
--- /dev/null
+++ b/src/main/webapp/views/displayCustomers.jsp
@@ -0,0 +1,149 @@
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
+
+
+
+ Customers – ShopEase Admin
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
All Customers
+
+
+
+
+
+
+ | Avatar |
+ Customer |
+ Email |
+ Address |
+
+
+
+
+
+ |
+
+ ${customer.username.substring(0,1).toUpperCase()}
+
+ |
+
+ ${customer.username}
+ |
+ ${customer.email} |
+ ${customer.address} |
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/webapp/views/index.jsp b/src/main/webapp/views/index.jsp
new file mode 100644
index 00000000..3f72c9eb
--- /dev/null
+++ b/src/main/webapp/views/index.jsp
@@ -0,0 +1,272 @@
+<%@page import="java.util.*"%>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
+
+
+
+ ShopEase – Fresh Perishable Products
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Welcome to ShopEase
+
Discover fresh, premium perishable products at great prices
+
+
+
+
+
+
+
+
+
+
+
No products available
+
Check back soon for fresh arrivals!
+
+
+
+
+
+
+
+
+

+
+
+
${product.category.name}
+
${product.name}
+
${product.description}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/webapp/views/products.jsp b/src/main/webapp/views/products.jsp
new file mode 100644
index 00000000..61fe38ac
--- /dev/null
+++ b/src/main/webapp/views/products.jsp
@@ -0,0 +1,204 @@
+<%@page import="java.util.*"%>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
+
+
+
+ Products – ShopEase Admin
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
All Products
+
+ Add Product
+
+
+
+
+
+
+
+
+ | ID |
+ Preview |
+ Name |
+ Category |
+ Price |
+ Qty |
+ Weight |
+ Description |
+ Actions |
+
+
+
+
+
+ | #${product.id} |
+
+
+
+
+
+
+
+
+
+ |
+ ${product.name} |
+ ${product.category.name} |
+ $${product.price} |
+ ${product.quantity} |
+ ${product.weight}g |
+ ${product.description} |
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/webapp/views/productsAdd.jsp b/src/main/webapp/views/productsAdd.jsp
new file mode 100644
index 00000000..1d2103d6
--- /dev/null
+++ b/src/main/webapp/views/productsAdd.jsp
@@ -0,0 +1,240 @@
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
+
+
+
+ Add Product – ShopEase Admin
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/webapp/views/productsUpdate.jsp b/src/main/webapp/views/productsUpdate.jsp
new file mode 100644
index 00000000..3daf3f0b
--- /dev/null
+++ b/src/main/webapp/views/productsUpdate.jsp
@@ -0,0 +1,230 @@
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
+
+
+
+ Update Product – ShopEase Admin
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/webapp/views/register.jsp b/src/main/webapp/views/register.jsp
new file mode 100644
index 00000000..e027f39b
--- /dev/null
+++ b/src/main/webapp/views/register.jsp
@@ -0,0 +1,138 @@
+
+
+
+
+
+ Register – ShopEase
+
+
+
+
+
+
+
+
+
+
+
+
Create Account
+
Join ShopEase and start shopping fresh products
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/webapp/views/test.jsp b/src/main/webapp/views/test.jsp
new file mode 100644
index 00000000..ba36bc21
--- /dev/null
+++ b/src/main/webapp/views/test.jsp
@@ -0,0 +1,33 @@
+<%@page import="java.sql.*"%>
+<%@page import="java.util.*"%>
+<%@page import="java.text.*"%>
+<%@page import ="java.io.FileOutputStream" %>
+<%@page import=" java.io.ObjectOutputStream" %>
+
+
+
+
+
+ test page
+ <% String s=(String)request.getAttribute("author");
+ Integer id=(Integer)request.getAttribute("id");
+ List friends=(List)request.getAttribute("f");
+ %>
+ author name is <%=s %>
+ Id is <%=id %>
+
+ <%
+ for(String st:friends)
+ {
+ %>
+ <%=st %>
+ <%
+ }
+ %>
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/webapp/views/test2.jsp b/src/main/webapp/views/test2.jsp
new file mode 100644
index 00000000..c5f40baf
--- /dev/null
+++ b/src/main/webapp/views/test2.jsp
@@ -0,0 +1,37 @@
+
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
+
+
+
+ test page
+
+ <%
+ //String name=(String)request.getAttribute("name");
+ //Integer id= (Integer)request.getAttribute("id");
+
+ %>
+
+ Name: ${name}, id= ${id}
+
+
+
+
+
+ ${item }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/webapp/views/updateProfile.jsp b/src/main/webapp/views/updateProfile.jsp
new file mode 100644
index 00000000..7b86b193
--- /dev/null
+++ b/src/main/webapp/views/updateProfile.jsp
@@ -0,0 +1,108 @@
+
+
+
+
+
+ Update Profile – ShopEase
+
+
+
+
+
+
+
+
+
+
+
User Profile
+
Update your personal information below
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/webapp/views/uproduct.jsp b/src/main/webapp/views/uproduct.jsp
new file mode 100644
index 00000000..a9e06ecf
--- /dev/null
+++ b/src/main/webapp/views/uproduct.jsp
@@ -0,0 +1,179 @@
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
+
+
+
+ Browse Products – ShopEase
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
${product.category.name}
+
${product.name}
+
+ ${product.quantity} in stock
+ · ${product.weight}g
+
+
${product.description}
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/webapp/views/userLogin.jsp b/src/main/webapp/views/userLogin.jsp
new file mode 100644
index 00000000..d7319564
--- /dev/null
+++ b/src/main/webapp/views/userLogin.jsp
@@ -0,0 +1,168 @@
+
+
+
+
+
+ User Login – ShopEase
+
+
+
+
+
+
+
+
+
+
+
+
+
+
ShopEase
+
Your one-stop destination for fresh perishable products, delivered with care.
+
+
+
+
+
+
+
+
+
diff --git a/JtProject/src/test/java/com/jtspringproject/JtSpringProject/JtSpringProjectApplicationTests.java b/src/test/java/com/jtspringproject/JtSpringProject/JtSpringProjectApplicationTests.java
similarity index 100%
rename from JtProject/src/test/java/com/jtspringproject/JtSpringProject/JtSpringProjectApplicationTests.java
rename to src/test/java/com/jtspringproject/JtSpringProject/JtSpringProjectApplicationTests.java
diff --git a/JtProject/src/test/java/com/jtspringproject/JtSpringProject/models/CartProductIdTest.java b/src/test/java/com/jtspringproject/JtSpringProject/models/CartProductIdTest.java
similarity index 100%
rename from JtProject/src/test/java/com/jtspringproject/JtSpringProject/models/CartProductIdTest.java
rename to src/test/java/com/jtspringproject/JtSpringProject/models/CartProductIdTest.java
diff --git a/JtProject/src/test/java/com/jtspringproject/JtSpringProject/models/CartProductTest.java b/src/test/java/com/jtspringproject/JtSpringProject/models/CartProductTest.java
similarity index 100%
rename from JtProject/src/test/java/com/jtspringproject/JtSpringProject/models/CartProductTest.java
rename to src/test/java/com/jtspringproject/JtSpringProject/models/CartProductTest.java
diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties
new file mode 100644
index 00000000..01d99329
--- /dev/null
+++ b/src/test/resources/application.properties
@@ -0,0 +1,8 @@
+spring.datasource.url=jdbc:h2:mem:testdb;MODE=MySQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
+spring.datasource.driver-class-name=org.h2.Driver
+spring.datasource.username=sa
+spring.datasource.password=
+spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
+spring.jpa.hibernate.ddl-auto=create-drop
+spring.flyway.enabled=false
+