Giter Club home page Giter Club logo

jaygajera17 / e-commerce-project-springboot Goto Github PK

View Code? Open in Web Editor NEW
441.0 6.0 426.0 16.87 MB

This a web application Java Based Beginner level project To developing the e-commerce website to Buy/sell the Food Item. We use the Spring Boot to build the back-end part

Home Page: https://www.youtube.com/watch?v=c6WWdINWSlI&feature=youtu.be

Java 100.00%
eclipse jdbc spring spring-boot spring-boot-project spring-mvc spring-projects e-commerce-project-in-java spring-web-project java

e-commerce-project-springboot's Introduction

Old Version

New Upgrade ( 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.
  3. Make sure you are in the JtProject directory
  4. Configure the database connection in application.properties file (check the 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.sqlscript 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 application.properties file, with the appropriate values for the following properties: (you'd better use another username not root)

    db.url=jdbc:mysql://[ip address of db]:[port of db]/ecommjava?createDatabaseIfNotExist=true
    db.username=[username]
    db.password=[password, if any]

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.

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.

Web Directories

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:

  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"

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)! configurations

Workflow

  • image

Controller

  • control the endpoint and also send data to view( we use ModelAndView method)
  •   public String adminlogin() {
      	
      	return "adminlogin";
      }```
    
  • whenever /login url is hit , src->main->webapp-> adminlogin.jsp file execute

Models

  • represent data as entity and relationship among them.

View

  • receive data from controller and show with frontend.

Endpoints

Spring Boot

For any information about Spring Boot, here are some useful links!

Reference Documentation

For further reference, please consider the following sections:

Guides

The following guides illustrate how to use some features concretely:

Preview

image image image

Link

  • π—¬π—Όπ˜‚π˜π˜‚π—―π—² π—½π—Ώπ—Όπ—·π—²π—°π˜ π˜ƒπ—Άπ—±π—²π—Ό π—ͺ𝗼𝗿𝗸𝗢𝗻𝗴 𝗗𝗲𝗺𝗼 + π˜€π˜π—²π—½ π—―π˜† π˜€π˜π—²π—½ π—²π˜…π—²π—°π˜‚π˜π—Άπ—Όπ—» 𝗹𝗢𝗻𝗸 ( old version )::--- click here youtube

e-commerce-project-springboot's People

Contributors

augustdg avatar dakshay111 avatar jaygajera17 avatar kliu57 avatar pixeebot[bot] avatar wanggithub0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

e-commerce-project-springboot's Issues

XSS in username

XSS exists in username field. For PoC set username to:

<script>alert()</script>

register met error "Duplicate entry '1' for key 'customer.PRIMARY'

Caused by: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '1' for key 'customer.PRIMARY'
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:118)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:916)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1061)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1009)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1320)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:994)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:197)

Error message not displaying when customer/admin login fails

Steps to reproduce this issue:

  1. Start the server and go to the user registration page http://localhost:8080/.

  2. Enter non-existing username and password and click Login.

image

  1. An error is thrown. We expect to see the Log in page with an nicely formatted error message for the user.

image


Similar issue for admin log in. For example, go to a page that requires admin access such as customers page http://localhost:8080/admin/customers

image

image

Reason this is a problem:

There is existing code for showing error messages. This is a bug that can be fixed.

Proposed fix:

Fix the areas in the code that is causing the bug and have the predefined error messages display successfully on the Log in page for both customer log in and admin log in.

Application run failed

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-09-07 10:23:43.955 ERROR 16316 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'adminController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userService': Unsatisfied dependency expressed through field 'userDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDao': Unsatisfied dependency expressed through field 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/jtspringproject/JtSpringProject/HibernateConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:659) ~[spring-beans-5.3.16.jar:5.3.16]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639) ~[spring-beans-5.3.16.jar:5.3.16]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.3.16.jar:5.3.16]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.3.16.jar:5.3.16]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431) ~[spring-beans-5.3.16.jar:5.3.16]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619) ~[spring-beans-5.3.16.jar:5.3.16]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.16.jar:5.3.16]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.16.jar:5.3.16]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.16.jar:5.3.16]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.16.jar:5.3.16]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.16.jar:5.3.16]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[spring-beans-5.3.16.jar:5.3.16]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.16.jar:5.3.16]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.16.jar:5.3.16]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.6.4.jar:2.6.4]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740) ~[spring-boot-2.6.4.jar:2.6.4]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415) ~[spring-boot-2.6.4.jar:2.6.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-2.6.4.jar:2.6.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) ~[spring-boot-2.6.4.jar:2.6.4]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) ~[spring-boot-2.6.4.jar:2.6.4]
at com.jtspringproject.JtSpringProject.JtSpringProjectApplication.main(JtSpringProjectApplication.java:11) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]

No validation for duplicate username during registration

Steps to reproduce this issue:

  1. Start the server and go to the user registration page http://localhost:8080/register

  2. Enter valid data and a non-existing username and click Register. Check the database to make sure the new user appears as a new row in the customer table.
    screenshot1

  3. Go back to the registration page and enter the same details again. Check the database and the new duplicate user is created.

screenshot2

Reason this is a problem:

Customers should not be allowed to register with an existing username.
customers table username column should have a unique constraint to not allow duplicate usernames.

Proposed fix:

  1. Change the basedata.sql script to have a UNIQUE constraint on the username column of the customers table.

In models/User, define a unique constraint on the username field with @Column(unique = true)

  1. Change the source code to check if a username is an existing username or not. If it is existing, display an error message on the page. If it is not existing, create the user and redirect the user to the login page.

Add CartProduct class

In mysql database, there is a table named CART_PRODUCT and CART table has [id, customer_id], so need to revise models in project.

image

Redesign applying the Composite pattern

Proposal:
It is proposed to implement the Composite pattern to hierarchically structure entities such as products, categories, and shopping carts in the project. A common interface will be created to allow clients to interact uniformly with individual products and categories, facilitating standard operations like adding, removing, and retrieving information. The introduction of the Composite pattern aims to simplify the manipulation of the product and category structure consistently, promoting code reusability, and facilitating the system's expansion into future functionalities.

Consequences:
β€’ Uniform Interaction: The implementation of the Composite pattern will provide a consistent interface for products and categories, allowing consistent operations and simplifying client interaction.
β€’ Flexibility and Extensibility: By treating products and categories uniformly, the system's flexibility to build complex structures is enhanced. Additionally, adopting the Composite pattern facilitates the introduction of new functionalities without substantial modifications to existing code.
β€’ Code Simplification and Coherence: The Composite pattern centralizes common operations in a shared interface, simplifying the code and increasing coherence in the manipulation of products and categories. This results in more maintainable and easily understandable code.

Solution in UML:
image

buy product

after click on submit button nothing will happen

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.