├── .github ├── dependabot.yml └── workflows │ └── maven.yml ├── .gitignore ├── .mvn └── wrapper │ ├── MavenWrapperDownloader.java │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── README.md ├── frontend ├── .editorconfig ├── .gitignore ├── README.md ├── angular.json ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.e2e.json ├── package-lock.json ├── package.json ├── proxy-conf.json ├── src │ ├── app │ │ ├── app-routing.module.ts │ │ ├── app.component.css │ │ ├── app.component.html │ │ ├── app.component.spec.ts │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ └── ecommerce │ │ │ ├── ecommerce.component.css │ │ │ ├── ecommerce.component.html │ │ │ ├── ecommerce.component.spec.ts │ │ │ ├── ecommerce.component.ts │ │ │ ├── models │ │ │ ├── product-order.model.ts │ │ │ ├── product-orders.model.ts │ │ │ └── product.model.ts │ │ │ ├── orders │ │ │ ├── orders.component.css │ │ │ ├── orders.component.html │ │ │ ├── orders.component.spec.ts │ │ │ └── orders.component.ts │ │ │ ├── products │ │ │ ├── products.component.css │ │ │ ├── products.component.html │ │ │ ├── products.component.spec.ts │ │ │ └── products.component.ts │ │ │ ├── services │ │ │ └── ecommerce.service.ts │ │ │ └── shopping-cart │ │ │ ├── shopping-cart.component.css │ │ │ ├── shopping-cart.component.html │ │ │ ├── shopping-cart.component.spec.ts │ │ │ └── shopping-cart.component.ts │ ├── assets │ │ └── .gitkeep │ ├── browserslist │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── karma.conf.js │ ├── main.ts │ ├── polyfills.ts │ ├── styles.css │ ├── test.ts │ ├── tsconfig.app.json │ ├── tsconfig.spec.json │ └── tslint.json ├── tsconfig.json └── tslint.json ├── img ├── checkout.png ├── home.png ├── order.png └── pay.png ├── mvnw ├── mvnw.cmd ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── hendisantika │ │ └── ecommerce │ │ └── springbootecommerce │ │ ├── SpringbootEcommerceApplication.java │ │ ├── controller │ │ ├── OrderController.java │ │ └── ProductController.java │ │ ├── dto │ │ └── OrderProductDto.java │ │ ├── exception │ │ ├── ApiExceptionHandler.java │ │ └── ResourceNotFoundException.java │ │ ├── model │ │ ├── Order.java │ │ ├── OrderProduct.java │ │ ├── OrderProductPK.java │ │ ├── OrderStatus.java │ │ └── Product.java │ │ ├── repository │ │ ├── OrderProductRepository.java │ │ ├── OrderRepository.java │ │ └── ProductRepository.java │ │ └── service │ │ ├── OrderProductService.java │ │ ├── OrderProductServiceImpl.java │ │ ├── OrderService.java │ │ ├── OrderServiceImpl.java │ │ ├── ProductService.java │ │ └── ProductServiceImpl.java └── resources │ ├── application.properties │ └── logback.xml └── test └── java └── com └── hendisantika └── ecommerce └── springbootecommerce ├── EcommerceApplicationIntegrationTest.java └── SpringbootEcommerceApplicationTests.java /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: maven 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: '05:00' 8 | timezone: Asia/Jakarta 9 | open-pull-requests-limit: 10 10 | - package-ecosystem: npm 11 | directory: "/frontend" 12 | schedule: 13 | interval: daily 14 | time: '05:00' 15 | timezone: Asia/Jakarta 16 | open-pull-requests-limit: 10 17 | - package-ecosystem: "github-actions" 18 | directory: "/" 19 | schedule: 20 | interval: "daily" 21 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven 3 | 4 | # This workflow uses actions that are not certified by GitHub. 5 | # They are provided by a third-party and are governed by 6 | # separate terms of service, privacy policy, and support 7 | # documentation. 8 | 9 | name: Java CI with Maven 10 | 11 | on: 12 | push: 13 | branches: [ "master" ] 14 | pull_request: 15 | branches: [ "master" ] 16 | 17 | jobs: 18 | build: 19 | 20 | runs-on: ubuntu-latest 21 | 22 | steps: 23 | - uses: actions/checkout@v4 24 | - name: Set up JDK 21 25 | uses: actions/setup-java@v4 26 | with: 27 | java-version: '21' 28 | distribution: 'temurin' 29 | cache: maven 30 | - name: Build with Maven 31 | run: mvn -B package --file pom.xml 32 | 33 | # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive 34 | - name: Update dependency graph 35 | uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | logs 16 | *.iws 17 | *.iml 18 | *.ipr 19 | 20 | ### NetBeans ### 21 | /nbproject/private/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ 26 | /build/ 27 | 28 | ### VS Code ### 29 | .vscode/ 30 | -------------------------------------------------------------------------------- /.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed to the Apache Software Foundation (ASF) under one 3 | or more contributor license agreements. See the NOTICE file 4 | distributed with this work for additional information 5 | regarding copyright ownership. The ASF licenses this file 6 | to you under the Apache License, Version 2.0 (the 7 | "License"); you may not use this file except in compliance 8 | with the License. You may obtain a copy of the License at 9 | 10 | https://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an 14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, either express or implied. See the License for the 16 | specific language governing permissions and limitations 17 | under the License. 18 | */ 19 | 20 | import java.io.File; 21 | import java.io.FileInputStream; 22 | import java.io.FileOutputStream; 23 | import java.io.IOException; 24 | import java.net.URL; 25 | import java.nio.channels.Channels; 26 | import java.nio.channels.ReadableByteChannel; 27 | import java.util.Properties; 28 | 29 | public class MavenWrapperDownloader { 30 | 31 | /** 32 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 33 | */ 34 | private static final String DEFAULT_DOWNLOAD_URL = 35 | "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; 36 | 37 | /** 38 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 39 | * use instead of the default one. 40 | */ 41 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 42 | ".mvn/wrapper/maven-wrapper.properties"; 43 | 44 | /** 45 | * Path where the maven-wrapper.jar will be saved to. 46 | */ 47 | private static final String MAVEN_WRAPPER_JAR_PATH = 48 | ".mvn/wrapper/maven-wrapper.jar"; 49 | 50 | /** 51 | * Name of the property which should be used to override the default download url for the wrapper. 52 | */ 53 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 54 | 55 | public static void main(String args[]) { 56 | System.out.println("- Downloader started"); 57 | File baseDirectory = new File(args[0]); 58 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 59 | 60 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 61 | // wrapperUrl parameter. 62 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 63 | String url = DEFAULT_DOWNLOAD_URL; 64 | if (mavenWrapperPropertyFile.exists()) { 65 | FileInputStream mavenWrapperPropertyFileInputStream = null; 66 | try { 67 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 68 | Properties mavenWrapperProperties = new Properties(); 69 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 70 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 71 | } catch (IOException e) { 72 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 73 | } finally { 74 | try { 75 | if (mavenWrapperPropertyFileInputStream != null) { 76 | mavenWrapperPropertyFileInputStream.close(); 77 | } 78 | } catch (IOException e) { 79 | // Ignore ... 80 | } 81 | } 82 | } 83 | System.out.println("- Downloading from: : " + url); 84 | 85 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 86 | if (!outputFile.getParentFile().exists()) { 87 | if (!outputFile.getParentFile().mkdirs()) { 88 | System.out.println( 89 | "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 90 | } 91 | } 92 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 93 | try { 94 | downloadFileFromURL(url, outputFile); 95 | System.out.println("Done"); 96 | System.exit(0); 97 | } catch (Throwable e) { 98 | System.out.println("- Error downloading"); 99 | e.printStackTrace(); 100 | System.exit(1); 101 | } 102 | } 103 | 104 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 105 | URL website = new URL(urlString); 106 | ReadableByteChannel rbc; 107 | rbc = Channels.newChannel(website.openStream()); 108 | FileOutputStream fos = new FileOutputStream(destination); 109 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 110 | fos.close(); 111 | rbc.close(); 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hendisantika/springboot-ecommerce/f32e457302a42414f67cc0f52c5ceac8e92b391c/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # springboot-ecommerce 2 | #### Spring Boot Angular 3 | A Simple E-Commerce Implementation with Spring 4 | 5 | This module contains articles about Spring Boot with Angular 6 | 7 | #### Technology Stacks 8 | 1. Java 8 9 | 2. Maven 3.6.3 10 | 3. IntelliJ Ultimate 2020.1 11 | 4. NodeJS v14.2.0 12 | 5. NPM 6.14.5 13 | 6. Angular CLI: 7.3.10 14 | 7. Angular: 7.2.16 15 | 8. H2 Database 16 | 9. Spring Boot Stack 17 | 18 | ### Things todo list: 19 | 1. Clone this repository: `git clone https://github.com/hendisantika/springboot-ecommerce.git` 20 | 2. Go inside the folder: `cd springboot-ecommerce` 21 | 3. Run the backend application: `mvn clean spring-boot:run` 22 | 4. Run Angular Application: `cd frontend && npm run start` 23 | 5. Open your favorite browser: http://localhost:4200 24 | 25 | ### Screen shot 26 | 27 | Home Page 28 | 29 | ![Home Page](img/home.png "Home Page") 30 | 31 | Order Page 32 | 33 | ![Order Page](img/order.png "Order Page") 34 | 35 | Checkout Page 36 | 37 | ![Checkout Page](img/checkout.png "Checkout Page") 38 | 39 | Pay order Page 40 | 41 | ![Pay order Page](img/pay.png "Pay order Page") -------------------------------------------------------------------------------- /frontend/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | 8 | # dependencies 9 | /node_modules 10 | 11 | # profiling files 12 | chrome-profiler-events.json 13 | speed-measure-plugin.json 14 | 15 | # IDEs and editors 16 | /.idea 17 | .project 18 | .classpath 19 | .c9/ 20 | *.launch 21 | .settings/ 22 | *.sublime-workspace 23 | 24 | # IDE - VSCode 25 | .vscode/* 26 | !.vscode/settings.json 27 | !.vscode/tasks.json 28 | !.vscode/launch.json 29 | !.vscode/extensions.json 30 | .history/* 31 | 32 | # misc 33 | /.sass-cache 34 | /connect.lock 35 | /coverage 36 | /libpeerconnection.log 37 | npm-debug.log 38 | yarn-error.log 39 | testem.log 40 | /typings 41 | 42 | # System Files 43 | .DS_Store 44 | Thumbs.db 45 | -------------------------------------------------------------------------------- /frontend/README.md: -------------------------------------------------------------------------------- 1 | # Frontend 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 7.3.0. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 28 | -------------------------------------------------------------------------------- /frontend/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "frontend": { 7 | "root": "", 8 | "sourceRoot": "src", 9 | "projectType": "application", 10 | "prefix": "app", 11 | "schematics": {}, 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/frontend", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "src/tsconfig.app.json", 21 | "assets": [ 22 | "src/favicon.ico", 23 | "src/assets" 24 | ], 25 | "styles": [ 26 | "src/styles.css", 27 | "node_modules/bootstrap/dist/css/bootstrap.min.css" 28 | ], 29 | "scripts": [], 30 | "es5BrowserSupport": true 31 | }, 32 | "configurations": { 33 | "production": { 34 | "fileReplacements": [ 35 | { 36 | "replace": "src/environments/environment.ts", 37 | "with": "src/environments/environment.prod.ts" 38 | } 39 | ], 40 | "optimization": true, 41 | "outputHashing": "all", 42 | "sourceMap": false, 43 | "extractCss": true, 44 | "namedChunks": false, 45 | "aot": true, 46 | "extractLicenses": true, 47 | "vendorChunk": false, 48 | "buildOptimizer": true, 49 | "budgets": [ 50 | { 51 | "type": "initial", 52 | "maximumWarning": "2mb", 53 | "maximumError": "5mb" 54 | } 55 | ] 56 | } 57 | } 58 | }, 59 | "serve": { 60 | "builder": "@angular-devkit/build-angular:dev-server", 61 | "options": { 62 | "browserTarget": "frontend:build" 63 | }, 64 | "configurations": { 65 | "production": { 66 | "browserTarget": "frontend:build:production" 67 | } 68 | } 69 | }, 70 | "extract-i18n": { 71 | "builder": "@angular-devkit/build-angular:extract-i18n", 72 | "options": { 73 | "browserTarget": "frontend:build" 74 | } 75 | }, 76 | "test": { 77 | "builder": "@angular-devkit/build-angular:karma", 78 | "options": { 79 | "main": "src/test.ts", 80 | "polyfills": "src/polyfills.ts", 81 | "tsConfig": "src/tsconfig.spec.json", 82 | "karmaConfig": "src/karma.conf.js", 83 | "styles": [ 84 | "src/styles.css" 85 | ], 86 | "scripts": [], 87 | "assets": [ 88 | "src/favicon.ico", 89 | "src/assets" 90 | ] 91 | } 92 | }, 93 | "lint": { 94 | "builder": "@angular-devkit/build-angular:tslint", 95 | "options": { 96 | "tsConfig": [ 97 | "src/tsconfig.app.json", 98 | "src/tsconfig.spec.json" 99 | ], 100 | "exclude": [ 101 | "**/node_modules/**" 102 | ] 103 | } 104 | } 105 | } 106 | }, 107 | "frontend-e2e": { 108 | "root": "e2e/", 109 | "projectType": "application", 110 | "prefix": "", 111 | "architect": { 112 | "e2e": { 113 | "builder": "@angular-devkit/build-angular:protractor", 114 | "options": { 115 | "protractorConfig": "e2e/protractor.conf.js", 116 | "devServerTarget": "frontend:serve" 117 | }, 118 | "configurations": { 119 | "production": { 120 | "devServerTarget": "frontend:serve:production" 121 | } 122 | } 123 | }, 124 | "lint": { 125 | "builder": "@angular-devkit/build-angular:tslint", 126 | "options": { 127 | "tsConfig": "e2e/tsconfig.e2e.json", 128 | "exclude": [ 129 | "**/node_modules/**" 130 | ] 131 | } 132 | } 133 | } 134 | } 135 | }, 136 | "defaultProject": "frontend" 137 | } 138 | -------------------------------------------------------------------------------- /frontend/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const {SpecReporter} = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './src/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function () { 21 | } 22 | }, 23 | onPrepare() { 24 | require('ts-node').register({ 25 | project: require('path').join(__dirname, './tsconfig.e2e.json') 26 | }); 27 | jasmine.getEnv().addReporter(new SpecReporter({spec: {displayStacktrace: true}})); 28 | } 29 | }; 30 | -------------------------------------------------------------------------------- /frontend/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import {AppPage} from './app.po'; 2 | import {browser, logging} from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('Welcome to frontend!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | })); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /frontend/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import {browser, by, element} from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText() { 9 | return element(by.css('app-root h1')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /frontend/e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } -------------------------------------------------------------------------------- /frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve --proxy-config proxy-conf.json", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "~7.2.0", 15 | "@angular/common": "~7.2.0", 16 | "@angular/compiler": "~7.2.0", 17 | "@angular/core": "~11.0.5", 18 | "@angular/forms": "~7.2.0", 19 | "@angular/platform-browser": "~7.2.0", 20 | "@angular/platform-browser-dynamic": "~7.2.0", 21 | "@angular/router": "~7.2.0", 22 | "bootstrap": "^5.0.0", 23 | "core-js": "^2.5.4", 24 | "rxjs": "~6.3.3", 25 | "tslib": "^1.9.0", 26 | "zone.js": "~0.8.26" 27 | }, 28 | "devDependencies": { 29 | "@angular-devkit/build-angular": "~20.0.1", 30 | "@angular/cli": "~15.0.0", 31 | "@angular/compiler-cli": "~15.0.0", 32 | "@angular/language-service": "~7.2.0", 33 | "@types/node": "~8.9.4", 34 | "@types/jasmine": "~2.8.8", 35 | "@types/jasminewd2": "~2.0.3", 36 | "codelyzer": "~4.5.0", 37 | "jasmine-core": "~2.99.1", 38 | "jasmine-spec-reporter": "~4.2.1", 39 | "karma": "~6.3.16", 40 | "karma-chrome-launcher": "~2.2.0", 41 | "karma-coverage-istanbul-reporter": "~2.0.1", 42 | "karma-jasmine": "~1.1.2", 43 | "karma-jasmine-html-reporter": "^0.2.2", 44 | "protractor": "~7.0.0", 45 | "ts-node": "~7.0.0", 46 | "tslint": "~5.11.0", 47 | "typescript": "~3.2.2" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /frontend/proxy-conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "/api": { 3 | "target": "http://localhost:8080", 4 | "secure": false 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /frontend/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import {NgModule} from '@angular/core'; 2 | import {RouterModule, Routes} from '@angular/router'; 3 | 4 | const routes: Routes = []; 5 | 6 | @NgModule({ 7 | imports: [RouterModule.forRoot(routes)], 8 | exports: [RouterModule] 9 | }) 10 | export class AppRoutingModule { 11 | } 12 | -------------------------------------------------------------------------------- /frontend/src/app/app.component.css: -------------------------------------------------------------------------------- 1 | .container { 2 | padding-top: 65px; 3 | } 4 | -------------------------------------------------------------------------------- /frontend/src/app/app.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | -------------------------------------------------------------------------------- /frontend/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import {async, TestBed} from '@angular/core/testing'; 2 | import {RouterTestingModule} from '@angular/router/testing'; 3 | import {AppComponent} from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async(() => { 7 | TestBed.configureTestingModule({ 8 | imports: [ 9 | RouterTestingModule 10 | ], 11 | declarations: [ 12 | AppComponent 13 | ], 14 | }).compileComponents(); 15 | })); 16 | 17 | it('should create the app', () => { 18 | const fixture = TestBed.createComponent(AppComponent); 19 | const app = fixture.debugElement.componentInstance; 20 | expect(app).toBeTruthy(); 21 | }); 22 | 23 | it(`should have as title 'frontend'`, () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.debugElement.componentInstance; 26 | expect(app.title).toEqual('frontend'); 27 | }); 28 | 29 | it('should render title in a h1 tag', () => { 30 | const fixture = TestBed.createComponent(AppComponent); 31 | fixture.detectChanges(); 32 | const compiled = fixture.debugElement.nativeElement; 33 | expect(compiled.querySelector('h1').textContent).toContain('Welcome to frontend!'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /frontend/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import {Component} from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.css'] 7 | }) 8 | export class AppComponent { 9 | title = 'frontend'; 10 | } 11 | -------------------------------------------------------------------------------- /frontend/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import {BrowserModule} from '@angular/platform-browser'; 2 | import {NgModule} from '@angular/core'; 3 | 4 | import {AppRoutingModule} from './app-routing.module'; 5 | import {AppComponent} from './app.component'; 6 | import {EcommerceComponent} from './ecommerce/ecommerce.component'; 7 | import {ProductsComponent} from './ecommerce/products/products.component'; 8 | import {OrdersComponent} from './ecommerce/orders/orders.component'; 9 | import {ShoppingCartComponent} from './ecommerce/shopping-cart/shopping-cart.component'; 10 | import {FormsModule, ReactiveFormsModule} from "@angular/forms"; 11 | import {HttpClientModule} from "@angular/common/http"; 12 | import {EcommerceService} from "./ecommerce/services/ecommerce.service"; 13 | 14 | @NgModule({ 15 | declarations: [ 16 | AppComponent, 17 | EcommerceComponent, 18 | ProductsComponent, 19 | OrdersComponent, 20 | ShoppingCartComponent 21 | ], 22 | imports: [ 23 | BrowserModule, 24 | HttpClientModule, 25 | ReactiveFormsModule, 26 | AppRoutingModule, 27 | FormsModule 28 | ], 29 | providers: [EcommerceService], 30 | bootstrap: [AppComponent] 31 | }) 32 | export class AppModule { 33 | } 34 | -------------------------------------------------------------------------------- /frontend/src/app/ecommerce/ecommerce.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hendisantika/springboot-ecommerce/f32e457302a42414f67cc0f52c5ceac8e92b391c/frontend/src/app/ecommerce/ecommerce.component.css -------------------------------------------------------------------------------- /frontend/src/app/ecommerce/ecommerce.component.html: -------------------------------------------------------------------------------- 1 | 22 | 23 |
24 |
25 | 26 |
27 |
28 | 30 |
31 |
32 | 33 |
34 |
35 | -------------------------------------------------------------------------------- /frontend/src/app/ecommerce/ecommerce.component.spec.ts: -------------------------------------------------------------------------------- 1 | import {async, ComponentFixture, TestBed} from '@angular/core/testing'; 2 | 3 | import {EcommerceComponent} from './ecommerce.component'; 4 | 5 | describe('EcommerceComponent', () => { 6 | let component: EcommerceComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [EcommerceComponent] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(EcommerceComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /frontend/src/app/ecommerce/ecommerce.component.ts: -------------------------------------------------------------------------------- 1 | import {Component, OnInit, ViewChild} from '@angular/core'; 2 | import {ProductsComponent} from "./products/products.component"; 3 | import {ShoppingCartComponent} from "./shopping-cart/shopping-cart.component"; 4 | import {OrdersComponent} from "./orders/orders.component"; 5 | 6 | @Component({ 7 | selector: 'app-ecommerce', 8 | templateUrl: './ecommerce.component.html', 9 | styleUrls: ['./ecommerce.component.css'] 10 | }) 11 | export class EcommerceComponent implements OnInit { 12 | 13 | constructor() { 14 | } 15 | 16 | ngOnInit() { 17 | } 18 | 19 | orderFinished = false; 20 | @ViewChild('productsC') 21 | productsC: ProductsComponent; 22 | @ViewChild('shoppingCartC') 23 | shoppingCartC: ShoppingCartComponent; 24 | @ViewChild('ordersC') 25 | ordersC: OrdersComponent; 26 | private collapsed = true; 27 | 28 | toggleCollapsed(): void { 29 | this.collapsed = !this.collapsed; 30 | } 31 | 32 | finishOrder(orderFinished: boolean) { 33 | this.orderFinished = orderFinished; 34 | } 35 | 36 | reset() { 37 | this.orderFinished = false; 38 | this.productsC.reset(); 39 | this.shoppingCartC.reset(); 40 | this.ordersC.paid = false; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /frontend/src/app/ecommerce/models/product-order.model.ts: -------------------------------------------------------------------------------- 1 | import {Product} from "./product.model"; 2 | 3 | export class ProductOrder { 4 | product: Product; 5 | quantity: number; 6 | 7 | constructor(product: Product, quantity: number) { 8 | this.product = product; 9 | this.quantity = quantity; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /frontend/src/app/ecommerce/models/product-orders.model.ts: -------------------------------------------------------------------------------- 1 | import {ProductOrder} from "./product-order.model"; 2 | 3 | export class ProductOrders { 4 | productOrders: ProductOrder[] = []; 5 | } 6 | -------------------------------------------------------------------------------- /frontend/src/app/ecommerce/models/product.model.ts: -------------------------------------------------------------------------------- 1 | export class Product { 2 | id: number; 3 | name: string; 4 | price: number; 5 | pictureUrl: string; 6 | 7 | constructor(id: number, name: string, price: number, pictureUrl: string) { 8 | this.id = id; 9 | this.name = name; 10 | this.price = price; 11 | this.pictureUrl = pictureUrl; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /frontend/src/app/ecommerce/orders/orders.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hendisantika/springboot-ecommerce/f32e457302a42414f67cc0f52c5ceac8e92b391c/frontend/src/app/ecommerce/orders/orders.component.css -------------------------------------------------------------------------------- /frontend/src/app/ecommerce/orders/orders.component.html: -------------------------------------------------------------------------------- 1 |

ORDER

2 |
    3 |
  • 4 | {{ order.product.name }} - ${{ order.product.price }} x {{ order.quantity}} pcs. 5 |
  • 6 |
7 |

Total amount: ${{ total }}

8 | 9 | 10 | 13 | -------------------------------------------------------------------------------- /frontend/src/app/ecommerce/orders/orders.component.spec.ts: -------------------------------------------------------------------------------- 1 | import {async, ComponentFixture, TestBed} from '@angular/core/testing'; 2 | 3 | import {OrdersComponent} from './orders.component'; 4 | 5 | describe('OrdersComponent', () => { 6 | let component: OrdersComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [OrdersComponent] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(OrdersComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /frontend/src/app/ecommerce/orders/orders.component.ts: -------------------------------------------------------------------------------- 1 | import {Component, OnInit} from '@angular/core'; 2 | import {EcommerceService} from "../services/ecommerce.service"; 3 | import {Subscription} from "rxjs"; 4 | import {ProductOrders} from "../models/product-orders.model"; 5 | 6 | @Component({ 7 | selector: 'app-orders', 8 | templateUrl: './orders.component.html', 9 | styleUrls: ['./orders.component.css'] 10 | }) 11 | export class OrdersComponent implements OnInit { 12 | 13 | orders: ProductOrders; 14 | total: number; 15 | paid: boolean; 16 | sub: Subscription; 17 | 18 | constructor(private ecommerceService: EcommerceService) { 19 | this.orders = this.ecommerceService.ProductOrders; 20 | } 21 | 22 | ngOnInit() { 23 | this.paid = false; 24 | this.sub = this.ecommerceService.OrdersChanged.subscribe(() => { 25 | this.orders = this.ecommerceService.ProductOrders; 26 | }); 27 | this.loadTotal(); 28 | } 29 | 30 | pay() { 31 | this.paid = true; 32 | this.ecommerceService.saveOrder(this.orders).subscribe(); 33 | } 34 | 35 | 36 | loadTotal() { 37 | this.sub = this.ecommerceService.TotalChanged.subscribe(() => { 38 | this.total = this.ecommerceService.Total; 39 | }); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /frontend/src/app/ecommerce/products/products.component.css: -------------------------------------------------------------------------------- 1 | .padding-0 { 2 | padding-right: 0; 3 | padding-left: 1; 4 | } 5 | -------------------------------------------------------------------------------- /frontend/src/app/ecommerce/products/products.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 |

{{order.product.name}}

6 |
7 |
8 | 9 |
${{order.product.price}}
10 |
11 |
12 | 13 |
14 |
15 | 18 |
19 |
20 | 23 |
24 |
25 |
26 |
27 |
28 |
29 | © 2020 GitHub, Inc. 30 | -------------------------------------------------------------------------------- /frontend/src/app/ecommerce/products/products.component.spec.ts: -------------------------------------------------------------------------------- 1 | import {async, ComponentFixture, TestBed} from '@angular/core/testing'; 2 | 3 | import {ProductsComponent} from './products.component'; 4 | 5 | describe('ProductsComponent', () => { 6 | let component: ProductsComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ProductsComponent] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ProductsComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /frontend/src/app/ecommerce/products/products.component.ts: -------------------------------------------------------------------------------- 1 | import {Component, OnInit} from '@angular/core'; 2 | import {ProductOrder} from "../models/product-order.model"; 3 | import {EcommerceService} from "../services/ecommerce.service"; 4 | import {Subscription} from "rxjs"; 5 | import {ProductOrders} from "../models/product-orders.model"; 6 | import {Product} from "../models/product.model"; 7 | 8 | @Component({ 9 | selector: 'app-products', 10 | templateUrl: './products.component.html', 11 | styleUrls: ['./products.component.css'] 12 | }) 13 | export class ProductsComponent implements OnInit { 14 | 15 | productOrders: ProductOrder[] = []; 16 | products: Product[] = []; 17 | selectedProductOrder: ProductOrder; 18 | private shoppingCartOrders: ProductOrders; 19 | sub: Subscription; 20 | productSelected: boolean = false; 21 | 22 | constructor(private ecommerceService: EcommerceService) { 23 | } 24 | 25 | ngOnInit() { 26 | this.productOrders = []; 27 | this.loadProducts(); 28 | this.loadOrders(); 29 | } 30 | 31 | addToCart(order: ProductOrder) { 32 | this.ecommerceService.SelectedProductOrder = order; 33 | this.selectedProductOrder = this.ecommerceService.SelectedProductOrder; 34 | this.productSelected = true; 35 | } 36 | 37 | removeFromCart(productOrder: ProductOrder) { 38 | let index = this.getProductIndex(productOrder.product); 39 | if (index > -1) { 40 | this.shoppingCartOrders.productOrders.splice( 41 | this.getProductIndex(productOrder.product), 1); 42 | } 43 | this.ecommerceService.ProductOrders = this.shoppingCartOrders; 44 | this.shoppingCartOrders = this.ecommerceService.ProductOrders; 45 | this.productSelected = false; 46 | } 47 | 48 | getProductIndex(product: Product): number { 49 | return this.ecommerceService.ProductOrders.productOrders.findIndex( 50 | value => value.product === product); 51 | } 52 | 53 | isProductSelected(product: Product): boolean { 54 | return this.getProductIndex(product) > -1; 55 | } 56 | 57 | loadProducts() { 58 | this.ecommerceService.getAllProducts() 59 | .subscribe( 60 | (products: any[]) => { 61 | this.products = products; 62 | this.products.forEach(product => { 63 | this.productOrders.push(new ProductOrder(product, 0)); 64 | }) 65 | }, 66 | (error) => console.log(error) 67 | ); 68 | } 69 | 70 | loadOrders() { 71 | this.sub = this.ecommerceService.OrdersChanged.subscribe(() => { 72 | this.shoppingCartOrders = this.ecommerceService.ProductOrders; 73 | }); 74 | } 75 | 76 | reset() { 77 | this.productOrders = []; 78 | this.loadProducts(); 79 | this.ecommerceService.ProductOrders.productOrders = []; 80 | this.loadOrders(); 81 | this.productSelected = false; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /frontend/src/app/ecommerce/services/ecommerce.service.ts: -------------------------------------------------------------------------------- 1 | import {Injectable} from '@angular/core'; 2 | import {Subject} from "rxjs"; 3 | import {ProductOrders} from "../models/product-orders.model"; 4 | import {HttpClient} from "@angular/common/http"; 5 | import {ProductOrder} from "../models/product-order.model"; 6 | 7 | @Injectable() 8 | export class EcommerceService { 9 | private productsUrl = "/api/products"; 10 | private ordersUrl = "/api/orders"; 11 | 12 | private productOrder: ProductOrder; 13 | private orders: ProductOrders = new ProductOrders(); 14 | 15 | private productOrderSubject = new Subject(); 16 | private ordersSubject = new Subject(); 17 | private totalSubject = new Subject(); 18 | 19 | private total: number; 20 | 21 | ProductOrderChanged = this.productOrderSubject.asObservable(); 22 | OrdersChanged = this.ordersSubject.asObservable(); 23 | TotalChanged = this.totalSubject.asObservable(); 24 | 25 | constructor(private http: HttpClient) { 26 | } 27 | 28 | getAllProducts() { 29 | return this.http.get(this.productsUrl); 30 | } 31 | 32 | saveOrder(order: ProductOrders) { 33 | return this.http.post(this.ordersUrl, order); 34 | } 35 | 36 | get SelectedProductOrder() { 37 | return this.productOrder; 38 | } 39 | 40 | set SelectedProductOrder(value: ProductOrder) { 41 | this.productOrder = value; 42 | this.productOrderSubject.next(); 43 | } 44 | 45 | get ProductOrders() { 46 | return this.orders; 47 | } 48 | 49 | set ProductOrders(value: ProductOrders) { 50 | this.orders = value; 51 | this.ordersSubject.next(); 52 | } 53 | 54 | get Total() { 55 | return this.total; 56 | } 57 | 58 | set Total(value: number) { 59 | this.total = value; 60 | this.totalSubject.next(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /frontend/src/app/ecommerce/shopping-cart/shopping-cart.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hendisantika/springboot-ecommerce/f32e457302a42414f67cc0f52c5ceac8e92b391c/frontend/src/app/ecommerce/shopping-cart/shopping-cart.component.css -------------------------------------------------------------------------------- /frontend/src/app/ecommerce/shopping-cart/shopping-cart.component.html: -------------------------------------------------------------------------------- 1 |
2 |
Shopping Cart
3 |
4 |
Total: ${{total}}
5 |
6 |
Items bought:
7 | 8 |
    9 |
  • 10 | {{ order.product.name }} - {{ order.quantity}} pcs. 11 |
  • 12 |
13 | 14 | 17 |
18 |
19 | -------------------------------------------------------------------------------- /frontend/src/app/ecommerce/shopping-cart/shopping-cart.component.spec.ts: -------------------------------------------------------------------------------- 1 | import {async, ComponentFixture, TestBed} from '@angular/core/testing'; 2 | 3 | import {ShoppingCartComponent} from './shopping-cart.component'; 4 | 5 | describe('ShoppingCartComponent', () => { 6 | let component: ShoppingCartComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ShoppingCartComponent] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ShoppingCartComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /frontend/src/app/ecommerce/shopping-cart/shopping-cart.component.ts: -------------------------------------------------------------------------------- 1 | import {Component, EventEmitter, OnDestroy, OnInit, Output} from '@angular/core'; 2 | import {ProductOrders} from "../models/product-orders.model"; 3 | import {Subscription} from "rxjs"; 4 | import {EcommerceService} from "../services/ecommerce.service"; 5 | import {ProductOrder} from "../models/product-order.model"; 6 | 7 | @Component({ 8 | selector: 'app-shopping-cart', 9 | templateUrl: './shopping-cart.component.html', 10 | styleUrls: ['./shopping-cart.component.css'] 11 | }) 12 | export class ShoppingCartComponent implements OnInit, OnDestroy { 13 | orderFinished: boolean; 14 | orders: ProductOrders; 15 | total: number; 16 | sub: Subscription; 17 | 18 | @Output() onOrderFinished: EventEmitter; 19 | 20 | constructor(private ecommerceService: EcommerceService) { 21 | this.total = 0; 22 | this.orderFinished = false; 23 | this.onOrderFinished = new EventEmitter(); 24 | } 25 | 26 | ngOnInit() { 27 | this.orders = new ProductOrders(); 28 | this.loadCart(); 29 | this.loadTotal(); 30 | } 31 | 32 | ngOnDestroy() { 33 | this.sub.unsubscribe(); 34 | } 35 | 36 | finishOrder() { 37 | this.orderFinished = true; 38 | this.ecommerceService.Total = this.total; 39 | this.onOrderFinished.emit(this.orderFinished); 40 | } 41 | 42 | reset() { 43 | this.orderFinished = false; 44 | this.orders = new ProductOrders(); 45 | this.orders.productOrders = [] 46 | this.loadTotal(); 47 | this.total = 0; 48 | } 49 | 50 | loadTotal() { 51 | this.sub = this.ecommerceService.OrdersChanged.subscribe(() => { 52 | this.total = this.calculateTotal(this.orders.productOrders); 53 | }); 54 | } 55 | 56 | loadCart() { 57 | this.sub = this.ecommerceService.ProductOrderChanged.subscribe(() => { 58 | let productOrder = this.ecommerceService.SelectedProductOrder; 59 | if (productOrder) { 60 | this.orders.productOrders.push(new ProductOrder( 61 | productOrder.product, productOrder.quantity)); 62 | } 63 | this.ecommerceService.ProductOrders = this.orders; 64 | this.orders = this.ecommerceService.ProductOrders; 65 | this.total = this.calculateTotal(this.orders.productOrders); 66 | }); 67 | } 68 | 69 | private calculateTotal(products: ProductOrder[]): number { 70 | let sum = 0; 71 | products.forEach(value => { 72 | sum += (value.product.price * value.quantity); 73 | }); 74 | return sum; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /frontend/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hendisantika/springboot-ecommerce/f32e457302a42414f67cc0f52c5ceac8e92b391c/frontend/src/assets/.gitkeep -------------------------------------------------------------------------------- /frontend/src/browserslist: -------------------------------------------------------------------------------- 1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | # 5 | # For IE 9-11 support, please remove 'not' from the last line of the file and adjust as needed 6 | 7 | > 0.5% 8 | last 2 versions 9 | Firefox ESR 10 | not dead 11 | not IE 9-11 -------------------------------------------------------------------------------- /frontend/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /frontend/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /frontend/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hendisantika/springboot-ecommerce/f32e457302a42414f67cc0f52c5ceac8e92b391c/frontend/src/favicon.ico -------------------------------------------------------------------------------- /frontend/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Frontend 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /frontend/src/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, '../coverage/frontend'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false 30 | }); 31 | }; 32 | -------------------------------------------------------------------------------- /frontend/src/main.ts: -------------------------------------------------------------------------------- 1 | import {enableProdMode} from '@angular/core'; 2 | import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; 3 | 4 | import {AppModule} from './app/app.module'; 5 | import {environment} from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /frontend/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags.ts'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | -------------------------------------------------------------------------------- /frontend/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /frontend/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import {getTestBed} from '@angular/core/testing'; 5 | import {BrowserDynamicTestingModule, platformBrowserDynamicTesting} from '@angular/platform-browser-dynamic/testing'; 6 | 7 | declare const require: any; 8 | 9 | // First, initialize the Angular testing environment. 10 | getTestBed().initTestEnvironment( 11 | BrowserDynamicTestingModule, 12 | platformBrowserDynamicTesting() 13 | ); 14 | // Then we find all the tests. 15 | const context = require.context('./', true, /\.spec\.ts$/); 16 | // And load the modules. 17 | context.keys().map(context); 18 | -------------------------------------------------------------------------------- /frontend/src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "types": [] 6 | }, 7 | "exclude": [ 8 | "test.ts", 9 | "**/*.spec.ts" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /frontend/src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "test.ts", 12 | "polyfills.ts" 13 | ], 14 | "include": [ 15 | "**/*.spec.ts", 16 | "**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /frontend/src/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "app", 8 | "camelCase" 9 | ], 10 | "component-selector": [ 11 | true, 12 | "element", 13 | "app", 14 | "kebab-case" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /frontend/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "module": "es2015", 9 | "moduleResolution": "node", 10 | "emitDecoratorMetadata": true, 11 | "experimentalDecorators": true, 12 | "importHelpers": true, 13 | "target": "es5", 14 | "typeRoots": [ 15 | "node_modules/@types" 16 | ], 17 | "lib": [ 18 | "es2018", 19 | "dom" 20 | ] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /frontend/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rulesDirectory": [ 4 | "codelyzer" 5 | ], 6 | "rules": { 7 | "array-type": false, 8 | "arrow-parens": false, 9 | "deprecation": { 10 | "severity": "warn" 11 | }, 12 | "import-blacklist": [ 13 | true, 14 | "rxjs/Rx" 15 | ], 16 | "interface-name": false, 17 | "max-classes-per-file": false, 18 | "max-line-length": [ 19 | true, 20 | 140 21 | ], 22 | "member-access": false, 23 | "member-ordering": [ 24 | true, 25 | { 26 | "order": [ 27 | "static-field", 28 | "instance-field", 29 | "static-method", 30 | "instance-method" 31 | ] 32 | } 33 | ], 34 | "no-consecutive-blank-lines": false, 35 | "no-console": [ 36 | true, 37 | "debug", 38 | "info", 39 | "time", 40 | "timeEnd", 41 | "trace" 42 | ], 43 | "no-empty": false, 44 | "no-inferrable-types": [ 45 | true, 46 | "ignore-params" 47 | ], 48 | "no-non-null-assertion": true, 49 | "no-redundant-jsdoc": true, 50 | "no-switch-case-fall-through": true, 51 | "no-use-before-declare": true, 52 | "no-var-requires": false, 53 | "object-literal-key-quotes": [ 54 | true, 55 | "as-needed" 56 | ], 57 | "object-literal-sort-keys": false, 58 | "ordered-imports": false, 59 | "quotemark": [ 60 | true, 61 | "single" 62 | ], 63 | "trailing-comma": false, 64 | "no-output-on-prefix": true, 65 | "use-input-property-decorator": true, 66 | "use-output-property-decorator": true, 67 | "use-host-property-decorator": true, 68 | "no-input-rename": true, 69 | "no-output-rename": true, 70 | "use-life-cycle-interface": true, 71 | "use-pipe-transform-interface": true, 72 | "component-class-suffix": true, 73 | "directive-class-suffix": true 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /img/checkout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hendisantika/springboot-ecommerce/f32e457302a42414f67cc0f52c5ceac8e92b391c/img/checkout.png -------------------------------------------------------------------------------- /img/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hendisantika/springboot-ecommerce/f32e457302a42414f67cc0f52c5ceac8e92b391c/img/home.png -------------------------------------------------------------------------------- /img/order.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hendisantika/springboot-ecommerce/f32e457302a42414f67cc0f52c5ceac8e92b391c/img/order.png -------------------------------------------------------------------------------- /img/pay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hendisantika/springboot-ecommerce/f32e457302a42414f67cc0f52c5ceac8e92b391c/img/pay.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 | # Maven2 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 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | ########################################################################################## 204 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 205 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 206 | ########################################################################################## 207 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 208 | if [ "$MVNW_VERBOSE" = true ]; then 209 | echo "Found .mvn/wrapper/maven-wrapper.jar" 210 | fi 211 | else 212 | if [ "$MVNW_VERBOSE" = true ]; then 213 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 214 | fi 215 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 216 | while IFS="=" read key value; do 217 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 218 | esac 219 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 220 | if [ "$MVNW_VERBOSE" = true ]; then 221 | echo "Downloading from: $jarUrl" 222 | fi 223 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 224 | 225 | if command -v wget > /dev/null; then 226 | if [ "$MVNW_VERBOSE" = true ]; then 227 | echo "Found wget ... using wget" 228 | fi 229 | wget "$jarUrl" -O "$wrapperJarPath" 230 | elif command -v curl > /dev/null; then 231 | if [ "$MVNW_VERBOSE" = true ]; then 232 | echo "Found curl ... using curl" 233 | fi 234 | curl -o "$wrapperJarPath" "$jarUrl" 235 | else 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Falling back to using Java to download" 238 | fi 239 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 240 | if [ -e "$javaClass" ]; then 241 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 242 | if [ "$MVNW_VERBOSE" = true ]; then 243 | echo " - Compiling MavenWrapperDownloader.java ..." 244 | fi 245 | # Compiling the Java class 246 | ("$JAVA_HOME/bin/javac" "$javaClass") 247 | fi 248 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 249 | # Running the downloader 250 | if [ "$MVNW_VERBOSE" = true ]; then 251 | echo " - Running MavenWrapperDownloader.java ..." 252 | fi 253 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 254 | fi 255 | fi 256 | fi 257 | fi 258 | ########################################################################################## 259 | # End of extension 260 | ########################################################################################## 261 | 262 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 263 | if [ "$MVNW_VERBOSE" = true ]; then 264 | echo $MAVEN_PROJECTBASEDIR 265 | fi 266 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 267 | 268 | # For Cygwin, switch paths to Windows format before running java 269 | if $cygwin; then 270 | [ -n "$M2_HOME" ] && 271 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 272 | [ -n "$JAVA_HOME" ] && 273 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 274 | [ -n "$CLASSPATH" ] && 275 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 276 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 277 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 278 | fi 279 | 280 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 281 | 282 | exec "$JAVACMD" \ 283 | $MAVEN_OPTS \ 284 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 285 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 286 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 287 | -------------------------------------------------------------------------------- /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 Maven2 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 key stroke 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 my 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.4.2/maven-wrapper-0.4.2.jar" 124 | FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( 125 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 126 | ) 127 | 128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 130 | if exist %WRAPPER_JAR% ( 131 | echo Found %WRAPPER_JAR% 132 | ) else ( 133 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 134 | echo Downloading from: %DOWNLOAD_URL% 135 | powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" 136 | echo Finished downloading %WRAPPER_JAR% 137 | ) 138 | @REM End of extension 139 | 140 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 141 | if ERRORLEVEL 1 goto error 142 | goto end 143 | 144 | :error 145 | set ERROR_CODE=1 146 | 147 | :end 148 | @endlocal & set ERROR_CODE=%ERROR_CODE% 149 | 150 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 151 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 152 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 153 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 154 | :skipRcPost 155 | 156 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 157 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 158 | 159 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 160 | 161 | exit /B %ERROR_CODE% 162 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 3.3.3 9 | 10 | 11 | com.hendisantika.ecommerce 12 | springboot-ecommerce 13 | 0.0.1-SNAPSHOT 14 | springboot-ecommerce 15 | Demo project for Spring Boot 16 | 17 | 18 | 21 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-validation 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-data-jpa 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-devtools 37 | 38 | 39 | com.h2database 40 | h2 41 | 2.2.220 42 | runtime 43 | 44 | 45 | com.fasterxml.jackson.datatype 46 | jackson-datatype-jsr310 47 | 2.9.8 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-starter-test 52 | test 53 | 54 | 55 | 56 | 57 | 58 | 59 | org.springframework.boot 60 | spring-boot-maven-plugin 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /src/main/java/com/hendisantika/ecommerce/springbootecommerce/SpringbootEcommerceApplication.java: -------------------------------------------------------------------------------- 1 | package com.hendisantika.ecommerce.springbootecommerce; 2 | 3 | import com.hendisantika.ecommerce.springbootecommerce.model.Product; 4 | import com.hendisantika.ecommerce.springbootecommerce.service.ProductService; 5 | import org.springframework.boot.CommandLineRunner; 6 | import org.springframework.boot.SpringApplication; 7 | import org.springframework.boot.autoconfigure.SpringBootApplication; 8 | import org.springframework.context.annotation.Bean; 9 | 10 | @SpringBootApplication 11 | public class SpringbootEcommerceApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(SpringbootEcommerceApplication.class, args); 15 | } 16 | 17 | @Bean 18 | CommandLineRunner runner(ProductService productService) { 19 | return args -> { 20 | productService.save(new Product(1L, "Samsung TV Set", 300.00, "https://encrypted-tbn0.gstatic" + 21 | ".com/images?q=tbn:ANd9GcSHs_Q_HmDxOPprg7CJHWYf_qMf3qUtubTQ8nsSoC4FRdhsaT5ffg&s")); 22 | productService.save(new Product(2L, "Game Console", 200.00, "https://images-na.ssl-images-amazon" + 23 | ".com/images/I/71jN27mYlhL._AC_SL1500_.jpg")); 24 | productService.save(new Product(3L, "Sofa", 100.00, "https://media.4rgos.it/i/Argos/9182723_R_Z001A?w=750" + 25 | "&h=440&qlt=70")); 26 | productService.save(new Product(4L, "Ice Cream", 5.00, "https://mmc.tirto.id/image/otf/500x0/2020/03/31" + 27 | "/header-walls-vienetta_ratio-16x9.jpg")); 28 | productService.save(new Product(5L, "Marjan", 3.00, "https://ecs7.tokopedia" + 29 | ".net/img/cache/700/product-1/2018/10/18/4395737/4395737_869adbbe-e65e-4491-82eb" + 30 | "-7f66cce49488_394_394.jpg")); 31 | productService.save(new Product(6L, "iPhone 16 Pro Max", 500.00, "https://www.concept-phones" + 32 | ".com/wp-content/uploads/2019/08/iPhone-11X-concept-phone-Hasan-Kaymak-1.jpg")); 33 | productService.save(new Product(7L, "Watch", 30.00, "https://p.ipricegroup" + 34 | ".com/uploaded_16689895db8e5bf4e35f115583693d64.jpg")); 35 | productService.save(new Product(8L, "MI TV Set", 300.00, "https://i01.appmifile" + 36 | ".com/v1/MI_18455B3E4DA706226CF7535A58E875F0267/pms_1586239648.44731389.jpg")); 37 | productService.save(new Product(9L, "Brompton", 350.00, "https://www.brompton" + 38 | ".com/~/media/images/core-site-content/interactive-bike-block/explore/bromptonexplore_740x600" + 39 | ".png?h=600&la=en&w=740")); 40 | }; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/hendisantika/ecommerce/springbootecommerce/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | package com.hendisantika.ecommerce.springbootecommerce.controller; 2 | 3 | import com.hendisantika.ecommerce.springbootecommerce.dto.OrderProductDto; 4 | import com.hendisantika.ecommerce.springbootecommerce.exception.ResourceNotFoundException; 5 | import com.hendisantika.ecommerce.springbootecommerce.model.Order; 6 | import com.hendisantika.ecommerce.springbootecommerce.model.OrderProduct; 7 | import com.hendisantika.ecommerce.springbootecommerce.model.OrderStatus; 8 | import com.hendisantika.ecommerce.springbootecommerce.service.OrderProductService; 9 | import com.hendisantika.ecommerce.springbootecommerce.service.OrderService; 10 | import com.hendisantika.ecommerce.springbootecommerce.service.ProductService; 11 | import org.antlr.v4.runtime.misc.NotNull; 12 | import org.springframework.http.HttpHeaders; 13 | import org.springframework.http.HttpStatus; 14 | import org.springframework.http.ResponseEntity; 15 | import org.springframework.util.CollectionUtils; 16 | import org.springframework.web.bind.annotation.GetMapping; 17 | import org.springframework.web.bind.annotation.PostMapping; 18 | import org.springframework.web.bind.annotation.RequestBody; 19 | import org.springframework.web.bind.annotation.RequestMapping; 20 | import org.springframework.web.bind.annotation.ResponseStatus; 21 | import org.springframework.web.bind.annotation.RestController; 22 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | import java.util.Objects; 27 | import java.util.stream.Collectors; 28 | 29 | /** 30 | * Created by IntelliJ IDEA. 31 | * Project : springboot-ecommerce 32 | * User: hendisantika 33 | * Email: hendisantika@gmail.com 34 | * Telegram : @hendisantika34 35 | * Date: 2019-04-26 36 | * Time: 06:17 37 | */ 38 | @RestController 39 | @RequestMapping("/api/orders") 40 | public class OrderController { 41 | 42 | ProductService productService; 43 | OrderService orderService; 44 | OrderProductService orderProductService; 45 | 46 | public OrderController(ProductService productService, OrderService orderService, OrderProductService orderProductService) { 47 | this.productService = productService; 48 | this.orderService = orderService; 49 | this.orderProductService = orderProductService; 50 | } 51 | 52 | @GetMapping 53 | @ResponseStatus(HttpStatus.OK) 54 | public @NotNull Iterable listAllOrders() { 55 | return this.orderService.getAllOrders(); 56 | } 57 | 58 | @PostMapping 59 | public ResponseEntity create(@RequestBody OrderForm form) { 60 | List formDtos = form.getProductOrders(); 61 | validateProductsExistence(formDtos); 62 | Order order = new Order(); 63 | order.setStatus(OrderStatus.PAID.name()); 64 | order = this.orderService.create(order); 65 | 66 | List orderProducts = new ArrayList<>(); 67 | for (OrderProductDto dto : formDtos) { 68 | orderProducts.add(orderProductService.create(new OrderProduct(order, productService.getProduct(dto 69 | .getProduct() 70 | .getId()), dto.getQuantity()))); 71 | } 72 | 73 | order.setOrderProducts(orderProducts); 74 | 75 | this.orderService.update(order); 76 | 77 | String uri = ServletUriComponentsBuilder 78 | .fromCurrentServletMapping() 79 | .path("/orders/{id}") 80 | .buildAndExpand(order.getId()) 81 | .toString(); 82 | HttpHeaders headers = new HttpHeaders(); 83 | headers.add("Location", uri); 84 | 85 | return new ResponseEntity<>(order, headers, HttpStatus.CREATED); 86 | } 87 | 88 | private void validateProductsExistence(List orderProducts) { 89 | List list = orderProducts 90 | .stream() 91 | .filter(op -> Objects.isNull(productService.getProduct(op 92 | .getProduct() 93 | .getId()))) 94 | .collect(Collectors.toList()); 95 | 96 | if (!CollectionUtils.isEmpty(list)) { 97 | new ResourceNotFoundException("Product not found"); 98 | } 99 | } 100 | 101 | public static class OrderForm { 102 | 103 | private List productOrders; 104 | 105 | public List getProductOrders() { 106 | return productOrders; 107 | } 108 | 109 | public void setProductOrders(List productOrders) { 110 | this.productOrders = productOrders; 111 | } 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/com/hendisantika/ecommerce/springbootecommerce/controller/ProductController.java: -------------------------------------------------------------------------------- 1 | package com.hendisantika.ecommerce.springbootecommerce.controller; 2 | 3 | import com.hendisantika.ecommerce.springbootecommerce.model.Product; 4 | import com.hendisantika.ecommerce.springbootecommerce.service.ProductService; 5 | import org.antlr.v4.runtime.misc.NotNull; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | /** 11 | * Created by IntelliJ IDEA. 12 | * Project : springboot-ecommerce 13 | * User: hendisantika 14 | * Email: hendisantika@gmail.com 15 | * Telegram : @hendisantika34 16 | * Date: 2019-04-26 17 | * Time: 06:21 18 | */ 19 | @RestController 20 | @RequestMapping("/api/products") 21 | public class ProductController { 22 | 23 | private final ProductService productService; 24 | 25 | public ProductController(ProductService productService) { 26 | this.productService = productService; 27 | } 28 | 29 | @GetMapping(value = {"", "/"}) 30 | public @NotNull Iterable getProducts() { 31 | return productService.getAllProducts(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/hendisantika/ecommerce/springbootecommerce/dto/OrderProductDto.java: -------------------------------------------------------------------------------- 1 | package com.hendisantika.ecommerce.springbootecommerce.dto; 2 | 3 | import com.hendisantika.ecommerce.springbootecommerce.model.Product; 4 | 5 | /** 6 | * Created by IntelliJ IDEA. 7 | * Project : springboot-ecommerce 8 | * User: hendisantika 9 | * Email: hendisantika@gmail.com 10 | * Telegram : @hendisantika34 11 | * Date: 2019-04-26 12 | * Time: 06:08 13 | */ 14 | public class OrderProductDto { 15 | private Product product; 16 | private Integer quantity; 17 | 18 | public Product getProduct() { 19 | return product; 20 | } 21 | 22 | public void setProduct(Product product) { 23 | this.product = product; 24 | } 25 | 26 | public Integer getQuantity() { 27 | return quantity; 28 | } 29 | 30 | public void setQuantity(Integer quantity) { 31 | this.quantity = quantity; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/hendisantika/ecommerce/springbootecommerce/exception/ApiExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.hendisantika.ecommerce.springbootecommerce.exception; 2 | 3 | import com.fasterxml.jackson.annotation.JsonInclude; 4 | import jakarta.validation.ConstraintViolation; 5 | import jakarta.validation.ConstraintViolationException; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.ExceptionHandler; 9 | import org.springframework.web.bind.annotation.RestControllerAdvice; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | /** 15 | * Created by IntelliJ IDEA. 16 | * Project : springboot-ecommerce 17 | * User: hendisantika 18 | * Email: hendisantika@gmail.com 19 | * Telegram : @hendisantika34 20 | * Date: 2019-04-26 21 | * Time: 06:08 22 | */ 23 | @RestControllerAdvice 24 | public class ApiExceptionHandler { 25 | @SuppressWarnings("rawtypes") 26 | @ExceptionHandler(ConstraintViolationException.class) 27 | public ResponseEntity handle(ConstraintViolationException e) { 28 | ErrorResponse errors = new ErrorResponse(); 29 | for (ConstraintViolation violation : e.getConstraintViolations()) { 30 | ErrorItem error = new ErrorItem(); 31 | error.setCode(violation.getMessageTemplate()); 32 | error.setMessage(violation.getMessage()); 33 | errors.addError(error); 34 | } 35 | 36 | return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST); 37 | } 38 | 39 | @SuppressWarnings("rawtypes") 40 | @ExceptionHandler(ResourceNotFoundException.class) 41 | public ResponseEntity handle(ResourceNotFoundException e) { 42 | ErrorItem error = new ErrorItem(); 43 | error.setMessage(e.getMessage()); 44 | 45 | return new ResponseEntity<>(error, HttpStatus.NOT_FOUND); 46 | } 47 | 48 | public static class ErrorItem { 49 | 50 | @JsonInclude(JsonInclude.Include.NON_NULL) 51 | private String code; 52 | 53 | private String message; 54 | 55 | public String getCode() { 56 | return code; 57 | } 58 | 59 | public void setCode(String code) { 60 | this.code = code; 61 | } 62 | 63 | public String getMessage() { 64 | return message; 65 | } 66 | 67 | public void setMessage(String message) { 68 | this.message = message; 69 | } 70 | 71 | } 72 | 73 | public static class ErrorResponse { 74 | 75 | private List errors = new ArrayList<>(); 76 | 77 | public List getErrors() { 78 | return errors; 79 | } 80 | 81 | public void setErrors(List errors) { 82 | this.errors = errors; 83 | } 84 | 85 | public void addError(ErrorItem error) { 86 | this.errors.add(error); 87 | } 88 | 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/com/hendisantika/ecommerce/springbootecommerce/exception/ResourceNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.hendisantika.ecommerce.springbootecommerce.exception; 2 | 3 | /** 4 | * Created by IntelliJ IDEA. 5 | * Project : springboot-ecommerce 6 | * User: hendisantika 7 | * Email: hendisantika@gmail.com 8 | * Telegram : @hendisantika34 9 | * Date: 2019-04-26 10 | * Time: 06:11 11 | */ 12 | public class ResourceNotFoundException extends RuntimeException { 13 | 14 | private static final long serialVersionUID = 5861310537366287163L; 15 | 16 | public ResourceNotFoundException() { 17 | super(); 18 | } 19 | 20 | public ResourceNotFoundException(final String message, final Throwable cause) { 21 | super(message, cause); 22 | } 23 | 24 | public ResourceNotFoundException(final String message) { 25 | super(message); 26 | } 27 | 28 | public ResourceNotFoundException(final Throwable cause) { 29 | super(cause); 30 | } 31 | } -------------------------------------------------------------------------------- /src/main/java/com/hendisantika/ecommerce/springbootecommerce/model/Order.java: -------------------------------------------------------------------------------- 1 | package com.hendisantika.ecommerce.springbootecommerce.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import com.fasterxml.jackson.annotation.JsonIdentityInfo; 5 | import com.fasterxml.jackson.annotation.ObjectIdGenerators; 6 | import jakarta.persistence.Entity; 7 | import jakarta.persistence.GeneratedValue; 8 | import jakarta.persistence.GenerationType; 9 | import jakarta.persistence.Id; 10 | import jakarta.persistence.OneToMany; 11 | import jakarta.persistence.Table; 12 | import jakarta.persistence.Transient; 13 | import jakarta.validation.Valid; 14 | 15 | import java.time.LocalDate; 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | 19 | /** 20 | * Created by IntelliJ IDEA. 21 | * Project : springboot-ecommerce 22 | * User: hendisantika 23 | * Email: hendisantika@gmail.com 24 | * Telegram : @hendisantika34 25 | * Date: 2019-04-26 26 | * Time: 06:03 27 | */ 28 | @Entity 29 | @Table(name = "orders") 30 | @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "orderProducts") 31 | public class Order { 32 | 33 | @Id 34 | @GeneratedValue(strategy = GenerationType.IDENTITY) 35 | private Long id; 36 | 37 | @JsonFormat(pattern = "dd/MM/yyyy") 38 | private LocalDate dateCreated; 39 | 40 | private String status; 41 | 42 | @OneToMany(mappedBy = "pk.order") 43 | @Valid 44 | private List orderProducts = new ArrayList<>(); 45 | 46 | @Transient 47 | public Double getTotalOrderPrice() { 48 | double sum = 0D; 49 | List orderProducts = getOrderProducts(); 50 | for (OrderProduct op : orderProducts) { 51 | sum += op.getTotalPrice(); 52 | } 53 | 54 | return sum; 55 | } 56 | 57 | public Long getId() { 58 | return id; 59 | } 60 | 61 | public void setId(Long id) { 62 | this.id = id; 63 | } 64 | 65 | public LocalDate getDateCreated() { 66 | return dateCreated; 67 | } 68 | 69 | public void setDateCreated(LocalDate dateCreated) { 70 | this.dateCreated = dateCreated; 71 | } 72 | 73 | public String getStatus() { 74 | return status; 75 | } 76 | 77 | public void setStatus(String status) { 78 | this.status = status; 79 | } 80 | 81 | public List getOrderProducts() { 82 | return orderProducts; 83 | } 84 | 85 | public void setOrderProducts(List orderProducts) { 86 | this.orderProducts = orderProducts; 87 | } 88 | 89 | @Transient 90 | public int getNumberOfProducts() { 91 | return this.orderProducts.size(); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/com/hendisantika/ecommerce/springbootecommerce/model/OrderProduct.java: -------------------------------------------------------------------------------- 1 | package com.hendisantika.ecommerce.springbootecommerce.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; 4 | import jakarta.persistence.Column; 5 | import jakarta.persistence.EmbeddedId; 6 | import jakarta.persistence.Entity; 7 | import jakarta.persistence.Transient; 8 | 9 | /** 10 | * Created by IntelliJ IDEA. 11 | * Project : springboot-ecommerce 12 | * User: hendisantika 13 | * Email: hendisantika@gmail.com 14 | * Telegram : @hendisantika34 15 | * Date: 2019-04-26 16 | * Time: 06:06 17 | */ 18 | @Entity 19 | public class OrderProduct { 20 | 21 | @EmbeddedId 22 | @JsonIgnore 23 | private OrderProductPK pk; 24 | 25 | @Column(nullable = false) 26 | private Integer quantity; 27 | 28 | public OrderProduct() { 29 | super(); 30 | } 31 | 32 | public OrderProduct(Order order, Product product, Integer quantity) { 33 | pk = new OrderProductPK(); 34 | pk.setOrder(order); 35 | pk.setProduct(product); 36 | this.quantity = quantity; 37 | } 38 | 39 | @Transient 40 | public Product getProduct() { 41 | return this.pk.getProduct(); 42 | } 43 | 44 | @Transient 45 | public Double getTotalPrice() { 46 | return getProduct().getPrice() * getQuantity(); 47 | } 48 | 49 | public OrderProductPK getPk() { 50 | return pk; 51 | } 52 | 53 | public void setPk(OrderProductPK pk) { 54 | this.pk = pk; 55 | } 56 | 57 | public Integer getQuantity() { 58 | return quantity; 59 | } 60 | 61 | public void setQuantity(Integer quantity) { 62 | this.quantity = quantity; 63 | } 64 | 65 | @Override 66 | public int hashCode() { 67 | final int prime = 31; 68 | int result = 1; 69 | result = prime * result + ((pk == null) ? 0 : pk.hashCode()); 70 | 71 | return result; 72 | } 73 | 74 | @Override 75 | public boolean equals(Object obj) { 76 | if (this == obj) { 77 | return true; 78 | } 79 | if (obj == null) { 80 | return false; 81 | } 82 | if (getClass() != obj.getClass()) { 83 | return false; 84 | } 85 | OrderProduct other = (OrderProduct) obj; 86 | if (pk == null) { 87 | return other.pk == null; 88 | } else return pk.equals(other.pk); 89 | 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/hendisantika/ecommerce/springbootecommerce/model/OrderProductPK.java: -------------------------------------------------------------------------------- 1 | package com.hendisantika.ecommerce.springbootecommerce.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIdentityInfo; 4 | import com.fasterxml.jackson.annotation.ObjectIdGenerators; 5 | import jakarta.persistence.Embeddable; 6 | import jakarta.persistence.FetchType; 7 | import jakarta.persistence.JoinColumn; 8 | import jakarta.persistence.ManyToOne; 9 | 10 | import java.io.Serializable; 11 | 12 | /** 13 | * Created by IntelliJ IDEA. 14 | * Project : springboot-ecommerce 15 | * User: hendisantika 16 | * Email: hendisantika@gmail.com 17 | * Telegram : @hendisantika34 18 | * Date: 2019-04-26 19 | * Time: 06:06 20 | */ 21 | @Embeddable 22 | @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "order") 23 | public class OrderProductPK implements Serializable { 24 | 25 | private static final long serialVersionUID = 476151177562655457L; 26 | 27 | @ManyToOne(optional = false, fetch = FetchType.LAZY) 28 | @JoinColumn(name = "order_id") 29 | private Order order; 30 | 31 | @ManyToOne(optional = false, fetch = FetchType.LAZY) 32 | @JoinColumn(name = "product_id") 33 | private Product product; 34 | 35 | public Order getOrder() { 36 | return order; 37 | } 38 | 39 | public void setOrder(Order order) { 40 | this.order = order; 41 | } 42 | 43 | public Product getProduct() { 44 | return product; 45 | } 46 | 47 | public void setProduct(Product product) { 48 | this.product = product; 49 | } 50 | 51 | @Override 52 | public int hashCode() { 53 | final int prime = 31; 54 | int result = 1; 55 | 56 | result = prime * result + ((order.getId() == null) 57 | ? 0 58 | : order 59 | .getId() 60 | .hashCode()); 61 | result = prime * result + ((product.getId() == null) 62 | ? 0 63 | : product 64 | .getId() 65 | .hashCode()); 66 | 67 | return result; 68 | } 69 | 70 | @Override 71 | public boolean equals(Object obj) { 72 | if (this == obj) { 73 | return true; 74 | } 75 | if (obj == null) { 76 | return false; 77 | } 78 | if (getClass() != obj.getClass()) { 79 | return false; 80 | } 81 | OrderProductPK other = (OrderProductPK) obj; 82 | if (order == null) { 83 | if (other.order != null) { 84 | return false; 85 | } 86 | } else if (!order.equals(other.order)) { 87 | return false; 88 | } 89 | 90 | if (product == null) { 91 | return other.product == null; 92 | } else return product.equals(other.product); 93 | 94 | } 95 | } 96 | 97 | -------------------------------------------------------------------------------- /src/main/java/com/hendisantika/ecommerce/springbootecommerce/model/OrderStatus.java: -------------------------------------------------------------------------------- 1 | package com.hendisantika.ecommerce.springbootecommerce.model; 2 | 3 | /** 4 | * Created by IntelliJ IDEA. 5 | * Project : springboot-ecommerce 6 | * User: hendisantika 7 | * Email: hendisantika@gmail.com 8 | * Telegram : @hendisantika34 9 | * Date: 2019-04-26 10 | * Time: 06:05 11 | */ 12 | public enum OrderStatus { 13 | PAID, 14 | UNPAID, 15 | FAILED, 16 | CANCEL 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/hendisantika/ecommerce/springbootecommerce/model/Product.java: -------------------------------------------------------------------------------- 1 | package com.hendisantika.ecommerce.springbootecommerce.model; 2 | 3 | import jakarta.persistence.Basic; 4 | import jakarta.persistence.Entity; 5 | import jakarta.persistence.GeneratedValue; 6 | import jakarta.persistence.GenerationType; 7 | import jakarta.persistence.Id; 8 | import jakarta.validation.constraints.NotNull; 9 | 10 | /** 11 | * Created by IntelliJ IDEA. 12 | * Project : springboot-ecommerce 13 | * User: hendisantika 14 | * Email: hendisantika@gmail.com 15 | * Telegram : @hendisantika34 16 | * Date: 2019-04-26 17 | * Time: 06:04 18 | */ 19 | @Entity 20 | public class Product { 21 | 22 | @Id 23 | @GeneratedValue(strategy = GenerationType.IDENTITY) 24 | private Long id; 25 | 26 | @NotNull(message = "Product name is required.") 27 | @Basic(optional = false) 28 | private String name; 29 | 30 | private Double price; 31 | 32 | private String pictureUrl; 33 | 34 | public Product(Long id, @NotNull(message = "Product name is required.") String name, Double price, String pictureUrl) { 35 | this.id = id; 36 | this.name = name; 37 | this.price = price; 38 | this.pictureUrl = pictureUrl; 39 | } 40 | 41 | public Product() { 42 | } 43 | 44 | public Long getId() { 45 | return id; 46 | } 47 | 48 | public void setId(Long id) { 49 | this.id = id; 50 | } 51 | 52 | public String getName() { 53 | return name; 54 | } 55 | 56 | public void setName(String name) { 57 | this.name = name; 58 | } 59 | 60 | public Double getPrice() { 61 | return price; 62 | } 63 | 64 | public void setPrice(Double price) { 65 | this.price = price; 66 | } 67 | 68 | public String getPictureUrl() { 69 | return pictureUrl; 70 | } 71 | 72 | public void setPictureUrl(String pictureUrl) { 73 | this.pictureUrl = pictureUrl; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/hendisantika/ecommerce/springbootecommerce/repository/OrderProductRepository.java: -------------------------------------------------------------------------------- 1 | package com.hendisantika.ecommerce.springbootecommerce.repository; 2 | 3 | import com.hendisantika.ecommerce.springbootecommerce.model.OrderProduct; 4 | import com.hendisantika.ecommerce.springbootecommerce.model.OrderProductPK; 5 | import org.springframework.data.repository.CrudRepository; 6 | 7 | /** 8 | * Created by IntelliJ IDEA. 9 | * Project : springboot-ecommerce 10 | * User: hendisantika 11 | * Email: hendisantika@gmail.com 12 | * Telegram : @hendisantika34 13 | * Date: 2019-04-26 14 | * Time: 06:12 15 | */ 16 | public interface OrderProductRepository extends CrudRepository { 17 | } -------------------------------------------------------------------------------- /src/main/java/com/hendisantika/ecommerce/springbootecommerce/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package com.hendisantika.ecommerce.springbootecommerce.repository; 2 | 3 | import com.hendisantika.ecommerce.springbootecommerce.model.Order; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | /** 7 | * Created by IntelliJ IDEA. 8 | * Project : springboot-ecommerce 9 | * User: hendisantika 10 | * Email: hendisantika@gmail.com 11 | * Telegram : @hendisantika34 12 | * Date: 2019-04-26 13 | * Time: 06:12 14 | */ 15 | public interface OrderRepository extends CrudRepository { 16 | } -------------------------------------------------------------------------------- /src/main/java/com/hendisantika/ecommerce/springbootecommerce/repository/ProductRepository.java: -------------------------------------------------------------------------------- 1 | package com.hendisantika.ecommerce.springbootecommerce.repository; 2 | 3 | import com.hendisantika.ecommerce.springbootecommerce.model.Product; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | /** 7 | * Created by IntelliJ IDEA. 8 | * Project : springboot-ecommerce 9 | * User: hendisantika 10 | * Email: hendisantika@gmail.com 11 | * Telegram : @hendisantika34 12 | * Date: 2019-04-26 13 | * Time: 06:13 14 | */ 15 | public interface ProductRepository extends CrudRepository { 16 | } -------------------------------------------------------------------------------- /src/main/java/com/hendisantika/ecommerce/springbootecommerce/service/OrderProductService.java: -------------------------------------------------------------------------------- 1 | package com.hendisantika.ecommerce.springbootecommerce.service; 2 | 3 | import com.hendisantika.ecommerce.springbootecommerce.model.OrderProduct; 4 | import jakarta.validation.Valid; 5 | import jakarta.validation.constraints.NotNull; 6 | import org.springframework.validation.annotation.Validated; 7 | 8 | /** 9 | * Created by IntelliJ IDEA. 10 | * Project : springboot-ecommerce 11 | * User: hendisantika 12 | * Email: hendisantika@gmail.com 13 | * Telegram : @hendisantika34 14 | * Date: 2019-04-26 15 | * Time: 06:13 16 | */ 17 | @Validated 18 | public interface OrderProductService { 19 | 20 | OrderProduct create(@NotNull(message = "The products for order cannot be null.") @Valid OrderProduct orderProduct); 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/hendisantika/ecommerce/springbootecommerce/service/OrderProductServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.hendisantika.ecommerce.springbootecommerce.service; 2 | 3 | import com.hendisantika.ecommerce.springbootecommerce.model.OrderProduct; 4 | import com.hendisantika.ecommerce.springbootecommerce.repository.OrderProductRepository; 5 | import org.springframework.stereotype.Service; 6 | import org.springframework.transaction.annotation.Transactional; 7 | 8 | /** 9 | * Created by IntelliJ IDEA. 10 | * Project : springboot-ecommerce 11 | * User: hendisantika 12 | * Email: hendisantika@gmail.com 13 | * Telegram : @hendisantika34 14 | * Date: 2019-04-26 15 | * Time: 06:14 16 | */ 17 | @Service 18 | @Transactional 19 | public class OrderProductServiceImpl implements OrderProductService { 20 | 21 | private OrderProductRepository orderProductRepository; 22 | 23 | public OrderProductServiceImpl(OrderProductRepository orderProductRepository) { 24 | this.orderProductRepository = orderProductRepository; 25 | } 26 | 27 | @Override 28 | public OrderProduct create(OrderProduct orderProduct) { 29 | return this.orderProductRepository.save(orderProduct); 30 | } 31 | } -------------------------------------------------------------------------------- /src/main/java/com/hendisantika/ecommerce/springbootecommerce/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.hendisantika.ecommerce.springbootecommerce.service; 2 | 3 | import com.hendisantika.ecommerce.springbootecommerce.model.Order; 4 | import jakarta.validation.Valid; 5 | import jakarta.validation.constraints.NotNull; 6 | import org.springframework.validation.annotation.Validated; 7 | 8 | /** 9 | * Created by IntelliJ IDEA. 10 | * Project : springboot-ecommerce 11 | * User: hendisantika 12 | * Email: hendisantika@gmail.com 13 | * Telegram : @hendisantika34 14 | * Date: 2019-04-26 15 | * Time: 06:14 16 | */ 17 | @Validated 18 | public interface OrderService { 19 | 20 | @NotNull 21 | Iterable getAllOrders(); 22 | 23 | Order create(@NotNull(message = "The order cannot be null.") @Valid Order order); 24 | 25 | void update(@NotNull(message = "The order cannot be null.") @Valid Order order); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/hendisantika/ecommerce/springbootecommerce/service/OrderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.hendisantika.ecommerce.springbootecommerce.service; 2 | 3 | import com.hendisantika.ecommerce.springbootecommerce.model.Order; 4 | import com.hendisantika.ecommerce.springbootecommerce.repository.OrderRepository; 5 | import org.springframework.stereotype.Service; 6 | import org.springframework.transaction.annotation.Transactional; 7 | 8 | import java.time.LocalDate; 9 | 10 | /** 11 | * Created by IntelliJ IDEA. 12 | * Project : springboot-ecommerce 13 | * User: hendisantika 14 | * Email: hendisantika@gmail.com 15 | * Telegram : @hendisantika34 16 | * Date: 2019-04-26 17 | * Time: 06:15 18 | */ 19 | @Service 20 | @Transactional 21 | public class OrderServiceImpl implements OrderService { 22 | 23 | private OrderRepository orderRepository; 24 | 25 | public OrderServiceImpl(OrderRepository orderRepository) { 26 | this.orderRepository = orderRepository; 27 | } 28 | 29 | @Override 30 | public Iterable getAllOrders() { 31 | return this.orderRepository.findAll(); 32 | } 33 | 34 | @Override 35 | public Order create(Order order) { 36 | order.setDateCreated(LocalDate.now()); 37 | 38 | return this.orderRepository.save(order); 39 | } 40 | 41 | @Override 42 | public void update(Order order) { 43 | this.orderRepository.save(order); 44 | } 45 | } -------------------------------------------------------------------------------- /src/main/java/com/hendisantika/ecommerce/springbootecommerce/service/ProductService.java: -------------------------------------------------------------------------------- 1 | package com.hendisantika.ecommerce.springbootecommerce.service; 2 | 3 | import com.hendisantika.ecommerce.springbootecommerce.model.Product; 4 | import jakarta.validation.constraints.Min; 5 | import jakarta.validation.constraints.NotNull; 6 | import org.springframework.validation.annotation.Validated; 7 | 8 | /** 9 | * Created by IntelliJ IDEA. 10 | * Project : springboot-ecommerce 11 | * User: hendisantika 12 | * Email: hendisantika@gmail.com 13 | * Telegram : @hendisantika34 14 | * Date: 2019-04-26 15 | * Time: 06:15 16 | */ 17 | @Validated 18 | public interface ProductService { 19 | 20 | @NotNull 21 | Iterable getAllProducts(); 22 | 23 | Product getProduct(@Min(value = 1L, message = "Invalid product ID.") long id); 24 | 25 | Product save(Product product); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/hendisantika/ecommerce/springbootecommerce/service/ProductServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.hendisantika.ecommerce.springbootecommerce.service; 2 | 3 | import com.hendisantika.ecommerce.springbootecommerce.exception.ResourceNotFoundException; 4 | import com.hendisantika.ecommerce.springbootecommerce.model.Product; 5 | import com.hendisantika.ecommerce.springbootecommerce.repository.ProductRepository; 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.transaction.annotation.Transactional; 8 | 9 | /** 10 | * Created by IntelliJ IDEA. 11 | * Project : springboot-ecommerce 12 | * User: hendisantika 13 | * Email: hendisantika@gmail.com 14 | * Telegram : @hendisantika34 15 | * Date: 2019-04-26 16 | * Time: 06:16 17 | */ 18 | @Service 19 | @Transactional 20 | public class ProductServiceImpl implements ProductService { 21 | 22 | private ProductRepository productRepository; 23 | 24 | public ProductServiceImpl(ProductRepository productRepository) { 25 | this.productRepository = productRepository; 26 | } 27 | 28 | @Override 29 | public Iterable getAllProducts() { 30 | return productRepository.findAll(); 31 | } 32 | 33 | @Override 34 | public Product getProduct(long id) { 35 | return productRepository 36 | .findById(id) 37 | .orElseThrow(() -> new ResourceNotFoundException("Product not found")); 38 | } 39 | 40 | @Override 41 | public Product save(Product product) { 42 | return productRepository.save(product); 43 | } 44 | } -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | management.security.enabled=false 2 | spring.datasource.name=ecommercedb 3 | spring.jpa.show-sql=true 4 | spring.jpa.properties.hibernate.format_sql=true 5 | #H2 settings 6 | spring.h2.console.enabled=true 7 | spring.h2.console.path=/h2-console 8 | -------------------------------------------------------------------------------- /src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/test/java/com/hendisantika/ecommerce/springbootecommerce/EcommerceApplicationIntegrationTest.java: -------------------------------------------------------------------------------- 1 | package com.hendisantika.ecommerce.springbootecommerce; 2 | 3 | import com.hendisantika.ecommerce.springbootecommerce.controller.OrderController; 4 | import com.hendisantika.ecommerce.springbootecommerce.controller.ProductController; 5 | import com.hendisantika.ecommerce.springbootecommerce.dto.OrderProductDto; 6 | import com.hendisantika.ecommerce.springbootecommerce.model.Product; 7 | import org.assertj.core.api.Assertions; 8 | import org.junit.jupiter.api.Test; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.test.context.SpringBootTest; 11 | import org.springframework.boot.test.web.client.TestRestTemplate; 12 | import org.springframework.boot.test.web.server.LocalServerPort; 13 | import org.springframework.core.ParameterizedTypeReference; 14 | import org.springframework.http.HttpMethod; 15 | import org.springframework.http.ResponseEntity; 16 | 17 | import java.util.Collections; 18 | 19 | import static org.hamcrest.CoreMatchers.hasItem; 20 | import static org.hamcrest.CoreMatchers.is; 21 | import static org.hamcrest.MatcherAssert.assertThat; 22 | import static org.hamcrest.Matchers.hasProperty; 23 | 24 | /** 25 | * Created by IntelliJ IDEA. 26 | * Project : springboot-ecommerce 27 | * User: hendisantika 28 | * Email: hendisantika@gmail.com 29 | * Telegram : @hendisantika34 30 | * Date: 2019-04-26 31 | * Time: 06:24 32 | */ 33 | @SpringBootTest(classes = {SpringbootEcommerceApplication.class}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 34 | public class EcommerceApplicationIntegrationTest { 35 | @Autowired 36 | private TestRestTemplate restTemplate; 37 | 38 | @LocalServerPort 39 | private int port; 40 | 41 | @Autowired 42 | private ProductController productController; 43 | 44 | @Autowired 45 | private OrderController orderController; 46 | 47 | @Test 48 | public void contextLoads() { 49 | Assertions 50 | .assertThat(productController) 51 | .isNotNull(); 52 | Assertions 53 | .assertThat(orderController) 54 | .isNotNull(); 55 | } 56 | 57 | @Test 58 | public void givenGetProductsApiCall_whenProductListRetrieved_thenSizeMatchAndListContainsProductNames() { 59 | ResponseEntity> responseEntity = restTemplate.exchange("http://localhost:" + port + "/api/products", HttpMethod.GET, null, new ParameterizedTypeReference>() { 60 | }); 61 | Iterable products = responseEntity.getBody(); 62 | Assertions 63 | .assertThat(products) 64 | .hasSize(9); 65 | 66 | assertThat(products, hasItem(hasProperty("name", is("Samsung TV Set")))); 67 | assertThat(products, hasItem(hasProperty("name", is("Game Console")))); 68 | assertThat(products, hasItem(hasProperty("name", is("Sofa")))); 69 | assertThat(products, hasItem(hasProperty("name", is("Ice Cream")))); 70 | assertThat(products, hasItem(hasProperty("name", is("Marjan")))); 71 | assertThat(products, hasItem(hasProperty("name", is("iPhone 16 Pro Max")))); 72 | assertThat(products, hasItem(hasProperty("name", is("Watch")))); 73 | assertThat(products, hasItem(hasProperty("name", is("MI TV Set")))); 74 | assertThat(products, hasItem(hasProperty("name", is("Brompton")))); 75 | } 76 | 77 | // @Test 78 | // public void givenPostOrder_whenBodyRequestMatcherJson_thenResponseContainsEqualObjectProperties() { 79 | // final ResponseEntity postResponse = restTemplate.postForEntity("http://localhost:" + port + "/api/orders", prepareOrderForm(), Order.class); 80 | // Order order = postResponse.getBody(); 81 | // Assertions 82 | // .assertThat(postResponse.getStatusCode()) 83 | // .isEqualByComparingTo(HttpStatus.CREATED); 84 | // 85 | // assertThat(order, hasProperty("status", is("PAID"))); 86 | // assertThat(order.getOrderProducts(), hasItem(hasProperty("quantity", is(2)))); 87 | // } 88 | 89 | private OrderController.OrderForm prepareOrderForm() { 90 | OrderController.OrderForm orderForm = new OrderController.OrderForm(); 91 | OrderProductDto productDto = new OrderProductDto(); 92 | productDto.setProduct(new Product(1L, "TV Set", 300.00, "http://placehold.it/200x100")); 93 | productDto.setQuantity(2); 94 | orderForm.setProductOrders(Collections.singletonList(productDto)); 95 | 96 | return orderForm; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/test/java/com/hendisantika/ecommerce/springbootecommerce/SpringbootEcommerceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.hendisantika.ecommerce.springbootecommerce; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | public class SpringbootEcommerceApplicationTests { 8 | 9 | @Test 10 | public void contextLoads() { 11 | } 12 | 13 | } 14 | --------------------------------------------------------------------------------