├── .gitignore ├── .mvn └── wrapper │ ├── MavenWrapperDownloader.java │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── Dockerfile ├── README.md ├── Report ├── .DS_Store ├── Architecture │ └── Architecture.001.png └── Untitled.key ├── data.csv ├── data.json ├── data2.csv ├── docker-compose.yml ├── female-data.json ├── frontend ├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public │ ├── favicon.ico │ ├── index.html │ ├── logo192.png │ ├── logo512.png │ ├── manifest.json │ └── robots.txt └── src │ ├── App.css │ ├── App.js │ ├── App.test.js │ ├── Components │ ├── AppBar.js │ ├── DressShow.js │ └── PrivateRoute.js │ ├── Pages │ ├── CartScreen.js │ ├── Products.js │ ├── Register.js │ ├── home.js │ └── login.js │ ├── Service │ └── AuthenticationService.js │ ├── assets │ ├── logo.png │ └── logof.png │ ├── context.js │ ├── data.js │ ├── index.css │ ├── index.js │ ├── logo.svg │ ├── reportWebVitals.js │ ├── scrapeHM.js │ └── setupTests.js ├── logof.png ├── men-data.json ├── mvnw ├── mvnw.cmd ├── pom.xml ├── src ├── main │ ├── java │ │ └── com │ │ │ └── flamup │ │ │ └── spring │ │ │ ├── Application.java │ │ │ ├── Controllers │ │ │ ├── AuthController.java │ │ │ ├── CartServiceController.java │ │ │ ├── ProductController.java │ │ │ ├── RegistrationController.java │ │ │ ├── SessionController.java │ │ │ └── TestGetController.java │ │ │ ├── DTO │ │ │ ├── OrderDTO.java │ │ │ └── UpdateOrderDTO.java │ │ │ ├── Models │ │ │ ├── AppUserRole.java │ │ │ ├── ApplicationUser.java │ │ │ ├── OrderItem.java │ │ │ ├── Product.java │ │ │ ├── RegistrationRequest.java │ │ │ └── ShoppingCart.java │ │ │ ├── Repositories │ │ │ ├── ApplicationUserRepository.java │ │ │ ├── CartRepository.java │ │ │ ├── OrderRepository.java │ │ │ └── ProductRepository.java │ │ │ ├── Services │ │ │ ├── CartService.java │ │ │ ├── CustomLogoutHandler.java │ │ │ ├── ProductService.java │ │ │ └── RegistrationService.java │ │ │ ├── auth │ │ │ └── AppUserService.java │ │ │ └── security │ │ │ ├── PasswordEncoder.java │ │ │ ├── RestAuthEntryPoint.java │ │ │ ├── SwaggerConfig.java │ │ │ └── WebSecurityConfig.java │ └── resources │ │ ├── application.properties │ │ ├── application.yml │ │ ├── data-postgres.sql │ │ └── spring.jks └── test │ └── java │ └── com │ └── flamup │ └── spring │ └── ApplicationTests.java └── work.py /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | node_modules/ 4 | build/ 5 | !.mvn/wrapper/maven-wrapper.jar 6 | !**/src/main/**/target/ 7 | !**/src/test/**/target/ 8 | 9 | .DS_Store 10 | 11 | ### STS ### 12 | .apt_generated 13 | .classpath 14 | .factorypath 15 | .project 16 | .settings 17 | .springBeans 18 | .sts4-cache 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | 26 | ### NetBeans ### 27 | /nbproject/private/ 28 | /nbbuild/ 29 | /dist/ 30 | /nbdist/ 31 | /.nb-gradle/ 32 | build/ 33 | !**/src/main/**/build/ 34 | !**/src/test/**/build/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2007-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import java.net.*; 18 | import java.io.*; 19 | import java.nio.channels.*; 20 | import java.util.Properties; 21 | 22 | public class MavenWrapperDownloader { 23 | 24 | private static final String WRAPPER_VERSION = "0.5.6"; 25 | /** 26 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 27 | */ 28 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" 29 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; 30 | 31 | /** 32 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 33 | * use instead of the default one. 34 | */ 35 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 36 | ".mvn/wrapper/maven-wrapper.properties"; 37 | 38 | /** 39 | * Path where the maven-wrapper.jar will be saved to. 40 | */ 41 | private static final String MAVEN_WRAPPER_JAR_PATH = 42 | ".mvn/wrapper/maven-wrapper.jar"; 43 | 44 | /** 45 | * Name of the property which should be used to override the default download url for the wrapper. 46 | */ 47 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 48 | 49 | public static void main(String args[]) { 50 | System.out.println("- Downloader started"); 51 | File baseDirectory = new File(args[0]); 52 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 53 | 54 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 55 | // wrapperUrl parameter. 56 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 57 | String url = DEFAULT_DOWNLOAD_URL; 58 | if (mavenWrapperPropertyFile.exists()) { 59 | FileInputStream mavenWrapperPropertyFileInputStream = null; 60 | try { 61 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 62 | Properties mavenWrapperProperties = new Properties(); 63 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 64 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 65 | } catch (IOException e) { 66 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 67 | } finally { 68 | try { 69 | if (mavenWrapperPropertyFileInputStream != null) { 70 | mavenWrapperPropertyFileInputStream.close(); 71 | } 72 | } catch (IOException e) { 73 | // Ignore ... 74 | } 75 | } 76 | } 77 | System.out.println("- Downloading from: " + url); 78 | 79 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 80 | if (!outputFile.getParentFile().exists()) { 81 | if (!outputFile.getParentFile().mkdirs()) { 82 | System.out.println( 83 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 84 | } 85 | } 86 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 87 | try { 88 | downloadFileFromURL(url, outputFile); 89 | System.out.println("Done"); 90 | System.exit(0); 91 | } catch (Throwable e) { 92 | System.out.println("- Error downloading"); 93 | e.printStackTrace(); 94 | System.exit(1); 95 | } 96 | } 97 | 98 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 99 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { 100 | String username = System.getenv("MVNW_USERNAME"); 101 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); 102 | Authenticator.setDefault(new Authenticator() { 103 | @Override 104 | protected PasswordAuthentication getPasswordAuthentication() { 105 | return new PasswordAuthentication(username, password); 106 | } 107 | }); 108 | } 109 | URL website = new URL(urlString); 110 | ReadableByteChannel rbc; 111 | rbc = Channels.newChannel(website.openStream()); 112 | FileOutputStream fos = new FileOutputStream(destination); 113 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 114 | fos.close(); 115 | rbc.close(); 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheSYNcoder/Full-Stack-Ecommerce-Spring-Boot-React/dc42b58c3534759276621c7c9d3923e3961e8697/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar 3 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | #FROM maven:3.6.0-jdk-11-slim AS build 2 | FROM maven:3.6.1-jdk-8-slim AS build 3 | RUN mkdir -p workspace 4 | WORKDIR workspace 5 | COPY pom.xml /workspace 6 | COPY src /workspace/src 7 | COPY frontend /workspace/frontend 8 | COPY data2.csv /workspace 9 | RUN mvn -f pom.xml clean install -DskipTests=true 10 | ##RUN ./mvnw clean package -DskipTests 11 | # 12 | ##FROM adoptopenjdk/openjdk11:alpine-jre 13 | FROM openjdk:16-ea-29-oraclelinux8 14 | COPY --from=build /workspace/target/*.jar app.jar 15 | #EXPOSE 8080 16 | #ENTRYPOINT ["java","-jar","app.jar"] 17 | 18 | 19 | #FROM adoptopenjdk/openjdk11:alpine-jre 20 | 21 | #COPY target/*.jar app.jar 22 | EXPOSE 8080 23 | ENTRYPOINT ["java","-jar","app.jar"] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Spring-Boot-React 2 | 3 | 4 |

5 | 6 |

7 | 8 | This is a full stack web application made with spring boot and ReactJs in the frontend. Relevant blog articles on this are 9 | 10 | * [Spring Boot and Docker Setup](https://medium.com/geekculture/a-full-stack-e-commerce-application-using-spring-boot-and-making-a-docker-container-eff46f6f4e14) 11 | * [Integrating ReactJs with the backend](https://medium.com/geekculture/a-reactjs-web-application-with-a-spring-boot-backend-and-containerizing-it-using-docker-3eeaed8cb45a) 12 | 13 | ## Setting up Locally 14 | 15 | * Install [docker](https://www.docker.com) and docker-compose on your system. 16 | * Install `psql` for your system which is a client for the Postgresql database. 17 | * Go the root directory of the system 18 | * Run `docker-compose up --build` 19 | * After the containers are up and running , run `psql -h 127.0.0.1 -d flamup -p 5432 -U postgres -c "\copy clothes FROM 'data2.csv' DELIMITER ',' CSV";`. 20 | 21 | Now continue to https://localhost:8443, the application should be up and running. 22 | 23 | ### Caveats 24 | 25 | * In case you are using chrome, go to chrome://flags/#allow-insecure-localhost and Enable the option that says "Allow invalid certificates for resources loaded from localhost". 26 | 27 | -------------------------------------------------------------------------------- /Report/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheSYNcoder/Full-Stack-Ecommerce-Spring-Boot-React/dc42b58c3534759276621c7c9d3923e3961e8697/Report/.DS_Store -------------------------------------------------------------------------------- /Report/Architecture/Architecture.001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheSYNcoder/Full-Stack-Ecommerce-Spring-Boot-React/dc42b58c3534759276621c7c9d3923e3961e8697/Report/Architecture/Architecture.001.png -------------------------------------------------------------------------------- /Report/Untitled.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheSYNcoder/Full-Stack-Ecommerce-Spring-Boot-React/dc42b58c3534759276621c7c9d3923e3961e8697/Report/Untitled.key -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | 5 | db: 6 | image: "postgres:9.6-alpine" 7 | container_name: db 8 | restart: always 9 | 10 | ports: 11 | - 5432:5432 12 | 13 | # volumes: 14 | # - postgres_data:/var/lib/postgresql/data 15 | 16 | environment: 17 | - POSTGRES_DB=flamup 18 | - POSTGRES_USER=postgres 19 | - POSTGRES_PASSWORD=postgres 20 | - PGDATA=/var/lib/postgresql/data/pgdata 21 | 22 | 23 | flamup: 24 | build: ./ 25 | # image: "thesyncoder/flamup:0.0.2" 26 | container_name: flamup 27 | environment: 28 | - DB_SERVER:db 29 | - POSTGRES_DB=flamup 30 | - POSTGRES_USER=postgres 31 | - POSTGRES_PASSWORD=postgres 32 | ports: 33 | - 8443:8443 # Forward the exposed port 8080 on the container to port 8080 on the host machine 34 | 35 | depends_on: 36 | - db 37 | 38 | 39 | 40 | volumes: 41 | postgres_data: 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /frontend/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@material-ui/core": "^4.11.3", 7 | "@material-ui/icons": "^4.11.2", 8 | "@material-ui/lab": "^4.0.0-alpha.57", 9 | "@testing-library/jest-dom": "^5.11.10", 10 | "@testing-library/react": "^11.2.6", 11 | "@testing-library/user-event": "^12.8.3", 12 | "axios": "^0.21.1", 13 | "react": "^17.0.2", 14 | "react-dom": "^17.0.2", 15 | "react-router-dom": "^5.2.0", 16 | "react-scripts": "4.0.3", 17 | "web-vitals": "^1.1.1" 18 | }, 19 | "scripts": { 20 | "start": "react-scripts start", 21 | "build": "react-scripts build", 22 | "test": "react-scripts test", 23 | "eject": "react-scripts eject" 24 | }, 25 | "eslintConfig": { 26 | "extends": [ 27 | "react-app", 28 | "react-app/jest" 29 | ] 30 | }, 31 | "browserslist": { 32 | "production": [ 33 | ">0.2%", 34 | "not dead", 35 | "not op_mini all" 36 | ], 37 | "development": [ 38 | "last 1 chrome version", 39 | "last 1 firefox version", 40 | "last 1 safari version" 41 | ] 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /frontend/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheSYNcoder/Full-Stack-Ecommerce-Spring-Boot-React/dc42b58c3534759276621c7c9d3923e3961e8697/frontend/public/favicon.ico -------------------------------------------------------------------------------- /frontend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 19 | 20 | 29 | React App 30 | 31 | 32 | 33 |
34 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /frontend/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheSYNcoder/Full-Stack-Ecommerce-Spring-Boot-React/dc42b58c3534759276621c7c9d3923e3961e8697/frontend/public/logo192.png -------------------------------------------------------------------------------- /frontend/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheSYNcoder/Full-Stack-Ecommerce-Spring-Boot-React/dc42b58c3534759276621c7c9d3923e3961e8697/frontend/public/logo512.png -------------------------------------------------------------------------------- /frontend/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /frontend/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /frontend/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /frontend/src/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import {BrowserRouter, Switch, Route } from "react-router-dom"; 3 | import Login from "./Pages/login"; 4 | import Home from "./Pages/home"; 5 | import Register from "./Pages/Register"; 6 | import Products from "./Pages/Products"; 7 | import PrivateRoute from "./Components/PrivateRoute"; 8 | import CartScreen from "./Pages/CartScreen"; 9 | import './App.css'; 10 | import AuthContext from "./context"; 11 | // var AuthService = require("./Service/AuthenticationService"); 12 | import AuthService from "./Service/AuthenticationService"; 13 | 14 | 15 | 16 | function App() { 17 | 18 | 19 | const [ auth , setAuth ] = React.useState( false); 20 | const [user, setUser ] = React.useState(null); 21 | 22 | React.useEffect(() => { 23 | AuthService(setUser, setAuth); 24 | },[]); 25 | React.useEffect(() => { 26 | AuthService(setUser, setAuth); 27 | },[auth]); 28 | 29 | 30 | 31 | return ( 32 | 33 | 34 | 35 | } /> 36 | } /> 37 | } /> 38 | 39 | 40 | 41 | 42 | 43 | ); 44 | } 45 | 46 | export default App; 47 | -------------------------------------------------------------------------------- /frontend/src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /frontend/src/Components/AppBar.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { fade, makeStyles } from '@material-ui/core/styles'; 3 | import AppBar from '@material-ui/core/AppBar'; 4 | import Toolbar from '@material-ui/core/Toolbar'; 5 | import IconButton from '@material-ui/core/IconButton'; 6 | import Typography from '@material-ui/core/Typography'; 7 | import InputBase from '@material-ui/core/InputBase'; 8 | import Badge from '@material-ui/core/Badge'; 9 | import MenuItem from '@material-ui/core/MenuItem'; 10 | import Menu from '@material-ui/core/Menu'; 11 | import MenuIcon from '@material-ui/icons/Menu'; 12 | import SearchIcon from '@material-ui/icons/Search'; 13 | import AccountCircle from '@material-ui/icons/AccountCircle'; 14 | import MailIcon from '@material-ui/icons/Mail'; 15 | import { ShoppingCart, Input } from '@material-ui/icons'; 16 | import MoreIcon from '@material-ui/icons/MoreVert'; 17 | import AuthContext from "../context"; 18 | import Logof from "../assets/logof.png"; 19 | import { withRouter } from 'react-router'; 20 | 21 | 22 | import axios from 'axios'; 23 | 24 | const useStyles = makeStyles((theme) => ({ 25 | grow: { 26 | flexGrow: 1, 27 | }, 28 | menuButton: { 29 | marginRight: theme.spacing(2), 30 | }, 31 | title: { 32 | display: 'none', 33 | [theme.breakpoints.up('sm')]: { 34 | display: 'block', 35 | }, 36 | }, 37 | search: { 38 | position: 'relative', 39 | borderRadius: theme.shape.borderRadius, 40 | backgroundColor: 'rgba(255,255,255,0.6)', 41 | '&:hover': { 42 | backgroundColor: 'rgba(255,255,255,0.8)', 43 | }, 44 | marginRight: theme.spacing(2), 45 | marginLeft: 0, 46 | width: '100%', 47 | [theme.breakpoints.up('sm')]: { 48 | marginLeft: theme.spacing(3), 49 | width: 'auto', 50 | }, 51 | }, 52 | searchIcon: { 53 | padding: theme.spacing(0, 2), 54 | height: '100%', 55 | position: 'absolute', 56 | pointerEvents: 'none', 57 | display: 'flex', 58 | alignItems: 'center', 59 | justifyContent: 'center', 60 | }, 61 | inputRoot: { 62 | color: 'white', 63 | }, 64 | inputInput: { 65 | padding: theme.spacing(1, 1, 1, 0), 66 | // vertical padding + font size from searchIcon 67 | paddingLeft: `calc(1em + ${theme.spacing(4)}px)`, 68 | transition: theme.transitions.create('width'), 69 | width: '100%', 70 | [theme.breakpoints.up('md')]: { 71 | width: '20ch', 72 | }, 73 | }, 74 | sectionDesktop: { 75 | display: 'none', 76 | [theme.breakpoints.up('md')]: { 77 | display: 'flex', 78 | }, 79 | }, 80 | sectionMobile: { 81 | display: 'flex', 82 | [theme.breakpoints.up('md')]: { 83 | display: 'none', 84 | }, 85 | }, 86 | })); 87 | 88 | function PrimarySearchAppBar(props) { 89 | const classes = useStyles(); 90 | 91 | const { auth, setAuth } = React.useContext( AuthContext ); 92 | const [anchorEl, setAnchorEl] = React.useState(null); 93 | const [mobileMoreAnchorEl, setMobileMoreAnchorEl] = React.useState(null); 94 | 95 | const isMenuOpen = Boolean(anchorEl); 96 | const isMobileMenuOpen = Boolean(mobileMoreAnchorEl); 97 | 98 | const handleProfileMenuOpen = (event) => { 99 | setAnchorEl(event.currentTarget); 100 | }; 101 | 102 | const handleMobileMenuClose = () => { 103 | setMobileMoreAnchorEl(null); 104 | }; 105 | 106 | const handleMenuClose = () => { 107 | setAnchorEl(null); 108 | handleMobileMenuClose(); 109 | }; 110 | 111 | const handleMobileMenuOpen = (event) => { 112 | setMobileMoreAnchorEl(event.currentTarget); 113 | }; 114 | 115 | const menuId = 'primary-search-account-menu'; 116 | const renderMenu = ( 117 | 126 | Profile 127 | My account 128 | 129 | ); 130 | 131 | const mobileMenuId = 'primary-search-account-menu-mobile'; 132 | const renderMobileMenu = ( 133 | 142 | 143 | 144 | props.history.push('/cart')} 145 | aria-label="show 11 new notifications" color="inherit" > 146 | 147 | 148 | 149 | 150 |

Shopping Cart

151 |
152 | 153 | 159 | 160 | 161 |

Profile

162 |
163 |
164 | ); 165 | 166 | 167 | 168 | 169 | 170 | return ( 171 |
172 | 173 | 174 | props.history.push("/")} 180 | > 181 | 182 | 183 | 184 | FlamUp 185 | 186 | {/*
187 |
188 | 189 |
190 | 198 |
*/} 199 |
200 |
201 | 202 | props.history.push('/cart')} 203 | color="inherit"> 204 | 205 | 206 | 207 | 208 | 216 | 217 | 218 |
219 |
220 | 227 | 228 | 229 |
230 | 231 | 232 | {renderMobileMenu} 233 | {renderMenu} 234 |
235 | ); 236 | } 237 | 238 | export default withRouter(PrimarySearchAppBar); -------------------------------------------------------------------------------- /frontend/src/Components/DressShow.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { fade, makeStyles } from '@material-ui/core/styles'; 3 | import { Grid, Typography,Paper, Button, IconButton } from "@material-ui/core"; 4 | 5 | 6 | 7 | 8 | const useStyles = makeStyles((theme) => ({ 9 | image: { 10 | borderRadius: "20px", 11 | maxHeight : "400px", 12 | maxWidth :"500px", 13 | }, 14 | paper :{ 15 | margin :"1em", 16 | width :"auto", 17 | borderRadius: "20px", 18 | }, 19 | 20 | })) 21 | 22 | const DressCard = ({dress}) => { 23 | 24 | 25 | 26 | const classes = useStyles(); 27 | 28 | return ( 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | {dress.b_dresstype} 37 | 38 | {dress.e_arrival.toLowerCase() === "new" ? 39 | 40 | New Arrival 41 | 42 | : 43 | } 44 | { 45 | dress.e_arrival.toLowerCase() === "old" ? 46 | 47 | Price : 48 | 49 | ₹ {dress.d_price} 50 | {' '} {dress.f_discount} 51 | 52 | : ₹ {dress.d_price} 53 | } 54 | 55 | 56 |
57 | ) 58 | } 59 | 60 | export default DressCard; -------------------------------------------------------------------------------- /frontend/src/Components/PrivateRoute.js: -------------------------------------------------------------------------------- 1 | import { Redirect, Route } from 'react-router-dom'; 2 | 3 | function PrivateRoute({component : Component , authed, ...rest}){ 4 | return ( 5 | authed === true ? 8 | 9 | : 13 | } 14 | /> 15 | ) 16 | } 17 | 18 | export default PrivateRoute; -------------------------------------------------------------------------------- /frontend/src/Pages/CartScreen.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { makeStyles } from '@material-ui/core/styles'; 3 | import Table from '@material-ui/core/Table'; 4 | import TableBody from '@material-ui/core/TableBody'; 5 | import TableCell from '@material-ui/core/TableCell'; 6 | import TableContainer from '@material-ui/core/TableContainer'; 7 | import TableHead from '@material-ui/core/TableHead'; 8 | import TableRow from '@material-ui/core/TableRow'; 9 | import Paper from '@material-ui/core/Paper'; 10 | import Appbar from "../Components/AppBar"; 11 | import Grid from "@material-ui/core/Grid"; 12 | 13 | import axios from 'axios'; 14 | import { Button, ButtonGroup, Container, TableFooter, Typography, IconButton } from "@material-ui/core"; 15 | import { Delete, RateReview } from '@material-ui/icons'; 16 | import { withRouter } from "react-router"; 17 | 18 | const useStyles = makeStyles({ 19 | table: { 20 | minWidth: 650, 21 | marginTop :"3em" 22 | }, 23 | }); 24 | 25 | 26 | 27 | function BasicTable() { 28 | const classes = useStyles(); 29 | 30 | const ORDER_URL ='/api/v1/orders' 31 | const PUT_URL = '/api/v1/order/' 32 | const [ total , setTotal] = React.useState(0); 33 | const [products, setProducts ]= React.useState([]); 34 | 35 | React.useEffect(() => { 36 | axios.get(ORDER_URL) 37 | .then(response => { 38 | if ( response.status === 200){ 39 | setTotal(response.data.total); 40 | setProducts(response.data.products); 41 | } 42 | }) 43 | }, []); 44 | 45 | 46 | React.useEffect(() => { 47 | axios.get(ORDER_URL) 48 | .then(response => { 49 | if (response.status === 200) { 50 | setTotal(response.data.total); 51 | setProducts(response.data.products); 52 | } 53 | }) 54 | }, [products]); 55 | 56 | 57 | const putRequest =(id, quantity) => { 58 | const payload ={ 59 | id: id, 60 | quantity : quantity 61 | } 62 | axios.put(PUT_URL, payload) 63 | .then( response => console.log(response)) 64 | .catch(err => console.log(err)); 65 | } 66 | 67 | const handleInc = (i , id ) => { 68 | var pro = products; 69 | var quantity = pro[i].quantity; 70 | pro[i].quantity = pro[i].quantity +1; 71 | setProducts(pro); 72 | putRequest( id, quantity +1); 73 | 74 | } 75 | const handleDec = (i , id ) => { 76 | var pro = products; 77 | var quantity = pro[i].quantity; 78 | pro[i].quantity = pro[i].quantity - 1; 79 | setProducts(pro); 80 | putRequest( id, quantity -1); 81 | 82 | } 83 | 84 | const handleDelete = ( i ,id ) => { 85 | var pro = products; 86 | pro = [...products.slice(0, i) , ...products.splice(i+1 )]; 87 | setProducts( pro ); 88 | axios.delete( PUT_URL + id) 89 | .then( response => console.log(response)); 90 | } 91 | 92 | 93 | 94 | 95 | 96 | return ( 97 |
98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | Product name 106 | Quantity 107 | Price 108 | . 109 | . 110 | 111 | 112 | 113 | {products && products.map((row,i) => { 114 | const display = row.quantity <= 0; 115 | return ( 116 | 117 | 118 | {row.product.b_dresstype} 119 | 120 | {row.quantity} 121 | {row.product.e_arrival.toLowerCase() === 'old' ? 122 | 'Rs.' + row.product.f_discount : row.product.d_price } 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | handleDelete(i , row.id) }> 132 | 133 | 134 | 135 | 136 | 137 | ) 138 | } 139 | ) 140 | } 141 | 142 | 143 | Total Price : Rs.{total} 144 | 145 |
146 |
147 | 148 |
149 |
150 |
151 | ); 152 | } 153 | 154 | export default withRouter(BasicTable); -------------------------------------------------------------------------------- /frontend/src/Pages/Products.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { fade, makeStyles } from '@material-ui/core/styles'; 3 | import Appbar from "../Components/AppBar"; 4 | 5 | import { Typography , Grid, Button, TextField , IconButton} from "@material-ui/core"; 6 | import data from "../data"; 7 | import DressCard from "../Components/DressShow"; 8 | import { Search } from "@material-ui/icons"; 9 | import axios from 'axios'; 10 | import AuthContext from "../context"; 11 | import { withRouter } from 'react-router'; 12 | import { Favorite, ShoppingCart } from '@material-ui/icons'; 13 | import Modal from '@material-ui/core/Modal'; 14 | 15 | 16 | const useStyles = makeStyles( (theme) => ({ 17 | heading:{ 18 | fontFamily:"Lobster,cursive", 19 | color:"#fc30d0", 20 | 21 | }, 22 | image :{ 23 | borderRadius:"40px" 24 | }, 25 | end:{ 26 | display : "flex", 27 | justifyContent:"flex-end", 28 | }, 29 | searchItem :{ 30 | padding :"1em", 31 | backgroundColor :"rgb(255,0,0,0.2)", 32 | borderRadius :"50px", 33 | margin:"0.5em" 34 | }, 35 | modal: { 36 | display: 'flex', 37 | alignItems: 'center', 38 | justifyContent: 'center', 39 | }, 40 | mimage: { 41 | height: "300px", 42 | width: "250px", 43 | borderRadius: "40px", 44 | 45 | } 46 | })) 47 | 48 | 49 | const Products = () => { 50 | 51 | 52 | const classes = useStyles(); 53 | 54 | const { user, auth } = React.useContext(AuthContext); 55 | 56 | const [PRODUCTS_BY_SEX_PAGINATION_URL, setURL] = React.useState(`/api/v1/clothes/?sex=${user.gender}&page=`); 57 | const PRODUCTS_BY_SEARCH_URL = '/api/v1/dresses/?dress='; 58 | const ORDER_URL = '/api/v1/orders' 59 | 60 | const [ posts, setPosts ] = React.useState([]); 61 | 62 | 63 | 64 | const [total, setTotal] = React.useState( 0); 65 | const [current, setCurrent ] = React.useState(0); 66 | const [products, setProducts ] = React.useState([]); 67 | 68 | 69 | React.useEffect(() => { 70 | axios.get(PRODUCTS_BY_SEX_PAGINATION_URL+current ) 71 | .then( response => { 72 | console.log(response); 73 | setCurrent( current + 1 ); 74 | setTotal( response.data.total); 75 | setPosts(response.data.products); 76 | }) 77 | .catch(err => console.log(err)); 78 | 79 | axios.get(ORDER_URL) 80 | .then(response => { 81 | if (response.status === 200) { 82 | setProducts(response.data.products); 83 | } 84 | }) 85 | .catch(err => console.log(err)); 86 | }, []); 87 | 88 | const handleShowMorePosts = () => { 89 | axios.get(PRODUCTS_BY_SEX_PAGINATION_URL + current) 90 | .then( response => { 91 | setCurrent( current + 1 ); 92 | setTotal( response.data.total); 93 | setPosts([...posts, ...response.data.products]); 94 | }) 95 | }; 96 | 97 | 98 | const [ search, setSearch ] = React.useState(''); 99 | 100 | const handleChange= (e) => { 101 | setSearch(e.target.value); 102 | } 103 | 104 | const handleKeyDown =(e) => { 105 | if ( e.keyCode === 13){ 106 | 107 | axios.get(PRODUCTS_BY_SEARCH_URL + search) 108 | .then( response => { 109 | setPosts(response.data.products); 110 | setTotal(response.data.length); 111 | setCurrent(response.data.length); 112 | }) 113 | .catch(err => console.log(err)); 114 | 115 | } 116 | } 117 | 118 | 119 | const getDressesBySex = (sex) => { 120 | const PRODUCTS_BY_SEX = `/api/v1/clothes/?sex=${sex}&page=`; 121 | 122 | axios.get(PRODUCTS_BY_SEX_PAGINATION_URL + 0) 123 | .then(response => { 124 | console.log(response); 125 | setCurrent(1); 126 | setURL(PRODUCTS_BY_SEX); 127 | setTotal(response.data.total); 128 | setPosts(response.data.products); 129 | }) 130 | .catch(err => console.log(err)); 131 | 132 | } 133 | 134 | 135 | 136 | 137 | // Modal things 138 | 139 | const SESSION_PERSIST_URL = 'api/persist/?msg=' 140 | const ADD_TO_CART_URL = 'api/v1/add'; 141 | 142 | 143 | const [open, setOpen] = React.useState(false); 144 | const [dress, setDress ] = React.useState(null); 145 | 146 | const handleOpen = () => { 147 | setOpen(true); 148 | }; 149 | 150 | const handleClose = () => { 151 | setOpen(false); 152 | }; 153 | 154 | 155 | 156 | const AddtoCart = () => { 157 | var payload = { 158 | productId: dress.id, 159 | quantity: 1, 160 | } 161 | 162 | axios.post(ADD_TO_CART_URL, payload) 163 | .then(response => { 164 | if (response.status === 200) { 165 | alert('Added to cart!'); 166 | } 167 | }) 168 | .catch(err => console.log(err)); 169 | } 170 | 171 | 172 | const handlePersist = () => { 173 | var msg = dress.e_arrival.toLowerCase() === 'old' ? "O" : "N"; 174 | axios.get(SESSION_PERSIST_URL + msg) 175 | .then(response => { 176 | console.log(response); 177 | }) 178 | .catch(err => console.log(err)); 179 | } 180 | 181 | const body = () => 182 | 185 | 186 | 187 | 188 | 189 | {dress.b_dresstype} 190 | 191 | 192 | { 193 | dress.e_arrival.toLowerCase() === "old" ? 194 | 195 | Price : 196 | 197 | ₹ {dress.d_price} 198 | {' '} {dress.f_discount} 199 | 200 | : ₹ {dress.d_price} 201 | } 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | < Favorite color="secondary" /> 211 | 212 | 213 | 214 | 215 | 216 | 217 | // Modal things end 218 | 219 | 220 | const handleClick =(i) => { 221 | 222 | setDress(posts[i]); 223 | 224 | setOpen(true); 225 | } 226 | 227 | 228 | 229 | const renderDresses =( posts )=> { 230 | let arr =[]; 231 | for ( let i = 0; i < posts.length ; i+=2 ){ 232 | if ( i !== posts.length -1 ){ 233 | arr.push( 234 | 235 | handleClick(i)}> 236 | {/* */} 237 | 238 | 239 | 240 | handleClick(i+1)}> 241 | {/* */} 242 | 243 | 244 | 245 | ) 246 | } 247 | else{ 248 | arr.push( 249 | 250 | handleClick(i)}> 251 | 252 | 253 | 254 | ) 255 | } 256 | } 257 | return arr; 258 | } 259 | 260 | return ( 261 |
262 | 263 | 264 | 265 | 266 | 267 | 268 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | getDressesBySex('MALE')} > 279 | MALE 280 | 281 | getDressesBySex('FEMALE')} > 282 | FEMALE 283 | 284 | { setSearch("Denim")}}> 285 | Denim 286 | 287 | { setSearch("T-Shirt") }} > 288 | T-Shirt 289 | 290 | 291 | 292 | 293 | 294 | {renderDresses(posts)} 295 | handleOpen(true)}> 296 | { 297 | current !== total ? 298 | 299 | : No more dresses to show . 300 | } 301 | 302 | 303 | 304 | 305 | 306 | 313 |
314 | {dress !== null ? body() :
} 315 |
316 |
317 |
318 | ) 319 | 320 | } 321 | 322 | 323 | export default withRouter(Products); 324 | 325 | -------------------------------------------------------------------------------- /frontend/src/Pages/Register.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Paper, withStyles, Grid, TextField, Button, FormControlLabel, FormControl, FormLabel, RadioGroup,Radio, Checkbox, Typography } from '@material-ui/core'; 3 | import Logo from "../assets/logo.png"; 4 | import { Face, Fingerprint, AccountCircle, Email } from '@material-ui/icons' 5 | import { withRouter } from 'react-router'; 6 | import axios from 'axios'; 7 | 8 | 9 | const styles = theme => ({ 10 | margin: { 11 | margin: theme.spacing.unit * 8, 12 | 13 | }, 14 | padding: { 15 | padding: theme.spacing.unit * 4, 16 | }, 17 | root:{ 18 | height : "auto", 19 | backgroundColor :"#fcf2f8", 20 | paddingBottom:"5em" 21 | } 22 | }); 23 | 24 | function Register(props) { 25 | 26 | 27 | const REGISTER_URI = '/api/register'; 28 | 29 | const [state,setState] = React.useState({ 30 | firstname :{ 31 | value :"", 32 | error:null 33 | }, 34 | lastname :{ 35 | value :"", 36 | error:null 37 | }, 38 | email :{ 39 | value :"", 40 | error:null 41 | }, 42 | password :{ 43 | value :"", 44 | error:null 45 | }, 46 | username :{ 47 | value :"", 48 | error:null 49 | }, 50 | gender :{ 51 | value :"MALE", 52 | error:null 53 | } 54 | }) 55 | 56 | 57 | 58 | const handleChange = (e) => { 59 | setState({ ...state, [e.target.name] : { value : e.target.value, error : null }}) 60 | 61 | } 62 | 63 | 64 | const handleSubmit = () => { 65 | const payload = { 66 | firstName : state.firstname.value, 67 | lastName :state.lastname.value, 68 | userName : state.username.value, 69 | password : state.password.value, 70 | email : state.email.value, 71 | gender : state.gender.value 72 | } 73 | 74 | axios.post( REGISTER_URI, payload) 75 | .then( response => { 76 | console.log(response); 77 | if ( response.status === 200 ){ 78 | props.history.push('/login'); 79 | } 80 | }).catch( err => console.log(err)); 81 | } 82 | 83 | 84 | 85 | 86 | const { classes } = props; 87 | 88 | return ( 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 |
97 | 98 | 99 | Register 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | Gender 143 | {/* value={value} onChange={handleChange} */} 144 | 145 | } label="Female" /> 146 | } label="Male" /> 147 | 148 | 149 | 150 | 151 | 152 | 154 | 155 |
156 |
157 |
158 | ); 159 | } 160 | 161 | 162 | export default withRouter(withStyles(styles)(Register)); -------------------------------------------------------------------------------- /frontend/src/Pages/home.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import {Container, Grid, Typography} from "@material-ui/core"; 3 | import { fade, makeStyles } from '@material-ui/core/styles'; 4 | import Logo from "../assets/logo.png"; 5 | import { Link, withRouter } from 'react-router-dom'; 6 | import data from "../data"; 7 | import Alert from '@material-ui/lab/Alert'; 8 | import IconButton from '@material-ui/core/IconButton'; 9 | import Collapse from '@material-ui/core/Collapse'; 10 | import Button from '@material-ui/core/Button'; 11 | import CloseIcon from '@material-ui/icons/Close'; 12 | import AuthContext from "../context"; 13 | import {Input } from '@material-ui/icons'; 14 | import axios from 'axios'; 15 | 16 | 17 | const useStyles = makeStyles( (theme) => ({ 18 | heading:{ 19 | fontFamily:"Lobster,cursive", 20 | color:"#fc30d0", 21 | 22 | }, 23 | image :{ 24 | borderRadius:"40px" 25 | }, 26 | end:{ 27 | display : "flex", 28 | justifyContent:"flex-end", 29 | } 30 | })) 31 | 32 | const Home = (props) => { 33 | 34 | const { auth , setAuth ,user } = React.useContext(AuthContext); 35 | const classes = useStyles(); 36 | const lstate = props.history.location.state; 37 | const cond = props.history.location.state !== undefined && props.history.location.state.message !== undefined 38 | const [open, setOpen] = React.useState(cond); 39 | 40 | const handleLogout = () => { 41 | axios.get('/api/logout') 42 | .then(response => { 43 | if (response.status === 200) { 44 | setAuth(false); 45 | props.history.push('/') 46 | } 47 | }).catch(err => { 48 | console.log(err); 49 | }) 50 | } 51 | 52 | return ( 53 |
54 | 55 | 56 | 57 | { 66 | setOpen(false); 67 | }} 68 | > 69 | 70 | 71 | } 72 | > 73 | { 74 | cond && 75 | props.history.location.state.message 76 | } 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | Products 85 | 86 | 87 | 88 | { auth && user !== null ? 89 | 90 | 91 | 92 | Welcome {user.email} 93 | 94 | 95 | 96 | 97 | Logout 99 | 100 | 101 | : 102 | 103 | 104 | 105 | Register 106 | 107 | 108 | 109 | 110 | Login 111 | 112 | 113 | 114 | } 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | Have the flamboyance in you have no bounds 125 | Shop for the new trends at never seen prices 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | Grab the latest fashion items 136 | 137 | 138 | 139 | 140 | 141 | 142 | At affordable prices 143 | 144 | 145 | 146 | 147 | 148 | Register now 150 | 151 | 152 | 153 | 154 | Explore more trends 156 | 157 | 158 | 159 | 160 |
161 | ) 162 | } 163 | 164 | 165 | export default withRouter(Home); 166 | -------------------------------------------------------------------------------- /frontend/src/Pages/login.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Paper, withStyles, Grid, TextField, Button, FormControlLabel, Checkbox, Typography } from '@material-ui/core'; 3 | import { Face, Fingerprint } from '@material-ui/icons' 4 | import { withRouter } from 'react-router'; 5 | import AuthContext from "../context"; 6 | const axios = require('axios'); 7 | 8 | 9 | 10 | const styles = theme => ({ 11 | margin: { 12 | margin: theme.spacing.unit * 8, 13 | 14 | }, 15 | padding: { 16 | padding: theme.spacing.unit * 8, 17 | }, 18 | root:{ 19 | height : "100vh", 20 | backgroundColor :"#fcf2f8" 21 | } 22 | }); 23 | 24 | 25 | 26 | 27 | 28 | 29 | function LoginTab(props) { 30 | 31 | 32 | const LOGIN_URI = '/api/login'; 33 | 34 | const { auth , setAuth } = React.useContext(AuthContext); 35 | 36 | const [state,setState] = 37 | React.useState({ 38 | email :{ 39 | value :"", 40 | error:null 41 | }, 42 | password :{ 43 | value :"", 44 | error:null 45 | } 46 | }) 47 | 48 | const handleSubmit = () => { 49 | const params = new URLSearchParams(); 50 | params.append('username', state.email.value); 51 | params.append('password' , state.password.value); 52 | const config = { 53 | headers: { 54 | 'Content-Type': 'application/x-www-form-urlencoded' 55 | } 56 | } 57 | 58 | axios.post( LOGIN_URI , params , config) 59 | .then( (response) => { 60 | 61 | if ( response.status === 200 ){ 62 | setAuth(true); 63 | props.history.push('/'); 64 | } 65 | }) 66 | .catch( (err) => { 67 | console.log(err); 68 | }); 69 | } 70 | 71 | const handleChange = (e) => { 72 | setState({...state, [e.target.name] : { value : e.target.value, error :null}}) 73 | } 74 | 75 | 76 | const { classes } = props; 77 | 78 | return ( 79 | 80 | 81 | Flam Up 82 | 83 | 84 |
85 | 86 | 87 | Login 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | {/* 107 | 108 | 112 | } label="Remember me" /> 113 | 114 | 115 | 116 | 117 | */} 118 | 119 | 121 | 122 |
123 |
124 |
125 | ); 126 | } 127 | 128 | 129 | export default withRouter(withStyles(styles)(LoginTab)); -------------------------------------------------------------------------------- /frontend/src/Service/AuthenticationService.js: -------------------------------------------------------------------------------- 1 | 2 | const axios = require('axios'); 3 | 4 | const checkIfAuthenticated = (setUser, setAuth) => { 5 | // make an axios call 6 | 7 | axios.get('/api/auth').then( response => { 8 | console.log(response); 9 | if ( response.data.AUTHENTICATED === true){ 10 | setAuth(true); 11 | setUser(response.data.USER); 12 | } 13 | else{ 14 | setAuth(false); 15 | setUser(null); 16 | } 17 | }) 18 | .catch( err => console.log(err)); 19 | 20 | 21 | } 22 | 23 | export default checkIfAuthenticated; -------------------------------------------------------------------------------- /frontend/src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheSYNcoder/Full-Stack-Ecommerce-Spring-Boot-React/dc42b58c3534759276621c7c9d3923e3961e8697/frontend/src/assets/logo.png -------------------------------------------------------------------------------- /frontend/src/assets/logof.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheSYNcoder/Full-Stack-Ecommerce-Spring-Boot-React/dc42b58c3534759276621c7c9d3923e3961e8697/frontend/src/assets/logof.png -------------------------------------------------------------------------------- /frontend/src/context.js: -------------------------------------------------------------------------------- 1 | 2 | import React from 'react'; 3 | const AuthContext = React.createContext(); 4 | export default AuthContext; -------------------------------------------------------------------------------- /frontend/src/data.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 3 | data :[ 4 | { 5 | "Unnamed: 0": 0, 6 | "sex": "MALE", 7 | "dresstype": "Round-neck T-shirt Regular Fit", 8 | "image": "lp2.hm.com/hmgoepprod?set=source[/d8/12/d812412329a628300624e1661969be84286fe637.jpg],origin[dam],category[men_tshirtstanks_shortsleeve],type[DESCRIPTIVESTILLLIFE],res[m],hmver[1]&call=url[file:/product/style]", 9 | "price": "Rs.399", 10 | "arrival": "old", 11 | "discount": 121 12 | }, { 13 | "Unnamed: 0": 1, 14 | "sex": "MALE", 15 | "dresstype": "Round-neck T-shirt Regular Fit", 16 | "image": "lp2.hm.com/hmgoepprod?set=source[/2d/ef/2deff3457f9fe4ae80d4067a911589de047fa042.jpg],origin[dam],category[men_tshirtstanks_shortsleeve],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 17 | "price": "Rs.399", 18 | "arrival": "old", 19 | "discount": 162 20 | }, { 21 | "Unnamed: 0": 2, 22 | "sex": "MALE", 23 | "dresstype": "T-shirt with a motif", 24 | "image": "lp2.hm.com/hmgoepprod?set=source[/1d/08/1d08a141515f4f0319ecc5d75230dcbd6325977d.jpg],origin[dam],category[men_tshirtstanks_shortsleeve],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 25 | "price": "Rs.799", 26 | "arrival": "old", 27 | "discount": 291 28 | }, { 29 | "Unnamed: 0": 3, 30 | "sex": "MALE", 31 | "dresstype": "3-pack Regular Fit Polo shirts", 32 | "image": "lp2.hm.com/hmgoepprod?set=source[/98/7d/987daeb1d16e824fa87cf197b26771a79acb1854.jpg],origin[dam],category[],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 33 | "price": "Rs.1,999", 34 | "arrival": "old", 35 | "discount": 334 36 | }, { 37 | "Unnamed: 0": 4, 38 | "sex": "MALE", 39 | "dresstype": "Printed T-shirt", 40 | "image": "lp2.hm.com/hmgoepprod?set=source[/66/d0/66d0fac52e180b88822a86cd981a7978656f2b65.jpg],origin[dam],category[men_tshirtstanks_shortsleeve],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 41 | "price": "Rs.599", 42 | "arrival": "new", 43 | "discount": 243 44 | }, { 45 | "Unnamed: 0": 5, 46 | "sex": "MALE", 47 | "dresstype": "3-pack T-shirts Slim Fit", 48 | "image": "lp2.hm.com/hmgoepprod?set=source[/ab/60/ab600b99932bddedde3bbeeb997f9cae16bfeca8.jpg],origin[dam],category[men_tshirtstanks_shortsleeve],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 49 | "price": "Rs.1,499", 50 | "arrival": "old", 51 | "discount": 1278 52 | }, { 53 | "Unnamed: 0": 6, 54 | "sex": "MALE", 55 | "dresstype": "Round-neck T-shirt Regular Fit", 56 | "image": "lp2.hm.com/hmgoepprod?set=source[/ee/b2/eeb2604d496769701b620b7ff0cc6b67f26b3fca.jpg],origin[dam],category[men_tshirtstanks_shortsleeve],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 57 | "price": "Rs.399", 58 | "arrival": "old", 59 | "discount": 388 60 | }, { 61 | "Unnamed: 0": 7, 62 | "sex": "MALE", 63 | "dresstype": "Round-neck T-shirt Regular Fit", 64 | "image": "lp2.hm.com/hmgoepprod?set=source[/58/09/5809760b5e1943484403097b9c642a571bcf825d.jpg],origin[dam],category[],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 65 | "price": "Rs.399", 66 | "arrival": "old", 67 | "discount": 332 68 | }, { 69 | "Unnamed: 0": 8, 70 | "sex": "MALE", 71 | "dresstype": "3-pack jersey tops Regular Fit", 72 | "image": "lp2.hm.com/hmgoepprod?set=source[/34/4f/344f8df19359f80587755b067b543a80f8b582b9.jpg],origin[dam],category[men_tshirtstanks_longsleeve],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 73 | "price": "Rs.1,999", 74 | "arrival": "old", 75 | "discount": 592 76 | }, { 77 | "Unnamed: 0": 9, 78 | "sex": "MALE", 79 | "dresstype": "Round-neck T-shirt Regular Fit", 80 | "image": "lp2.hm.com/hmgoepprod?set=source[/91/a0/91a050fbaecd1caba940f6adfc631fb84dbecccc.jpg],origin[dam],category[men_tshirtstanks_shortsleeve],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 81 | "price": "Rs.399", 82 | "arrival": "old", 83 | "discount": 193 84 | }, { 85 | "Unnamed: 0": 10, 86 | "sex": "MALE", 87 | "dresstype": "Cotton T-shirt", 88 | "image": "lp2.hm.com/hmgoepprod?set=source[/65/c1/65c1e7fb98cec0c6e42b819fbecd7e3bc5414670.jpg],origin[dam],category[],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 89 | "price": "Rs.799", 90 | "arrival": "old", 91 | "discount": 102 92 | }, { 93 | "Unnamed: 0": 11, 94 | "sex": "MALE", 95 | "dresstype": "T-shirt Long Fit", 96 | "image": "lp2.hm.com/hmgoepprod?set=source[/f3/7a/f37aee371f02fe06744019c8bac509c1d17d8e2a.jpg],origin[dam],category[men_tshirtstanks_shortsleeve],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 97 | "price": "Rs.699", 98 | "arrival": "old", 99 | "discount": 226 100 | }, { 101 | "Unnamed: 0": 12, 102 | "sex": "MALE", 103 | "dresstype": "Round-neck T-shirt Regular Fit", 104 | "image": "lp2.hm.com/hmgoepprod?set=source[/a6/47/a64786443b2acf43fef06c56c47fcddcf8697abe.jpg],origin[dam],category[men_tshirtstanks_shortsleeve],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 105 | "price": "Rs.399", 106 | "arrival": "old", 107 | "discount": 312 108 | }, { 109 | "Unnamed: 0": 13, 110 | "sex": "MALE", 111 | "dresstype": "3-pack T-shirts Slim Fit", 112 | "image": "lp2.hm.com/hmgoepprod?set=source[/54/2f/542ff2a50871b2d9c86ba8db5b2a0c02b6499d66.jpg],origin[dam],category[men_tshirtstanks_shortsleeve],type[DESCRIPTIVESTILLLIFE],res[m],hmver[1]&call=url[file:/product/style]", 113 | "price": "Rs.1,499", 114 | "arrival": "old", 115 | "discount": 862 116 | }, 117 | { 118 | "Unnamed: 0": 821, 119 | "sex": "FEMALE", 120 | "dresstype": "Rib-knit dress", 121 | "image": "lp2.hm.com/hmgoepprod?set=source[/39/64/3964cf9eccdfe89c8ecbb49586756b2617ac2c26.jpg],origin[dam],category[],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 122 | "price": "Rs.2,999", 123 | "arrival": "new", 124 | "discount": 705 125 | }, { 126 | "Unnamed: 0": 822, 127 | "sex": "FEMALE", 128 | "dresstype": "Knitted dress", 129 | "image": "lp2.hm.com/hmgoepprod?set=source[/83/41/83412d6216fa00a7fc17867fd52085e33a80294b.jpg],origin[dam],category[],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 130 | "price": "Rs.2,299", 131 | "arrival": "old", 132 | "discount": 1242 133 | }, { 134 | "Unnamed: 0": 823, 135 | "sex": "FEMALE", 136 | "dresstype": "Ribbed dress", 137 | "image": "lp2.hm.com/hmgoepprod?set=source[/2d/49/2d49ed9b378f77b2138fb4cedc0316be430de0a2.jpg],origin[dam],category[],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 138 | "price": "Rs.1,499", 139 | "arrival": "new", 140 | "discount": 1214 141 | }, { 142 | "Unnamed: 0": 824, 143 | "sex": "FEMALE", 144 | "dresstype": "Puff-sleeved dress", 145 | "image": "lp2.hm.com/hmgoepprod?set=source[/82/af/82afbf3d4292adc2a7db0e1e19ebce9769461eef.jpg],origin[dam],category[],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 146 | "price": "Rs.1,499", 147 | "arrival": "new", 148 | "discount": 1287 149 | }, { 150 | "Unnamed: 0": 825, 151 | "sex": "FEMALE", 152 | "dresstype": "Button-front dress", 153 | "image": "lp2.hm.com/hmgoepprod?set=source[/44/b0/44b068781aafc99832cf8e9fbb5f7ac56083e2f5.jpg],origin[dam],category[],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 154 | "price": "Rs.1,499", 155 | "arrival": "old", 156 | "discount": 834 157 | }, { 158 | "Unnamed: 0": 826, 159 | "sex": "FEMALE", 160 | "dresstype": "Airy cotton dress", 161 | "image": "lp2.hm.com/hmgoepprod?set=source[/9c/1b/9c1bf17e18fcea0fd9d37a333ed2b81ab8727d90.jpg],origin[dam],category[],type[DESCRIPTIVESTILLLIFE],res[m],hmver[2]&call=url[file:/product/style]", 162 | "price": "Rs.1,499", 163 | "arrival": "new", 164 | "discount": 411 165 | }, { 166 | "Unnamed: 0": 827, 167 | "sex": "FEMALE", 168 | "dresstype": "Long wrap dress", 169 | "image": "lp2.hm.com/hmgoepprod?set=source[/4d/42/4d4267f4ab21f7c5784d535aa94446a265b777c6.jpg],origin[dam],category[],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 170 | "price": "Rs.2,299", 171 | "arrival": "old", 172 | "discount": 459 173 | }, { 174 | "Unnamed: 0": 828, 175 | "sex": "FEMALE", 176 | "dresstype": "Calf-length T-shirt dress", 177 | "image": "lp2.hm.com/hmgoepprod?set=source[/0e/ab/0eabb9c010a6492c49979c065882a66adbdfa4be.jpg],origin[dam],category[],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 178 | "price": "Rs.1,499", 179 | "arrival": "old", 180 | "discount": 926 181 | }, { 182 | "Unnamed: 0": 829, 183 | "sex": "FEMALE", 184 | "dresstype": "Button-front dress", 185 | "image": "lp2.hm.com/hmgoepprod?set=source[/a7/04/a70467016c6f10b0df099612a867def1884cd690.jpg],origin[dam],category[],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 186 | "price": "Rs.1,499", 187 | "arrival": "old", 188 | "discount": 1480 189 | }, { 190 | "Unnamed: 0": 830, 191 | "sex": "FEMALE", 192 | "dresstype": "Shirt dress", 193 | "image": "lp2.hm.com/hmgoepprod?set=source[/97/a4/97a434949e029b2c4092ce1fdf05c931d450614f.jpg],origin[dam],category[],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 194 | "price": "Rs.1,499", 195 | "arrival": "old", 196 | "discount": 634 197 | }, { 198 | "Unnamed: 0": 831, 199 | "sex": "FEMALE", 200 | "dresstype": "Balloon-sleeved dress", 201 | "image": "lp2.hm.com/hmgoepprod?set=source[/28/c3/28c3c847b7be6f166f4927de26af352a1dc690e6.jpg],origin[dam],category[],type[DESCRIPTIVESTILLLIFE],res[m],hmver[2]&call=url[file:/product/style]", 202 | "price": "Rs.2,299", 203 | "arrival": "old", 204 | "discount": 101 205 | }, { 206 | "Unnamed: 0": 832, 207 | "sex": "FEMALE", 208 | "dresstype": "Wrap dress", 209 | "image": "lp2.hm.com/hmgoepprod?set=source[/a4/02/a402c5c91d56e98af823d3aceef767fdbadfdceb.jpg],origin[dam],category[],type[DESCRIPTIVESTILLLIFE],res[m],hmver[2]&call=url[file:/product/style]", 210 | "price": "Rs.1,999", 211 | "arrival": "old", 212 | "discount": 1095 213 | }, { 214 | "Unnamed: 0": 833, 215 | "sex": "FEMALE", 216 | "dresstype": "Straight dress", 217 | "image": "lp2.hm.com/hmgoepprod?set=source[/af/ac/afac8ebc2c6695a32459c91b274eb12bd8e120e3.jpg],origin[dam],category[],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 218 | "price": "Rs.1,299", 219 | "arrival": "new", 220 | "discount": 445 221 | }, { 222 | "Unnamed: 0": 834, 223 | "sex": "FEMALE", 224 | "dresstype": "Long V-neck dress", 225 | "image": "lp2.hm.com/hmgoepprod?set=source[/ec/8c/ec8c6dd28117773a49398b999ed060b7a5b5cb52.jpg],origin[dam],category[],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 226 | "price": "Rs.2,699", 227 | "arrival": "old", 228 | "discount": 202 229 | }, { 230 | "Unnamed: 0": 835, 231 | "sex": "FEMALE", 232 | "dresstype": "V-neck dress", 233 | "image": "lp2.hm.com/hmgoepprod?set=source[/b4/f6/b4f691b523d234eeccc542f2738fc1caae902917.jpg],origin[dam],category[],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 234 | "price": "Rs.1,499", 235 | "arrival": "new", 236 | "discount": 173 237 | }, { 238 | "Unnamed: 0": 836, 239 | "sex": "FEMALE", 240 | "dresstype": "Linen-blend wrapover dress", 241 | "image": "lp2.hm.com/hmgoepprod?set=source[/26/ba/26ba46e52c87ae619638b6237fd422e49c22e540.jpg],origin[dam],category[],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 242 | "price": "Rs.2,999", 243 | "arrival": "new", 244 | "discount": 1080 245 | }, { 246 | "Unnamed: 0": 837, 247 | "sex": "FEMALE", 248 | "dresstype": "Puff-sleeved dress", 249 | "image": "lp2.hm.com/hmgoepprod?set=source[/b8/b2/b8b269f5543619c59d0e1dbc94170467d1e10004.jpg],origin[dam],category[],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 250 | "price": "Rs.2,299", 251 | "arrival": "old", 252 | "discount": 791 253 | }, { 254 | "Unnamed: 0": 838, 255 | "sex": "FEMALE", 256 | "dresstype": "H&M+ Linen-blend dress", 257 | "image": "lp2.hm.com/hmgoepprod?set=source[/81/7f/817f010b52258397f4eedf2e843b70291525a95d.jpg],origin[dam],category[ladies_dresses_mididresses],type[LOOKBOOK],res[m],hmver[1]&call=url[file:/product/style]", 258 | "price": "Rs.2,299", 259 | "arrival": "old", 260 | "discount": 1321 261 | } 262 | 263 | ] 264 | 265 | } -------------------------------------------------------------------------------- /frontend/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | scroll-behavior: smooth; 9 | overflow-x: hidden; 10 | } 11 | 12 | code { 13 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 14 | monospace; 15 | } 16 | -------------------------------------------------------------------------------- /frontend/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | ReactDOM.render( 8 | 9 | 10 | , 11 | document.getElementById('root') 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /frontend/src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /frontend/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /frontend/src/scrapeHM.js: -------------------------------------------------------------------------------- 1 | var nodesObj = document.querySelectorAll('.product-item');var nodesList = Object.keys(nodesObj).map( key => nodesObj[key]);var objectMap = nodesList.map( node =>{ return { dressType : node.querySelector('.link').text 2 | , price : node.querySelector('.item-price').children[0].textContent 3 | , arrival : node.querySelector('.new-product') !== null ? 'new' : 'old', image : node.querySelector('.item-image').dataset.src.substring(2)}}); var jsonString = JSON.stringify(objectMap); console.log(jsonString); -------------------------------------------------------------------------------- /frontend/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /logof.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheSYNcoder/Full-Stack-Ecommerce-Spring-Boot-React/dc42b58c3534759276621c7c9d3923e3961e8697/logof.png -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | fi 118 | 119 | if [ -z "$JAVA_HOME" ]; then 120 | javaExecutable="`which javac`" 121 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 122 | # readlink(1) is not available as standard on Solaris 10. 123 | readLink=`which readlink` 124 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 125 | if $darwin ; then 126 | javaHome="`dirname \"$javaExecutable\"`" 127 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 128 | else 129 | javaExecutable="`readlink -f \"$javaExecutable\"`" 130 | fi 131 | javaHome="`dirname \"$javaExecutable\"`" 132 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 133 | JAVA_HOME="$javaHome" 134 | export JAVA_HOME 135 | fi 136 | fi 137 | fi 138 | 139 | if [ -z "$JAVACMD" ] ; then 140 | if [ -n "$JAVA_HOME" ] ; then 141 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 142 | # IBM's JDK on AIX uses strange locations for the executables 143 | JAVACMD="$JAVA_HOME/jre/sh/java" 144 | else 145 | JAVACMD="$JAVA_HOME/bin/java" 146 | fi 147 | else 148 | JAVACMD="`which java`" 149 | fi 150 | fi 151 | 152 | if [ ! -x "$JAVACMD" ] ; then 153 | echo "Error: JAVA_HOME is not defined correctly." >&2 154 | echo " We cannot execute $JAVACMD" >&2 155 | exit 1 156 | fi 157 | 158 | if [ -z "$JAVA_HOME" ] ; then 159 | echo "Warning: JAVA_HOME environment variable is not set." 160 | fi 161 | 162 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 163 | 164 | # traverses directory structure from process work directory to filesystem root 165 | # first directory with .mvn subdirectory is considered project base directory 166 | find_maven_basedir() { 167 | 168 | if [ -z "$1" ] 169 | then 170 | echo "Path not specified to find_maven_basedir" 171 | return 1 172 | fi 173 | 174 | basedir="$1" 175 | wdir="$1" 176 | while [ "$wdir" != '/' ] ; do 177 | if [ -d "$wdir"/.mvn ] ; then 178 | basedir=$wdir 179 | break 180 | fi 181 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 182 | if [ -d "${wdir}" ]; then 183 | wdir=`cd "$wdir/.."; pwd` 184 | fi 185 | # end of workaround 186 | done 187 | echo "${basedir}" 188 | } 189 | 190 | # concatenates all lines of a file 191 | concat_lines() { 192 | if [ -f "$1" ]; then 193 | echo "$(tr -s '\n' ' ' < "$1")" 194 | fi 195 | } 196 | 197 | BASE_DIR=`find_maven_basedir "$(pwd)"` 198 | if [ -z "$BASE_DIR" ]; then 199 | exit 1; 200 | fi 201 | 202 | ########################################################################################## 203 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 204 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 205 | ########################################################################################## 206 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 207 | if [ "$MVNW_VERBOSE" = true ]; then 208 | echo "Found .mvn/wrapper/maven-wrapper.jar" 209 | fi 210 | else 211 | if [ "$MVNW_VERBOSE" = true ]; then 212 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 213 | fi 214 | if [ -n "$MVNW_REPOURL" ]; then 215 | jarUrl="$MVNW_REPOURL/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 216 | else 217 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 218 | fi 219 | while IFS="=" read key value; do 220 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 221 | esac 222 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 223 | if [ "$MVNW_VERBOSE" = true ]; then 224 | echo "Downloading from: $jarUrl" 225 | fi 226 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 227 | if $cygwin; then 228 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` 229 | fi 230 | 231 | if command -v wget > /dev/null; then 232 | if [ "$MVNW_VERBOSE" = true ]; then 233 | echo "Found wget ... using wget" 234 | fi 235 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 236 | wget "$jarUrl" -O "$wrapperJarPath" 237 | else 238 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" 239 | fi 240 | elif command -v curl > /dev/null; then 241 | if [ "$MVNW_VERBOSE" = true ]; then 242 | echo "Found curl ... using curl" 243 | fi 244 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then 245 | curl -o "$wrapperJarPath" "$jarUrl" -f 246 | else 247 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f 248 | fi 249 | 250 | else 251 | if [ "$MVNW_VERBOSE" = true ]; then 252 | echo "Falling back to using Java to download" 253 | fi 254 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 255 | # For Cygwin, switch paths to Windows format before running javac 256 | if $cygwin; then 257 | javaClass=`cygpath --path --windows "$javaClass"` 258 | fi 259 | if [ -e "$javaClass" ]; then 260 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 261 | if [ "$MVNW_VERBOSE" = true ]; then 262 | echo " - Compiling MavenWrapperDownloader.java ..." 263 | fi 264 | # Compiling the Java class 265 | ("$JAVA_HOME/bin/javac" "$javaClass") 266 | fi 267 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 268 | # Running the downloader 269 | if [ "$MVNW_VERBOSE" = true ]; then 270 | echo " - Running MavenWrapperDownloader.java ..." 271 | fi 272 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 273 | fi 274 | fi 275 | fi 276 | fi 277 | ########################################################################################## 278 | # End of extension 279 | ########################################################################################## 280 | 281 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 282 | if [ "$MVNW_VERBOSE" = true ]; then 283 | echo $MAVEN_PROJECTBASEDIR 284 | fi 285 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 286 | 287 | # For Cygwin, switch paths to Windows format before running java 288 | if $cygwin; then 289 | [ -n "$M2_HOME" ] && 290 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 291 | [ -n "$JAVA_HOME" ] && 292 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 293 | [ -n "$CLASSPATH" ] && 294 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 295 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 296 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 297 | fi 298 | 299 | # Provide a "standardized" way to retrieve the CLI args that will 300 | # work with both Windows and non-Windows executions. 301 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" 302 | export MAVEN_CMD_LINE_ARGS 303 | 304 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 305 | 306 | exec "$JAVACMD" \ 307 | $MAVEN_OPTS \ 308 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 309 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 310 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 311 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 124 | 125 | FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 162 | if ERRORLEVEL 1 goto error 163 | goto end 164 | 165 | :error 166 | set ERROR_CODE=1 167 | 168 | :end 169 | @endlocal & set ERROR_CODE=%ERROR_CODE% 170 | 171 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 172 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 173 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 174 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 175 | :skipRcPost 176 | 177 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 178 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 179 | 180 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 181 | 182 | exit /B %ERROR_CODE% 183 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.4.4 9 | 10 | 11 | com.flamUp 12 | spring 13 | 0.0.2-SNAPSHOT 14 | spring 15 | Demo project for Spring Boot 16 | 17 | 8 18 | 1.11.3 19 | v14.16.0 20 | 6.14.11 21 | 22 | 23 | 24 | org.springframework.boot 25 | spring-boot-starter-data-jdbc 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-data-jpa 30 | 31 | 32 | org.springframework.boot 33 | spring-boot-starter-security 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-web 38 | 39 | 40 | org.springframework.session 41 | spring-session-core 42 | 43 | 44 | org.springframework.session 45 | spring-session-jdbc 46 | 47 | 48 | 49 | io.springfox 50 | springfox-boot-starter 51 | 3.0.0 52 | 53 | 54 | 55 | org.postgresql 56 | postgresql 57 | runtime 58 | 59 | 60 | org.projectlombok 61 | lombok 62 | true 63 | 64 | 65 | org.springframework.boot 66 | spring-boot-starter-test 67 | test 68 | 69 | 70 | org.springframework.security 71 | spring-security-test 72 | test 73 | 74 | 75 | 76 | 77 | 78 | 79 | ${project.basedir}/frontend/build 80 | false 81 | public/ 82 | 83 | 84 | ${project.basedir}/src/main/resources 85 | false 86 | 87 | 88 | 89 | 90 | org.springframework.boot 91 | spring-boot-maven-plugin 92 | 93 | 94 | 95 | org.projectlombok 96 | lombok 97 | 98 | 99 | 100 | 101 | 102 | 103 | com.github.eirslett 104 | frontend-maven-plugin 105 | 1.11.3 106 | 107 | frontend 108 | target 109 | 110 | 111 | 112 | install node and npm 113 | 114 | install-node-and-npm 115 | 116 | 117 | v14.16.0 118 | 6.14.11 119 | 120 | 121 | 122 | npm install 123 | 124 | npm 125 | 126 | 127 | install 128 | 129 | 130 | 131 | npm run build 132 | 133 | npm 134 | 135 | 136 | run build 137 | 138 | 139 | 140 | 141 | 142 | 143 | maven-antrun-plugin 144 | 145 | 146 | generate-resources 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | run 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/Application.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring; 2 | 3 | import org.apache.catalina.Context; 4 | import org.apache.catalina.connector.Connector; 5 | import org.apache.tomcat.util.descriptor.web.SecurityCollection; 6 | import org.apache.tomcat.util.descriptor.web.SecurityConstraint; 7 | import org.springframework.boot.SpringApplication; 8 | import org.springframework.boot.autoconfigure.SpringBootApplication; 9 | import org.springframework.boot.autoconfigure.domain.EntityScan; 10 | import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; 11 | import org.springframework.boot.web.servlet.server.ServletWebServerFactory; 12 | import org.springframework.context.annotation.Bean; 13 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 14 | 15 | @SpringBootApplication 16 | @EntityScan("com.flamup.spring.Models") 17 | @EnableJpaRepositories("com.flamup.spring.Repositories") 18 | public class Application { 19 | 20 | public static void main(String[] args) { 21 | SpringApplication.run(Application.class, args); 22 | } 23 | 24 | @Bean 25 | public ServletWebServerFactory servletContainer(){ 26 | TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory(){ 27 | @Override 28 | protected void postProcessContext(Context context) { 29 | SecurityConstraint securityConstraint = new SecurityConstraint(); 30 | securityConstraint.setUserConstraint("CONFIDENTIAL"); 31 | SecurityCollection securityCollection = new SecurityCollection(); 32 | securityCollection.addPattern("/*"); 33 | securityConstraint.addCollection(securityCollection); 34 | context.addConstraint(securityConstraint); 35 | } 36 | }; 37 | tomcat.addAdditionalTomcatConnectors(redirectConnector()); 38 | return tomcat; 39 | } 40 | 41 | 42 | private Connector redirectConnector(){ 43 | Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); 44 | connector.setScheme("http"); 45 | connector.setPort(8080); 46 | connector.setSecure(false); 47 | connector.setRedirectPort(8443); 48 | return connector; 49 | 50 | } 51 | 52 | } 53 | 54 | 55 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/Controllers/AuthController.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.Controllers; 2 | 3 | 4 | import com.flamup.spring.auth.AppUserService; 5 | import com.flamup.spring.Models.ApplicationUser; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.security.authentication.AnonymousAuthenticationToken; 8 | import org.springframework.security.core.Authentication; 9 | import org.springframework.security.core.context.SecurityContextHolder; 10 | import org.springframework.web.bind.annotation.GetMapping; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RestController; 13 | import java.util.HashMap; 14 | 15 | @RestController 16 | @RequestMapping(path = "api/") 17 | public class AuthController { 18 | 19 | 20 | private final AppUserService appUserService; 21 | 22 | @Autowired 23 | public AuthController(AppUserService appUserService) { 24 | this.appUserService = appUserService; 25 | } 26 | 27 | 28 | @GetMapping(path = "auth") 29 | public HashMap isAuthenticated(){ 30 | 31 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); 32 | HashMap hs = new HashMap<>(); 33 | 34 | if ( auth!= null && auth.getPrincipal() != null && auth.isAuthenticated() && !(auth instanceof AnonymousAuthenticationToken) ){ 35 | 36 | hs.put("AUTHENTICATED", true); 37 | ApplicationUser userDetails = (ApplicationUser) auth.getPrincipal(); 38 | userDetails.setPassword(""); 39 | hs.put("USER" , userDetails ); 40 | } 41 | else{ 42 | hs.put("AUTHENTICATED", false); 43 | } 44 | return hs; 45 | } 46 | 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/Controllers/CartServiceController.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.Controllers; 2 | 3 | import com.flamup.spring.DTO.OrderDTO; 4 | import com.flamup.spring.DTO.UpdateOrderDTO; 5 | import com.flamup.spring.Services.CartService; 6 | import lombok.AllArgsConstructor; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | import java.util.HashMap; 12 | 13 | @RestController 14 | @RequestMapping(path = "api/v1/") 15 | @AllArgsConstructor 16 | public class CartServiceController { 17 | 18 | private final CartService cartService; 19 | 20 | 21 | @PostMapping( path = "add") 22 | public ResponseEntity addProduct(@RequestBody OrderDTO orderDTO ){ 23 | return new ResponseEntity(cartService.addToCart(orderDTO) , HttpStatus.CREATED); 24 | } 25 | 26 | @GetMapping( path = "orders") 27 | public ResponseEntity> getOrders(){ 28 | return new ResponseEntity<>(cartService.getProducts(), HttpStatus.OK); 29 | } 30 | 31 | @PutMapping(path = "order") 32 | public ResponseEntity updateOrder(@RequestBody UpdateOrderDTO updateOrderDTO){ 33 | return new ResponseEntity<>(cartService.updateOrder( updateOrderDTO ), HttpStatus.CREATED); 34 | } 35 | 36 | @DeleteMapping( path = "order/{id}") 37 | public ResponseEntity deleteOrder(@PathVariable String id){ 38 | return new ResponseEntity<>(cartService.deleteOrder(id), HttpStatus.OK); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/Controllers/ProductController.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.Controllers; 2 | 3 | 4 | import com.flamup.spring.Models.Product; 5 | import com.flamup.spring.Services.ProductService; 6 | import lombok.AllArgsConstructor; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | import java.util.ArrayList; 14 | import java.util.HashMap; 15 | import java.util.List; 16 | import java.util.Map; 17 | import java.util.stream.Collectors; 18 | 19 | @RestController 20 | @RequestMapping(path = "api/v1/") 21 | @AllArgsConstructor 22 | public class ProductController { 23 | 24 | private final ProductService productService; 25 | 26 | @GetMapping(path = "dresses") 27 | public HashMap getProductsByDressTypeOnSearch(@RequestParam(name = "dress") String dress){ 28 | HashMap hs = new HashMap<>(); 29 | List products = productService.getProductsByDressType(dress); 30 | hs.put("products", products); 31 | hs.put("length" , products.size()); 32 | return hs; 33 | } 34 | 35 | 36 | @GetMapping( path = "clothes") 37 | public HashMap getProductsBySexAndSession( 38 | @RequestParam(name = "sex") String sex, 39 | @RequestParam(defaultValue = "10") Integer items, 40 | @RequestParam(defaultValue = "0") Integer page, 41 | HttpServletRequest request){ 42 | 43 | List messages = (List) request.getSession().getAttribute("SESSION_STORE"); 44 | 45 | if ( messages == null){ 46 | messages = new ArrayList<>(); 47 | } 48 | 49 | Map countBySex = messages.stream().collect( 50 | Collectors.partitioningBy( 51 | (String msg) -> (msg.equals("O")), Collectors.counting() )); 52 | 53 | return productService.getProductsBySex(sex, items, page, countBySex); 54 | 55 | } 56 | 57 | 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/Controllers/RegistrationController.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.Controllers; 2 | 3 | 4 | import com.flamup.spring.Models.RegistrationRequest; 5 | import com.flamup.spring.Services.RegistrationService; 6 | import lombok.AllArgsConstructor; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.http.ResponseEntity; 9 | import org.springframework.web.bind.annotation.PostMapping; 10 | import org.springframework.web.bind.annotation.RequestBody; 11 | import org.springframework.web.bind.annotation.RequestMapping; 12 | import org.springframework.web.bind.annotation.RestController; 13 | 14 | @RestController 15 | @RequestMapping(path = "api/register") 16 | @AllArgsConstructor 17 | public class RegistrationController { 18 | 19 | private RegistrationService registrationService; 20 | 21 | @PostMapping 22 | public ResponseEntity register(@RequestBody RegistrationRequest request ){ 23 | return new ResponseEntity(registrationService.register(request),HttpStatus.OK); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/Controllers/SessionController.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.Controllers; 2 | 3 | 4 | import org.apache.juli.logging.LogFactory; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | import javax.servlet.http.HttpServletRequest; 10 | import java.util.ArrayList; 11 | import java.util.List; 12 | 13 | @RestController 14 | @RequestMapping(path = "api/") 15 | public class SessionController { 16 | 17 | private static Logger logger = LoggerFactory.getLogger( SessionController.class); 18 | @GetMapping( path = "persist") 19 | public List persistMessages(@RequestParam(name = "msg") String message, HttpServletRequest request){ 20 | 21 | logger.debug("IN persist message" + message); 22 | List messages = (List) request.getSession().getAttribute("SESSION_STORE"); 23 | if ( messages == null ){ 24 | messages = new ArrayList<>(); 25 | request.getSession().setAttribute("SESSION_STORE" , messages); 26 | } 27 | messages.add(message); 28 | request.getSession().setAttribute("SESSION_STORE", messages); 29 | return messages; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/Controllers/TestGetController.java: -------------------------------------------------------------------------------- 1 | //package com.flamup.spring.Controllers; 2 | // 3 | //import org.springframework.stereotype.Controller; 4 | //import org.springframework.web.bind.annotation.GetMapping; 5 | //import org.springframework.web.bind.annotation.RequestMapping; 6 | //import org.springframework.web.bind.annotation.RestController; 7 | // 8 | //import java.util.HashMap; 9 | // 10 | //@RestController 11 | //@RequestMapping(path = "api/v1/") 12 | //public class TestGetController { 13 | // 14 | // @GetMapping(path = "sexy") 15 | // public HashMap sampleGet(){ 16 | // HashMap maps = new HashMap<>(); 17 | // maps.put("WOW", "COOL"); 18 | // maps.put("SEXY", "BITCH"); 19 | // return maps; 20 | // } 21 | // 22 | //} 23 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/DTO/OrderDTO.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.DTO; 2 | 3 | 4 | import com.flamup.spring.Models.Product; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Getter; 7 | import lombok.NoArgsConstructor; 8 | import lombok.Setter; 9 | 10 | @Getter 11 | @Setter 12 | @NoArgsConstructor 13 | @AllArgsConstructor 14 | public class OrderDTO { 15 | 16 | private Long productId; 17 | private int quantity; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/DTO/UpdateOrderDTO.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.DTO; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | @Getter 9 | @Setter 10 | @NoArgsConstructor 11 | @AllArgsConstructor 12 | public class UpdateOrderDTO { 13 | private String id; 14 | private Integer quantity; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/Models/AppUserRole.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.Models; 2 | 3 | 4 | public enum AppUserRole { 5 | USER, 6 | ADMIN 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/Models/ApplicationUser.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.Models; 2 | 3 | 4 | import lombok.*; 5 | import org.springframework.security.core.GrantedAuthority; 6 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 7 | import org.springframework.security.core.userdetails.UserDetails; 8 | import javax.persistence.*; 9 | import java.util.Collection; 10 | import java.util.Collections; 11 | 12 | 13 | 14 | 15 | 16 | @Entity 17 | @NoArgsConstructor 18 | @Data 19 | public class ApplicationUser implements UserDetails { 20 | 21 | 22 | public enum Gender{ 23 | MALE, 24 | FEMALE 25 | } 26 | 27 | @SequenceGenerator( 28 | name = "student_sequence", 29 | sequenceName = "student_sequence", 30 | allocationSize = 1 31 | ) 32 | 33 | @Id 34 | @GeneratedValue( 35 | strategy = GenerationType.SEQUENCE, 36 | generator = "student_sequence" 37 | ) 38 | private Long id; 39 | private String firstName; 40 | private String lastName; 41 | private String username; 42 | 43 | private String password; 44 | private String email; 45 | @Enumerated(EnumType.STRING) 46 | // @Column(name="role") 47 | private AppUserRole appUserRole; 48 | @Enumerated(EnumType.STRING) 49 | private Gender gender; 50 | 51 | 52 | public ApplicationUser(String firstName, 53 | String lastName, 54 | String username, 55 | String password, 56 | String email, 57 | AppUserRole appUserRole, 58 | Gender gender) { 59 | this.firstName = firstName; 60 | this.lastName = lastName; 61 | this.username = username; 62 | this.password = password; 63 | this.email = email; 64 | this.appUserRole = appUserRole; 65 | this.gender = gender; 66 | } 67 | 68 | public Long getId(){ 69 | return id; 70 | } 71 | public String getFirstName() { 72 | return firstName; 73 | } 74 | 75 | public void setFirstName(String firstName) { 76 | this.firstName = firstName; 77 | } 78 | 79 | public String getLastName() { 80 | return lastName; 81 | } 82 | 83 | public void setLastName(String lastName) { 84 | this.lastName = lastName; 85 | } 86 | 87 | 88 | public String getEmail() { return username; } 89 | 90 | public void setEmail(String email) { this.email = email; } 91 | 92 | 93 | 94 | 95 | @Override 96 | public Collection getAuthorities() { 97 | SimpleGrantedAuthority authority = 98 | new SimpleGrantedAuthority(appUserRole.name()); 99 | return Collections.singletonList(authority); 100 | } 101 | 102 | @Override 103 | public String getPassword() { 104 | return password; 105 | } 106 | 107 | @Override 108 | public String getUsername() { 109 | return email; 110 | } 111 | 112 | @Override 113 | public boolean isAccountNonExpired() { 114 | return true; 115 | } 116 | 117 | @Override 118 | public boolean isAccountNonLocked() { 119 | return true; 120 | } 121 | 122 | @Override 123 | public boolean isCredentialsNonExpired() { 124 | return true; 125 | } 126 | 127 | @Override 128 | public boolean isEnabled() { 129 | return true; 130 | } 131 | 132 | public void setPassword( String password){ 133 | this.password = password; 134 | } 135 | 136 | public void setUsername( String username ){ 137 | this.username = username; 138 | } 139 | 140 | 141 | 142 | } 143 | 144 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/Models/OrderItem.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.Models; 2 | 3 | 4 | import com.fasterxml.jackson.annotation.JsonIgnore; 5 | import com.flamup.spring.DTO.OrderDTO; 6 | import lombok.AllArgsConstructor; 7 | import lombok.Getter; 8 | import lombok.NoArgsConstructor; 9 | import lombok.Setter; 10 | 11 | import javax.persistence.*; 12 | import java.util.UUID; 13 | 14 | 15 | @Entity 16 | @Table(name = "item") 17 | @Getter 18 | @Setter 19 | @NoArgsConstructor 20 | @AllArgsConstructor 21 | public class OrderItem { 22 | 23 | @Id 24 | private String id; 25 | 26 | @OneToOne 27 | private Product product; 28 | 29 | @ManyToOne(fetch = FetchType.LAZY, optional = false) 30 | @JoinColumn(name ="cart_id" , nullable = false) 31 | @JsonIgnore 32 | private ShoppingCart cart; 33 | 34 | private int quantity; 35 | 36 | public void fromDto(Product p, ShoppingCart cart, int quantity ){ 37 | id = UUID.randomUUID().toString().replace("-", ""); 38 | product = p; 39 | this.cart = cart; 40 | this.quantity = quantity; 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/Models/Product.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.Models; 2 | 3 | import lombok.*; 4 | 5 | import javax.persistence.*; 6 | 7 | @Entity 8 | @Table(name = "clothes") 9 | @Getter 10 | @Setter 11 | @NoArgsConstructor 12 | @AllArgsConstructor 13 | @ToString 14 | public class Product { 15 | 16 | public enum sex{ 17 | MALE, 18 | FEMALE 19 | } 20 | 21 | @Id 22 | Long id; 23 | @Enumerated(EnumType.STRING) 24 | 25 | @Column(name = "sex") 26 | sex a_sex; 27 | @Column(name = "dresstype") 28 | String b_dresstype; 29 | @Column(name = "image") 30 | String c_image; 31 | @Column(name = "price") 32 | String d_price; 33 | @Column(name = "arrival") 34 | String e_arrival; 35 | @Column(name = "discount") 36 | int f_discount; 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/Models/RegistrationRequest.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.Models; 2 | 3 | 4 | import lombok.*; 5 | 6 | 7 | @AllArgsConstructor 8 | @Getter 9 | @Setter 10 | @NoArgsConstructor 11 | @EqualsAndHashCode 12 | @ToString 13 | public class RegistrationRequest { 14 | private String firstName; 15 | private String lastName; 16 | private String userName; 17 | private String password; 18 | private String email; 19 | private String gender; 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/Models/ShoppingCart.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.Models; 2 | 3 | import lombok.*; 4 | 5 | import javax.persistence.*; 6 | import java.time.LocalDateTime; 7 | import java.util.HashSet; 8 | import java.util.Set; 9 | 10 | @Entity 11 | @Table(name = "cart") 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | @Getter 15 | @Setter 16 | @ToString 17 | public class ShoppingCart { 18 | 19 | 20 | @Id 21 | @GeneratedValue(strategy = GenerationType.IDENTITY) 22 | private Long id; 23 | @Column(name = "user_id") 24 | private String userId; 25 | 26 | 27 | @OneToMany( mappedBy = "cart", cascade = CascadeType.ALL, fetch = FetchType.LAZY ) 28 | private Set items = new HashSet<>(); 29 | 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/Repositories/ApplicationUserRepository.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.Repositories; 2 | 3 | import com.flamup.spring.Models.ApplicationUser; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import javax.transaction.Transactional; 8 | import java.util.Optional; 9 | 10 | @Repository 11 | @Transactional 12 | public interface ApplicationUserRepository extends JpaRepository { 13 | 14 | Optional findApplicationUsersByEmail(String email); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/Repositories/CartRepository.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.Repositories; 2 | 3 | import com.flamup.spring.Models.ShoppingCart; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import java.util.Optional; 7 | 8 | public interface CartRepository extends JpaRepository { 9 | 10 | public Optional findByUserId(String user_email); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/Repositories/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.Repositories; 2 | 3 | import com.flamup.spring.Models.OrderItem; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import java.util.List; 7 | import java.util.Optional; 8 | 9 | 10 | public interface OrderRepository extends JpaRepository { 11 | 12 | public List findByCart_Id(Long cart_id); 13 | 14 | public Optional findById(String id); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/Repositories/ProductRepository.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.Repositories; 2 | 3 | import com.flamup.spring.Models.Product; 4 | import org.springframework.data.domain.Page; 5 | import org.springframework.data.domain.Pageable; 6 | import org.springframework.data.jpa.repository.JpaRepository; 7 | import org.springframework.data.jpa.repository.Query; 8 | import org.springframework.data.repository.query.Param; 9 | import org.springframework.stereotype.Repository; 10 | 11 | import javax.transaction.Transactional; 12 | import java.util.List; 13 | import java.util.Optional; 14 | 15 | @Repository 16 | @Transactional 17 | public interface ProductRepository extends JpaRepository { 18 | 19 | 20 | Optional findProductById( Long id); 21 | 22 | @Query("select p from Product p where LOWER(p.b_dresstype) LIKE LOWER(CONCAT('%', :type, '%'))") 23 | List findProductsByB_Dresstype(@Param("type") String type); 24 | 25 | @Query(value = "select p from Product p where LOWER(p.a_sex)=lower(:sex) order by p.e_arrival desc ") 26 | Page findProductByA_sex(@Param("sex") String sex, Pageable paging); 27 | 28 | @Query(value = "select p from Product p where LOWER(p.e_arrival)=LOWER(:arrival) and LOWER(p.a_sex)=LOWER(:sex)") 29 | List findProductsByE_arrivalAndA_sex(@Param("arrival") String arrival, @Param("sex") String sex); 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/Services/CartService.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.Services; 2 | 3 | import com.flamup.spring.DTO.OrderDTO; 4 | import com.flamup.spring.DTO.UpdateOrderDTO; 5 | import com.flamup.spring.Models.OrderItem; 6 | import com.flamup.spring.Models.Product; 7 | import com.flamup.spring.Models.ShoppingCart; 8 | import com.flamup.spring.Repositories.CartRepository; 9 | import com.flamup.spring.Repositories.OrderRepository; 10 | import com.flamup.spring.Repositories.ProductRepository; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.security.core.context.SecurityContextHolder; 13 | import org.springframework.security.core.userdetails.UserDetails; 14 | import org.springframework.stereotype.Service; 15 | 16 | import java.util.*; 17 | 18 | 19 | @Service 20 | public class CartService { 21 | 22 | private final CartRepository cartRepository; 23 | private final ProductRepository productRepository; 24 | private final OrderRepository orderRepository; 25 | 26 | 27 | @Autowired 28 | public CartService(CartRepository cartRepository, 29 | ProductRepository productRepository, 30 | OrderRepository orderRepository 31 | ) { 32 | this.cartRepository = cartRepository; 33 | this.productRepository = productRepository; 34 | this.orderRepository = orderRepository; 35 | } 36 | 37 | public String addToCart(OrderDTO order){ 38 | Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); 39 | 40 | if ( principal instanceof UserDetails) { 41 | 42 | Optional cartFromRepo = cartRepository.findByUserId(((UserDetails) principal).getUsername()); 43 | ShoppingCart cart; 44 | if ( ! cartFromRepo.isPresent() ){ 45 | cart = new ShoppingCart(); 46 | cart.setUserId(((UserDetails) principal).getUsername()); 47 | cartRepository.save(cart); 48 | } 49 | else{ 50 | cart = cartFromRepo.get(); 51 | } 52 | 53 | OrderItem item = new OrderItem(); 54 | Product pt = productRepository.findProductById(order.getProductId()) 55 | .orElseThrow( () -> new IllegalStateException("product not found")); 56 | item.fromDto(pt, cart, order.getQuantity()); 57 | 58 | orderRepository.save(item); 59 | return "SUCCESS"; 60 | } 61 | else{ 62 | throw new IllegalStateException("user not authenticated"); 63 | } 64 | } 65 | 66 | 67 | private Integer sanitizePrice( String price) { 68 | // price with Rs.2,244 --> 2244 69 | price = price.substring(3).replace(",", ""); 70 | return Integer.parseInt(price); 71 | } 72 | 73 | 74 | 75 | public HashMap getProducts(){ 76 | Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); 77 | HashMap hs = new HashMap<>(); 78 | hs.put("products" , new ArrayList<>()); 79 | hs.put("total" , 0); 80 | if ( principal instanceof UserDetails) { 81 | Optional cartFromRepo = cartRepository.findByUserId(((UserDetails) principal).getUsername()); 82 | ShoppingCart cart; 83 | if ( ! cartFromRepo.isPresent() ){ 84 | return hs; 85 | } 86 | cart = cartFromRepo.get(); 87 | ArrayList orders = new ArrayList<>(orderRepository.findByCart_Id(cart.getId())); 88 | hs.put("products" , orders); 89 | int price =0; 90 | for ( OrderItem order : orders ){ 91 | if ( order.getProduct().getE_arrival().toLowerCase(Locale.ROOT).equals("old")){ 92 | price += order.getQuantity() * order.getProduct().getF_discount(); 93 | } 94 | else { 95 | price += order.getQuantity() * sanitizePrice(order.getProduct().getD_price()); 96 | } 97 | } 98 | hs.put("total", price); 99 | return hs; 100 | } 101 | else{ 102 | throw new IllegalStateException("user not authenticated"); 103 | } 104 | } 105 | 106 | 107 | 108 | public String updateOrder(UpdateOrderDTO updateOrderDTO){ 109 | OrderItem item = orderRepository.findById(updateOrderDTO.getId()) 110 | .orElseThrow(()->new IllegalStateException("order does not exist")); 111 | 112 | item.setQuantity(updateOrderDTO.getQuantity()); 113 | orderRepository.save(item); 114 | return "SUCCESS"; 115 | } 116 | 117 | 118 | public String deleteOrder( String id){ 119 | OrderItem item = orderRepository.findById(id) 120 | .orElseThrow(()->new IllegalStateException("order does not exist")); 121 | orderRepository.delete(item); 122 | return "DELETED"; 123 | } 124 | 125 | 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/Services/CustomLogoutHandler.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.Services; 2 | 3 | import org.springframework.security.core.Authentication; 4 | import org.springframework.security.web.authentication.logout.LogoutHandler; 5 | import org.springframework.stereotype.Service; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | @Service 11 | public class CustomLogoutHandler implements LogoutHandler { 12 | 13 | @Override 14 | public void logout(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) { 15 | authentication.setAuthenticated(false); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/Services/ProductService.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.Services; 2 | 3 | import com.flamup.spring.Models.Product; 4 | import com.flamup.spring.Repositories.ProductRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.data.domain.Page; 7 | import org.springframework.data.domain.PageRequest; 8 | import org.springframework.data.domain.Pageable; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.ArrayList; 12 | import java.util.HashMap; 13 | import java.util.List; 14 | import java.util.Map; 15 | 16 | 17 | @Service 18 | public class ProductService { 19 | 20 | private final ProductRepository productRepository; 21 | 22 | @Autowired 23 | public ProductService(ProductRepository productRepository) { 24 | this.productRepository = productRepository; 25 | } 26 | 27 | // public Product getByDressType( String dresstype ){ 28 | // return productRepository.findProductByB_dresstype(dresstype) 29 | // .orElseThrow(() -> new IllegalStateException("Dress not found")); 30 | // } 31 | 32 | public List getProductsByDressType( String dresstype){ 33 | return productRepository.findProductsByB_Dresstype(dresstype); 34 | } 35 | 36 | 37 | public HashMap getProductsBySex(String sex, Integer pageSize, Integer page, Map countBySex){ 38 | 39 | Pageable paging = PageRequest.of(page , pageSize); 40 | Page prods = productRepository.findProductByA_sex(sex, paging); 41 | List newProds = productRepository.findProductsByE_arrivalAndA_sex("new" ,sex); 42 | Integer totalPages = prods.getTotalPages(); 43 | List products = prods.getContent(); 44 | products = rearrange(products, countBySex, newProds); 45 | Integer current = page; 46 | HashMap hs = new HashMap<>(); 47 | hs.put("current" , current); 48 | hs.put("products" , products); 49 | hs.put("total" , totalPages); 50 | return hs; 51 | 52 | } 53 | 54 | 55 | private List rearrange( List products, Map countBySex, List newProds){ 56 | 57 | List ll = new ArrayList<>(products); 58 | Product ptemp = ll.get(0); 59 | ll.remove(ptemp); 60 | ll.add(0, newProds.get(0)); 61 | 62 | 63 | if ( (long)( countBySex.get(true) + countBySex.get(false) ) == 0){ 64 | return ll; 65 | } 66 | 67 | Integer toShift = 68 | (int)(long)( (double) countBySex.get(false) / (countBySex.get(true) + countBySex.get(false)) * products.size()) ; 69 | 70 | System.out.println("toShift" + toShift); 71 | int pivot = Math.max( 0 , (int) (Math.random() * 50) - 5 ); 72 | for ( int start =0; start < Math.min(Math.min(Math.min( products.size() , toShift), newProds.size() ), 7) ; start++){ 73 | Product p = ll.get(start ); 74 | ll.remove(p); 75 | ll.add(0, newProds.get(start + pivot )); 76 | } 77 | return ll; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/Services/RegistrationService.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.Services; 2 | 3 | import com.flamup.spring.Models.RegistrationRequest; 4 | import com.flamup.spring.Models.AppUserRole; 5 | import com.flamup.spring.auth.AppUserService; 6 | import com.flamup.spring.Models.ApplicationUser; 7 | import lombok.AllArgsConstructor; 8 | import org.springframework.stereotype.Service; 9 | 10 | import java.util.Locale; 11 | 12 | @Service 13 | @AllArgsConstructor 14 | public class RegistrationService { 15 | 16 | private final AppUserService appUserService; 17 | 18 | 19 | public String register(RegistrationRequest request){ 20 | ApplicationUser.Gender gender = ApplicationUser.Gender.MALE; 21 | if ( request.getGender().toUpperCase(Locale.ROOT).equals("MALE")){ 22 | gender = ApplicationUser.Gender.MALE; 23 | } 24 | else if ( request.getGender().toUpperCase(Locale.ROOT).equals("FEMALE")){ 25 | gender = ApplicationUser.Gender.FEMALE; 26 | } 27 | else{ 28 | throw new IllegalStateException("GENDER SHOULD BE ONE OF MALE/FEMALE. There are only two genders!!"); 29 | } 30 | 31 | 32 | return appUserService.signupUser( new ApplicationUser( 33 | request.getFirstName(), 34 | request.getLastName(), 35 | request.getUserName(), 36 | request.getPassword(), 37 | request.getEmail(), 38 | AppUserRole.USER, 39 | gender 40 | )); 41 | 42 | 43 | } 44 | 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/auth/AppUserService.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.auth; 2 | 3 | import com.flamup.spring.Models.ApplicationUser; 4 | import com.flamup.spring.Repositories.ApplicationUserRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.security.core.userdetails.UserDetails; 7 | import org.springframework.security.core.userdetails.UserDetailsService; 8 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 9 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 10 | import org.springframework.stereotype.Service; 11 | 12 | import java.util.Optional; 13 | 14 | @Service 15 | public class AppUserService implements UserDetailsService { 16 | 17 | 18 | private final static String USER_NOT_FOUND_MSG = 19 | "user with email %s not found"; 20 | 21 | private final ApplicationUserRepository applicationUserRepository; 22 | private final BCryptPasswordEncoder bCryptPasswordEncoder; 23 | 24 | @Autowired 25 | public AppUserService(ApplicationUserRepository applicationUserRepository, BCryptPasswordEncoder bCryptPasswordEncoder) { 26 | this.applicationUserRepository = applicationUserRepository; 27 | this.bCryptPasswordEncoder = bCryptPasswordEncoder; 28 | } 29 | 30 | @Override 31 | public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { 32 | return applicationUserRepository.findApplicationUsersByEmail(email) 33 | .orElseThrow(() -> new UsernameNotFoundException(String.format(USER_NOT_FOUND_MSG, email))); 34 | 35 | } 36 | 37 | 38 | 39 | 40 | public String signupUser( ApplicationUser applicationUser){ 41 | boolean userExists = applicationUserRepository 42 | .findApplicationUsersByEmail(applicationUser.getUsername()) 43 | .isPresent(); 44 | 45 | if ( userExists ){ 46 | throw new IllegalStateException("email already used, try logging in"); 47 | } 48 | 49 | String encodedPassword = bCryptPasswordEncoder.encode(applicationUser.getPassword()); 50 | applicationUser.setPassword(encodedPassword); 51 | 52 | System.out.println("IN appUserService" + applicationUser); 53 | applicationUserRepository.save(applicationUser); 54 | return "SUCCESS"; 55 | } 56 | 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/security/PasswordEncoder.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.security; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 6 | 7 | @Configuration 8 | public class PasswordEncoder { 9 | 10 | @Bean 11 | public BCryptPasswordEncoder bCryptPasswordEncoder(){ 12 | return new BCryptPasswordEncoder(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/security/RestAuthEntryPoint.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.security; 2 | 3 | import org.springframework.security.core.AuthenticationException; 4 | import org.springframework.security.web.AuthenticationEntryPoint; 5 | import org.springframework.stereotype.Component; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | 12 | @Component 13 | public class RestAuthEntryPoint implements AuthenticationEntryPoint { 14 | 15 | @Override 16 | public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException { 17 | httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED , "Unauthorized"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/security/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.security; 2 | 3 | 4 | 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import springfox.documentation.builders.ApiInfoBuilder; 8 | import springfox.documentation.builders.PathSelectors; 9 | import springfox.documentation.builders.RequestHandlerSelectors; 10 | import springfox.documentation.service.ApiInfo; 11 | import springfox.documentation.service.Contact; 12 | import springfox.documentation.spi.DocumentationType; 13 | import springfox.documentation.spring.web.plugins.Docket; 14 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 15 | 16 | @Configuration 17 | @EnableSwagger2 18 | public class SwaggerConfig { 19 | 20 | @Bean 21 | public Docket api(){ 22 | return new Docket(DocumentationType.SWAGGER_2) 23 | .apiInfo(getApiInfo()) 24 | .select() 25 | .apis(RequestHandlerSelectors.basePackage("com.flamup.spring")) 26 | .paths(PathSelectors.any()) 27 | .build(); 28 | } 29 | 30 | 31 | private ApiInfo getApiInfo() { 32 | Contact contact = new Contact("FlamUP", "http://flamUp.com", "contact.flamUp@gmail.com"); 33 | return new ApiInfoBuilder() 34 | .title("Ecommerce API") 35 | .description("Documentation Ecommerce api") 36 | .version("1.0.0") 37 | .license("Apache 2.0") 38 | .licenseUrl("http://www.apache.org/licenses/LICENSE-2.0") 39 | .contact(contact) 40 | .build(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/flamup/spring/security/WebSecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring.security; 2 | 3 | import com.flamup.spring.Services.CustomLogoutHandler; 4 | import com.flamup.spring.auth.AppUserService; 5 | import org.apache.catalina.Context; 6 | import org.apache.catalina.connector.Connector; 7 | import org.apache.coyote.http11.Http11NioProtocol; 8 | import org.apache.tomcat.util.descriptor.web.SecurityCollection; 9 | import org.apache.tomcat.util.descriptor.web.SecurityConstraint; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; 12 | import org.springframework.boot.web.servlet.server.ServletWebServerFactory; 13 | import org.springframework.context.annotation.Bean; 14 | import org.springframework.context.annotation.Configuration; 15 | import org.springframework.http.HttpStatus; 16 | import org.springframework.security.authentication.dao.DaoAuthenticationProvider; 17 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 18 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 19 | import org.springframework.security.config.annotation.web.builders.WebSecurity; 20 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 21 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 22 | import org.springframework.security.crypto.password.PasswordEncoder; 23 | import org.springframework.security.web.authentication.logout.HttpStatusReturningLogoutSuccessHandler; 24 | 25 | 26 | import javax.sql.DataSource; 27 | 28 | //import javax.sql.DataSource; 29 | 30 | import static com.flamup.spring.Models.AppUserRole.*; 31 | 32 | @Configuration 33 | @EnableWebSecurity 34 | public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 35 | 36 | private final PasswordEncoder passwordEncoder; 37 | private final AppUserService appUserService; 38 | 39 | @Autowired 40 | RestAuthEntryPoint restAuthEntryPoint; 41 | 42 | @Autowired 43 | DataSource dataSource; 44 | 45 | @Autowired 46 | private CustomLogoutHandler logoutHandler; 47 | 48 | @Autowired 49 | public WebSecurityConfig(PasswordEncoder passwordEncoder, AppUserService appUserService) { 50 | this.passwordEncoder = passwordEncoder; 51 | this.appUserService = appUserService; 52 | } 53 | 54 | @Override 55 | public void configure(WebSecurity registry) throws Exception { 56 | registry.ignoring() 57 | .antMatchers("/docs/**") 58 | .antMatchers("/actuator/**") 59 | .antMatchers("/swagger-ui.html") 60 | .antMatchers("/webjars/**"); 61 | } 62 | 63 | @Override 64 | protected void configure(AuthenticationManagerBuilder auth) throws Exception { 65 | auth.authenticationProvider(daoAuthenticationProvider()); 66 | 67 | } 68 | 69 | 70 | 71 | @Override 72 | protected void configure(HttpSecurity http) throws Exception { 73 | http. 74 | csrf().disable() 75 | .authorizeRequests() 76 | .antMatchers("/","/static/**", "index*", "/css/*", "/js/*","/media/*","*.ico","*.png").permitAll() 77 | .antMatchers("/api/register").permitAll() 78 | .antMatchers("/api/auth").permitAll() 79 | .antMatchers("/api/persist/**").authenticated() 80 | 81 | .antMatchers("/api/v1/**").authenticated() 82 | .antMatchers("/admin/api/**").hasRole(ADMIN.name()) 83 | .and() 84 | .exceptionHandling() 85 | .authenticationEntryPoint(restAuthEntryPoint) 86 | .and() 87 | .formLogin() 88 | .loginProcessingUrl("/api/login") 89 | .permitAll() 90 | .and() 91 | .logout() 92 | .logoutUrl("/api/logout") 93 | .invalidateHttpSession(true) 94 | .deleteCookies("JSESSIONID") 95 | .clearAuthentication(true) 96 | .addLogoutHandler(logoutHandler) 97 | .logoutSuccessHandler(new HttpStatusReturningLogoutSuccessHandler(HttpStatus.OK)); 98 | 99 | } 100 | 101 | 102 | 103 | 104 | @Bean 105 | public DaoAuthenticationProvider daoAuthenticationProvider(){ 106 | DaoAuthenticationProvider provider = new DaoAuthenticationProvider(); 107 | provider.setPasswordEncoder(passwordEncoder); 108 | provider.setUserDetailsService(appUserService); 109 | return provider; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | server.error.include-message=always 6 | server.error.include-binding-errors=always 7 | 8 | 9 | spring.datasource.url=jdbc:postgresql://db:5432/flamup 10 | spring.datasource.username=postgres 11 | spring.datasource.password=postgres 12 | 13 | spring.jpa.hibernate.ddl-auto=update 14 | spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect 15 | spring.jpa.properties.hibernate.format-sql=true 16 | spring.jpa.show-sql=true 17 | 18 | 19 | spring.session.jdbc.initialize-schema=always 20 | spring.session.jdbc.table-name=SPRING_SESSION 21 | spring.session.store-type=jdbc 22 | 23 | server.port=8443 24 | server.ssl.enabled=true 25 | server.ssl.key-alias=spring 26 | server.ssl.key-password=password 27 | server.ssl.key-store-type=jks 28 | server.ssl.key-store-password=password 29 | server.ssl.key-store=classpath:spring.jks 30 | -------------------------------------------------------------------------------- /src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # 2 | #server: 3 | # error: 4 | # include-message: always 5 | # include-binding-errors: always 6 | # 7 | # 8 | #spring: 9 | # datasource: 10 | ## password: papai120499 11 | ## url: jdbc:postgresql://localhost:5432/testdb 12 | ## username: shuvayan 13 | # url : jdbc:postgresql://${DB_SERVER}/${POSTGRES_DB} 14 | # username : ${POSTGRES_USER} 15 | # password : ${POSTGRES_PASSWORD} 16 | # 17 | # jpa: 18 | # hibernate: 19 | # ddl-auto: update 20 | # properties: 21 | # hibernate: 22 | # dialect: org.hibernate.dialect.PostgreSQLDialect 23 | # format_sql: true 24 | # jdbc: 25 | # lob: 26 | # non_contextual_creation: true 27 | # show-sql: true 28 | # 29 | # session: 30 | # store-type: jdbc 31 | # jdbc: 32 | # table-name: SPRING_SESSION 33 | # initialize-schema: always 34 | # 35 | # 36 | # 37 | # 38 | # 39 | # 40 | # 41 | # 42 | # 43 | ## mail: 44 | ## host: localhost 45 | ## port: 1025 46 | ## username: hello 47 | ## password: hello 48 | ## 49 | ## properties: 50 | ## mail: 51 | ## smtp: 52 | ## ssl: 53 | ## trust: "*" 54 | ## auth: true 55 | ## starttls: 56 | ## enable: true 57 | ## connectiontimeout: 5000 58 | ## timeout: 3000 59 | ## writetimeout: 5000 60 | -------------------------------------------------------------------------------- /src/main/resources/data-postgres.sql: -------------------------------------------------------------------------------- 1 | 2 | -- 3 | -- 4 | 5 | DROP TABLE IF EXISTS application_user; 6 | 7 | drop sequence if exists student_sequence; 8 | 9 | 10 | create table if not exists application_user ( 11 | id int8 not null, 12 | app_user_role varchar(255), 13 | email varchar(255), 14 | first_name varchar(255), 15 | gender varchar(255), 16 | last_name varchar(255), 17 | password varchar(255), 18 | username varchar(255), 19 | primary key (id) 20 | ); 21 | 22 | create table if not exists clothes 23 | ( 24 | id int not null 25 | constraint clothes_pk 26 | primary key, 27 | sex varchar, 28 | dresstype varchar not null, 29 | image varchar not null, 30 | price varchar not null, 31 | arrival varchar, 32 | discount varchar not null 33 | ); 34 | 35 | create sequence student_sequence start 1 increment 1; 36 | 37 | -- 38 | -- CREATE TABLE SPRING_SESSION ( 39 | -- PRIMARY_ID CHAR(36) NOT NULL, 40 | -- SESSION_ID CHAR(36) NOT NULL, 41 | -- CREATION_TIME BIGINT NOT NULL, 42 | -- LAST_ACCESS_TIME BIGINT NOT NULL, 43 | -- MAX_INACTIVE_INTERVAL INT NOT NULL, 44 | -- EXPIRY_TIME BIGINT NOT NULL, 45 | -- PRINCIPAL_NAME VARCHAR(100), 46 | -- CONSTRAINT SPRING_SESSION_PK PRIMARY KEY (PRIMARY_ID) 47 | -- ); 48 | -- 49 | -- CREATE UNIQUE INDEX SPRING_SESSION_IX1 ON SPRING_SESSION (SESSION_ID); 50 | -- CREATE INDEX SPRING_SESSION_IX2 ON SPRING_SESSION (EXPIRY_TIME); 51 | -- CREATE INDEX SPRING_SESSION_IX3 ON SPRING_SESSION (PRINCIPAL_NAME); 52 | -- 53 | -- CREATE TABLE SPRING_SESSION_ATTRIBUTES ( 54 | -- SESSION_PRIMARY_ID CHAR(36) NOT NULL, 55 | -- ATTRIBUTE_NAME VARCHAR(200) NOT NULL, 56 | -- ATTRIBUTE_BYTES BYTEA NOT NULL, 57 | -- CONSTRAINT SPRING_SESSION_ATTRIBUTES_PK PRIMARY KEY (SESSION_PRIMARY_ID, ATTRIBUTE_NAME), 58 | -- CONSTRAINT SPRING_SESSION_ATTRIBUTES_FK FOREIGN KEY (SESSION_PRIMARY_ID) REFERENCES SPRING_SESSION(PRIMARY_ID) ON DELETE CASCADE 59 | -- ); 60 | 61 | 62 | -------------------------------------------------------------------------------- /src/main/resources/spring.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheSYNcoder/Full-Stack-Ecommerce-Spring-Boot-React/dc42b58c3534759276621c7c9d3923e3961e8697/src/main/resources/spring.jks -------------------------------------------------------------------------------- /src/test/java/com/flamup/spring/ApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.flamup.spring; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class ApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /work.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | import json 3 | import random 4 | men_content = json.loads(open('men-data.json','r').read()) 5 | f_content = json.loads(open('female-data.json','r').read()) 6 | 7 | 8 | obj = { 9 | 'a_sex':[], 10 | 'dresstype':[], 11 | 'image':[], 12 | 'price':[], 13 | 'arrival':[], 14 | 'discount':[] 15 | } 16 | df = pd.DataFrame(obj) 17 | 18 | def sanitizePrice(price): 19 | price = price[3:].replace(',','') 20 | return int(price) 21 | 22 | 23 | for content in men_content: 24 | temp = pd.DataFrame( { 'a_sex' : ['MALE'] , 25 | 'dresstype' :[content['dressType']], 26 | 'image' : [content['image']], 27 | 'price' : [content['price']], 28 | 'arrival':[content['arrival']], 29 | 'discount': [content['price']] 30 | }) 31 | temp.iloc[0]['discount'] = random.randint( 100, min( 1500, sanitizePrice(content['price']))) 32 | 33 | df = df.append(temp, ignore_index = True) 34 | 35 | 36 | for content in f_content: 37 | temp = pd.DataFrame( { 'a_sex' : ['FEMALE'] , 38 | 'dresstype' :[content['dressType']], 39 | 'image' : [content['image']], 40 | 'price' : [content['price']], 41 | 'arrival':[content['arrival']], 42 | 'discount': [content['price']] 43 | }) 44 | temp.iloc[0]['discount'] = random.randint( 45 | 100, min(1500, sanitizePrice(content['price']))) 46 | 47 | df = df.append(temp, ignore_index = True) 48 | 49 | df.to_csv('data2.csv') 50 | 51 | 52 | --------------------------------------------------------------------------------