├── .github └── workflows │ ├── codeql-analysis.yml │ ├── main.yml │ └── maven.yml ├── .gitignore ├── .mvn └── wrapper │ ├── MavenWrapperDownloader.java │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── LICENSE ├── README.md ├── SECURITY.md ├── _config.yml ├── bin ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.class │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── README.md ├── mvnw ├── mvnw.cmd ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── food │ │ │ └── delivery │ │ │ └── app │ │ │ └── ws │ │ │ └── FoodDeliveryWebAppApplication.class │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── food │ └── delivery │ └── app │ └── ws │ └── FoodDeliveryWebAppApplicationTests.class ├── mvnw ├── mvnw.cmd ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── food │ │ └── delivery │ │ └── app │ │ └── ws │ │ ├── FoodDeliveryWebAppApplication.java │ │ ├── SpringApplicationContext.java │ │ ├── SwaggerConfig.java │ │ ├── io │ │ ├── entity │ │ │ ├── FoodEntity.java │ │ │ ├── OrderEntity.java │ │ │ └── UserEntity.java │ │ └── repository │ │ │ ├── FoodRepository.java │ │ │ ├── OrderRepository.java │ │ │ └── UserRepository.java │ │ ├── model │ │ ├── request │ │ │ ├── FoodDetailsRequestModel.java │ │ │ ├── LoginRequest.java │ │ │ ├── OrderDetailsRequestModel.java │ │ │ ├── UserDetailsRequestModel.java │ │ │ └── UserLoginRequseModel.java │ │ └── response │ │ │ ├── FoodDetailsResponse.java │ │ │ ├── OperationStatusModel.java │ │ │ ├── OrderDetailsResponse.java │ │ │ ├── RequestOperationName.java │ │ │ ├── RequestOperationStatus.java │ │ │ └── UserRest.java │ │ ├── security │ │ ├── AuthenticationFilter.java │ │ ├── AuthorizationFilter.java │ │ ├── SecurityConstants.java │ │ └── WebSecurity.java │ │ ├── service │ │ ├── FoodService.java │ │ ├── OrderService.java │ │ ├── UserService.java │ │ └── impl │ │ │ ├── FoodServiceImpl.java │ │ │ ├── OrderServiceImpl.java │ │ │ └── UserServiceImpl.java │ │ ├── shared │ │ ├── Utils.java │ │ └── dto │ │ │ ├── FoodDto.java │ │ │ ├── OrderDto.java │ │ │ └── UserDto.java │ │ └── ui │ │ └── controller │ │ ├── AuthenticationController.java │ │ ├── FoodController.java │ │ ├── OrderController.java │ │ └── UserController.java └── resources │ └── application.properties └── test └── java └── com └── food └── delivery └── app └── ws └── FoodDeliveryWebAppApplicationTests.java /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | name: "CodeQL" 7 | 8 | on: 9 | push: 10 | branches: [master] 11 | pull_request: 12 | # The branches below must be a subset of the branches above 13 | branches: [master] 14 | schedule: 15 | - cron: '0 16 * * 0' 16 | 17 | jobs: 18 | analyze: 19 | name: Analyze 20 | runs-on: ubuntu-latest 21 | 22 | strategy: 23 | fail-fast: false 24 | matrix: 25 | # Override automatic language detection by changing the below list 26 | # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] 27 | language: ['java'] 28 | # Learn more... 29 | # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection 30 | 31 | steps: 32 | - name: Checkout repository 33 | uses: actions/checkout@v2 34 | with: 35 | # We must fetch at least the immediate parents so that if this is 36 | # a pull request then we can checkout the head. 37 | fetch-depth: 2 38 | 39 | # If this run was triggered by a pull request event, then checkout 40 | # the head of the pull request instead of the merge commit. 41 | - run: git checkout HEAD^2 42 | if: ${{ github.event_name == 'pull_request' }} 43 | 44 | # Initializes the CodeQL tools for scanning. 45 | - name: Initialize CodeQL 46 | uses: github/codeql-action/init@v1 47 | with: 48 | languages: ${{ matrix.language }} 49 | # If you wish to specify custom queries, you can do so here or in a config file. 50 | # By default, queries listed here will override any specified in a config file. 51 | # Prefix the list here with "+" to use these queries and those in the config file. 52 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 53 | 54 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 55 | # If this step fails, then you should remove it and run the build manually (see below) 56 | - name: Autobuild 57 | uses: github/codeql-action/autobuild@v1 58 | 59 | # ℹ️ Command-line programs to run using the OS shell. 60 | # 📚 https://git.io/JvXDl 61 | 62 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 63 | # and modify them (or add more) to build your code if your project 64 | # uses a compiled language 65 | 66 | #- run: | 67 | # make bootstrap 68 | # make release 69 | 70 | - name: Perform CodeQL Analysis 71 | uses: github/codeql-action/analyze@v1 72 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Docker_Build 2 | on: 3 | push: 4 | branches: [ docker ] 5 | pull_request: 6 | branches: [ docker ] 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v2 13 | - name: Docker Build For food boot 14 | run: | 15 | docker build -t foot-boot/food-delivery-web-app:0.0.1 16 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | name: Java CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v1 12 | - name: Set up JDK 1.8 13 | uses: actions/setup-java@v1 14 | with: 15 | java-version: 1.8 16 | - name: Build with Maven 17 | run: mvn package --file pom.xml 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | /target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | .sts4-cache 13 | 14 | ### IntelliJ IDEA ### 15 | .idea 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/food-boot/food_delivery_web_app_backend_springboot/9f8bdcd998805c2d15d46ece0fa69ed2c48ad3a7/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Food-Delivery-Web-App-BackEnd-SpringBoot 2 | 3 | ## Build from the Source 4 | 5 | Download the source code. You can either download it as a zip file and 6 | extract it or simply execute the following command in the terminal. 7 | 8 | `git clone 9 | https://github.com/food-boot/Food-Delivery-Web-App-BackEnd-SpringBoot.git` 10 | 11 | Change your directory into the project folder. And run the following command. 12 | 13 | `mvn install` 14 | 15 | * For windows try this 16 | [link](https://www.mkyong.com/maven/how-to-install-maven-in-windows/) to 17 | install maven. 18 | * for ubuntu you can use this 19 | [link](https://linuxize.com/post/how-to-install-apache-maven-on-ubuntu-18-04/) 20 | to install maven. 21 | 22 | Next run the command, 23 | 24 | `mvn spring-boot:run` 25 | 26 | and the server will start automatically. Try to visit 27 | [this](http://localhost:8080/food-boot/swagger-ui.html) url to see the api 28 | documentation. 29 | 30 | > NOTE 31 | > 32 | > If you failed to start the server try to configure your database 33 | details with the project. To update database details find the file 34 | located in **`src\main\resources`** and find the file 35 | **`application.properties`**. And update following details. 36 | > 37 | > `spring.datasource.username=` 38 | > `spring.datasource.password=` 39 | > 40 | >And then you will be good to go. Make sure to start the spring app when 41 | you are done editing the above mention file. 42 | 43 | If you wan't to run the war version of the spring app, locate to the 44 | folder `/target` which will be in your directory when you run the `mvn 45 | install command`, and in there you will see you `.war` file. 46 | 47 | To run the war file, use the below code. 48 | 49 | `java -jar food-delivery-web-app-0.0.1-SNAPSHOT.war` 50 | 51 | ## Docker Installation 52 | 53 | The docker file containing the docker image building is in the **1.0.0 branch**. If you wish to use the docker file for the building, please follow the following steps. 54 | 55 | 1. Make sure you have already installed Docker in your machine. If it is not, please refere [this](https://docs.docker.com/engine/install/) link. 56 | 2. Switch to the 1.0.0 branch 57 | `git checkout 1.0.0` 58 | 3. Use a terminal inside the project where the Dockerfile is located. Execute the following command to build the image. Replace `` by the tag of your own. 59 | `docker build --tag .` 60 | 5. Run the image as a container. 61 | `docker run -d -p 8080:8080 ` 62 | 7. Use [docker exec](https://docs.docker.com/engine/reference/commandline/exec/) command to access the container. 63 | 64 | PR's are welcome. Please submit any issue that you faced when developing your spring-boot application. 65 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | We are still developing this project and we take bugs very seriously. If you found any bug with respect to the supported version please report it to us. 6 | 7 | | Version | Supported | 8 | | ------- | ------------------ | 9 | | 1.2.x - beta | :white_check_mark: | 10 | | 1.2.x - alpha | :white_check_mark: | 11 | | 1.0.x | :white_check_mark: | 12 | | < 0.1 | :x: | 13 | 14 | ## Reporting a Vulnerability 15 | 16 | Use the issue template for reporting security vulnerabilities. Make sure to indicate the bug-reproducing method in your issue. 17 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /bin/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | /target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | 5 | ### STS ### 6 | .apt_generated 7 | .classpath 8 | .factorypath 9 | .project 10 | .settings 11 | .springBeans 12 | .sts4-cache 13 | 14 | ### IntelliJ IDEA ### 15 | .idea 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 | -------------------------------------------------------------------------------- /bin/.mvn/wrapper/MavenWrapperDownloader.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/food-boot/food_delivery_web_app_backend_springboot/9f8bdcd998805c2d15d46ece0fa69ed2c48ad3a7/bin/.mvn/wrapper/MavenWrapperDownloader.class -------------------------------------------------------------------------------- /bin/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/food-boot/food_delivery_web_app_backend_springboot/9f8bdcd998805c2d15d46ece0fa69ed2c48ad3a7/bin/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /bin/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | -------------------------------------------------------------------------------- /bin/README.md: -------------------------------------------------------------------------------- 1 | # Food-Delivery-Web-App-BackEnd-ScpringBoot 2 | -------------------------------------------------------------------------------- /bin/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 | -------------------------------------------------------------------------------- /bin/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 | -------------------------------------------------------------------------------- /bin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.1.4.RELEASE 9 | 10 | 11 | com.food.delivery.app.ws 12 | food-delivery-web-app 13 | 0.0.1-SNAPSHOT 14 | food-delivery-web-app 15 | Demo project for Spring Boot 16 | 17 | 18 | 1.8 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-test 30 | test 31 | 32 | 33 | 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-maven-plugin 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /bin/src/main/java/com/food/delivery/app/ws/FoodDeliveryWebAppApplication.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/food-boot/food_delivery_web_app_backend_springboot/9f8bdcd998805c2d15d46ece0fa69ed2c48ad3a7/bin/src/main/java/com/food/delivery/app/ws/FoodDeliveryWebAppApplication.class -------------------------------------------------------------------------------- /bin/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /bin/src/test/java/com/food/delivery/app/ws/FoodDeliveryWebAppApplicationTests.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/food-boot/food_delivery_web_app_backend_springboot/9f8bdcd998805c2d15d46ece0fa69ed2c48ad3a7/bin/src/test/java/com/food/delivery/app/ws/FoodDeliveryWebAppApplicationTests.class -------------------------------------------------------------------------------- /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 | 5 | 4.0.0 6 | 7 | org.springframework.boot 8 | spring-boot-starter-parent 9 | 2.1.4.RELEASE 10 | 11 | 12 | com.food.delivery.app.ws 13 | food-delivery-web-app 14 | 1.0.0-SNAPSHOT 15 | war 16 | food-delivery-web-app 17 | Food Delivery Web App End Points 18 | 19 | 20 | 1.8 21 | 22 | 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-web 27 | 28 | 29 | 30 | com.fasterxml.jackson.dataformat 31 | jackson-dataformat-xml 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-data-jpa 37 | 38 | 39 | 40 | mysql 41 | mysql-connector-java 42 | 43 | 44 | 45 | org.springframework.boot 46 | spring-boot-starter-security 47 | 48 | 49 | 50 | io.jsonwebtoken 51 | jjwt 52 | 0.9.1 53 | 54 | 55 | 56 | org.springframework.boot 57 | spring-boot-starter-tomcat 58 | provided 59 | 60 | 61 | 62 | 63 | org.modelmapper 64 | modelmapper 65 | 2.3.8 66 | 67 | 68 | 69 | org.springframework.boot 70 | spring-boot-starter-hateoas 71 | 72 | 73 | 74 | org.springframework.boot 75 | spring-boot-starter-test 76 | test 77 | 78 | 79 | 80 | io.springfox 81 | springfox-swagger2 82 | 3.0.0 83 | 84 | 85 | 86 | io.springfox 87 | springfox-swagger-ui 88 | 3.0.0 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | org.springframework.boot 97 | spring-boot-maven-plugin 98 | 99 | 100 | 101 | 102 | 103 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/FoodDeliveryWebAppApplication.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.builder.SpringApplicationBuilder; 6 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 9 | 10 | @SpringBootApplication 11 | public class FoodDeliveryWebAppApplication extends SpringBootServletInitializer{ 12 | 13 | @Override 14 | protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { 15 | return application.sources(FoodDeliveryWebAppApplication.class); 16 | } 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(FoodDeliveryWebAppApplication.class, args); 20 | } 21 | 22 | @Bean 23 | public BCryptPasswordEncoder bCryptPasswordEncoder() { 24 | return new BCryptPasswordEncoder(); 25 | } 26 | 27 | @Bean 28 | public SpringApplicationContext springApplicationContext() { 29 | return new SpringApplicationContext(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/SpringApplicationContext.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.ApplicationContextAware; 6 | 7 | public class SpringApplicationContext implements ApplicationContextAware{ 8 | 9 | private static ApplicationContext CONTEXT; 10 | 11 | @Override 12 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 13 | CONTEXT = applicationContext; 14 | } 15 | 16 | public static Object getBean(String beanName) { 17 | return CONTEXT.getBean(beanName); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.HashSet; 6 | import java.util.List; 7 | 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | 11 | import springfox.documentation.builders.PathSelectors; 12 | import springfox.documentation.builders.RequestHandlerSelectors; 13 | import springfox.documentation.service.ApiInfo; 14 | import springfox.documentation.service.Contact; 15 | import springfox.documentation.service.VendorExtension; 16 | import springfox.documentation.spi.DocumentationType; 17 | import springfox.documentation.spring.web.plugins.Docket; 18 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 19 | 20 | @Configuration 21 | @EnableSwagger2 22 | public class SwaggerConfig { 23 | 24 | Contact contact = new Contact( 25 | "Food-Boot", 26 | "https://food-boot.github.io/Food-Delivery-Web-App-BackEnd-ScpringBoot", 27 | "shehandvid@gmail.com"); 28 | 29 | List vendorExtensions = new ArrayList<>(); 30 | 31 | ApiInfo apiInfo = new ApiInfo( 32 | "Food Delivery Web App - RESTful web services documentation", 33 | "This pages documents all the available RESTful Web Service endpoints", 34 | "1.0.0", 35 | "https://github.com/food-boot/Food-Delivery-Web-App-BackEnd-ScpringBoot", 36 | contact, 37 | "Apache-2.0", 38 | "https://opensource.org/licenses/Apache-2.0", 39 | vendorExtensions); 40 | 41 | @Bean 42 | public Docket apiDocket() { 43 | Docket docket = new Docket(DocumentationType.SWAGGER_2) 44 | .protocols(new HashSet<>(Arrays.asList("HTTP","HTTPS"))) 45 | .apiInfo(apiInfo) 46 | .select() 47 | .apis(RequestHandlerSelectors.basePackage("com.food.delivery.app.ws")) 48 | .paths(PathSelectors.any()) 49 | .build(); 50 | 51 | return docket; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/io/entity/FoodEntity.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.io.entity; 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.Id; 9 | 10 | @Entity(name = "foods") 11 | public class FoodEntity implements Serializable { 12 | 13 | private static final long serialVersionUID = 767958036359069705L; 14 | 15 | @Id 16 | @GeneratedValue 17 | private long id; 18 | 19 | @Column(nullable = false) 20 | private String foodId; 21 | 22 | @Column(nullable = false) 23 | private String foodName; 24 | 25 | @Column(nullable = false) 26 | private float foodPrice; 27 | 28 | @Column(nullable = false) 29 | private String foodCategory; 30 | 31 | public long getId() { 32 | return id; 33 | } 34 | 35 | public void setId(long id) { 36 | this.id = id; 37 | } 38 | 39 | public String getFoodId() { 40 | return foodId; 41 | } 42 | 43 | public void setFoodId(String foodId) { 44 | this.foodId = foodId; 45 | } 46 | 47 | public String getFoodName() { 48 | return foodName; 49 | } 50 | 51 | public void setFoodName(String foodName) { 52 | this.foodName = foodName; 53 | } 54 | 55 | public float getFoodPrice() { 56 | return foodPrice; 57 | } 58 | 59 | public void setFoodPrice(float foodPrice) { 60 | this.foodPrice = foodPrice; 61 | } 62 | 63 | public String getFoodCategory() { 64 | return foodCategory; 65 | } 66 | 67 | public void setFoodCategory(String foodCategory) { 68 | this.foodCategory = foodCategory; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/io/entity/OrderEntity.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.io.entity; 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.Id; 9 | 10 | @Entity(name = "orders") 11 | public class OrderEntity implements Serializable { 12 | 13 | private static final long serialVersionUID = -6946120796474180178L; 14 | 15 | @Id 16 | @GeneratedValue 17 | private long id; 18 | 19 | @Column(nullable = false) 20 | private String orderId; 21 | 22 | @Column(nullable = false) 23 | private float cost; 24 | 25 | @Column(nullable = false) 26 | private String[] items; 27 | 28 | @Column(nullable = false) 29 | private String userId; 30 | 31 | @Column(nullable = false) 32 | private boolean status; 33 | 34 | public long getId() { 35 | return id; 36 | } 37 | 38 | public void setId(long id) { 39 | this.id = id; 40 | } 41 | 42 | public String getOrderId() { 43 | return orderId; 44 | } 45 | 46 | public void setOrderId(String orderId) { 47 | this.orderId = orderId; 48 | } 49 | 50 | public float getCost() { 51 | return cost; 52 | } 53 | 54 | public void setCost(float cost) { 55 | this.cost = cost; 56 | } 57 | 58 | public String[] getItems() { 59 | return items; 60 | } 61 | 62 | public void setItems(String[] items) { 63 | this.items = items; 64 | } 65 | 66 | public String getUserId() { 67 | return userId; 68 | } 69 | 70 | public void setUserId(String userId) { 71 | this.userId = userId; 72 | } 73 | 74 | public boolean isStatus() { 75 | return status; 76 | } 77 | 78 | public void setStatus(boolean status) { 79 | this.status = status; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/io/entity/UserEntity.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.io.entity; 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.Id; 9 | 10 | @Entity(name = "users") 11 | public class UserEntity implements Serializable { 12 | 13 | private static final long serialVersionUID = -3753911216867256002L; 14 | 15 | @Id 16 | @GeneratedValue 17 | private long id; 18 | 19 | @Column(nullable = false) 20 | private String userId; 21 | 22 | @Column(nullable = false, length = 20) 23 | private String firstName; 24 | 25 | @Column(nullable = false, length = 50) 26 | private String lastName; 27 | 28 | @Column(nullable = false, length = 120, unique = true) 29 | private String email; 30 | 31 | @Column(nullable = false) 32 | private String encryptedPassword; 33 | 34 | @Column(nullable = false) 35 | private String picURL; 36 | 37 | @Column(nullable = false) 38 | private String userType; 39 | 40 | public long getId() { 41 | return id; 42 | } 43 | 44 | public void setId(long id) { 45 | this.id = id; 46 | } 47 | 48 | public String getUserId() { 49 | return userId; 50 | } 51 | 52 | public void setUserId(String userId) { 53 | this.userId = userId; 54 | } 55 | 56 | public String getFirstName() { 57 | return firstName; 58 | } 59 | 60 | public void setFirstName(String firstName) { 61 | this.firstName = firstName; 62 | } 63 | 64 | public String getLastName() { 65 | return lastName; 66 | } 67 | 68 | public void setLastName(String lastName) { 69 | this.lastName = lastName; 70 | } 71 | 72 | public String getEmail() { 73 | return email; 74 | } 75 | 76 | public void setEmail(String email) { 77 | this.email = email; 78 | } 79 | 80 | public String getEncryptedPassword() { 81 | return encryptedPassword; 82 | } 83 | 84 | public void setEncryptedPassword(String encryptedPassword) { 85 | this.encryptedPassword = encryptedPassword; 86 | } 87 | 88 | public String getPicURL() { 89 | return picURL; 90 | } 91 | 92 | public void setPicURL(String picURL) { 93 | this.picURL = picURL; 94 | } 95 | 96 | public String getUserType() { 97 | return userType; 98 | } 99 | 100 | public void setUserType(String userType) { 101 | this.userType = userType; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/io/repository/FoodRepository.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.io.repository; 2 | 3 | import org.springframework.data.repository.CrudRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import com.food.delivery.app.ws.io.entity.FoodEntity; 7 | 8 | @Repository 9 | public interface FoodRepository extends CrudRepository { 10 | 11 | FoodEntity findByFoodId(String foodId); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/io/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.io.repository; 2 | 3 | import org.springframework.data.repository.CrudRepository; 4 | import org.springframework.stereotype.Repository; 5 | import com.food.delivery.app.ws.io.entity.OrderEntity; 6 | 7 | @Repository 8 | public interface OrderRepository extends CrudRepository { 9 | 10 | OrderEntity findByOrderId(String orderId); 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/io/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.io.repository; 2 | 3 | import org.springframework.data.repository.PagingAndSortingRepository; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import com.food.delivery.app.ws.io.entity.UserEntity; 7 | 8 | @Repository 9 | public interface UserRepository extends PagingAndSortingRepository { 10 | 11 | UserEntity findByEmail(String email); 12 | UserEntity findByUserId(String userId); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/model/request/FoodDetailsRequestModel.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.model.request; 2 | 3 | public class FoodDetailsRequestModel { 4 | 5 | private String foodName; 6 | private String foodCategory; 7 | private float foodPrice; 8 | 9 | public String getFoodName() { 10 | return foodName; 11 | } 12 | 13 | public void setFoodName(String foodName) { 14 | this.foodName = foodName; 15 | } 16 | 17 | public String getFoodCategory() { 18 | return foodCategory; 19 | } 20 | 21 | public void setFoodCategory(String foodCategory) { 22 | this.foodCategory = foodCategory; 23 | } 24 | 25 | public float getFoodPrice() { 26 | return foodPrice; 27 | } 28 | 29 | public void setFoodPrice(float foodPrice) { 30 | this.foodPrice = foodPrice; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/model/request/LoginRequest.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.model.request; 2 | 3 | public class LoginRequest { 4 | 5 | private String email; 6 | private String password; 7 | 8 | public String getEmail() { 9 | return email; 10 | } 11 | 12 | public void setEmail(String email) { 13 | this.email = email; 14 | } 15 | 16 | public String getPassword() { 17 | return password; 18 | } 19 | 20 | public void setPassword(String password) { 21 | this.password = password; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/model/request/OrderDetailsRequestModel.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.model.request; 2 | 3 | public class OrderDetailsRequestModel { 4 | 5 | private String[] items; 6 | private float cost; 7 | private String userId; 8 | 9 | public float getCost() { 10 | return cost; 11 | } 12 | 13 | public void setCost(float cost) { 14 | this.cost = cost; 15 | } 16 | 17 | public String[] getItems() { 18 | return items; 19 | } 20 | 21 | public void setItems(String[] items) { 22 | this.items = items; 23 | } 24 | 25 | public String getUserId() { 26 | return userId; 27 | } 28 | 29 | public void setUserId(String userId) { 30 | this.userId = userId; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/model/request/UserDetailsRequestModel.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.model.request; 2 | 3 | public class UserDetailsRequestModel { 4 | 5 | private String firstName; 6 | private String lastName; 7 | private String email; 8 | private String password; 9 | 10 | public String getFirstName() { 11 | return firstName; 12 | } 13 | 14 | public void setFirstName(String firstName) { 15 | this.firstName = firstName; 16 | } 17 | 18 | public String getLastName() { 19 | return lastName; 20 | } 21 | 22 | public void setLastName(String lastName) { 23 | this.lastName = lastName; 24 | } 25 | 26 | public String getEmail() { 27 | return email; 28 | } 29 | 30 | public void setEmail(String email) { 31 | this.email = email; 32 | } 33 | 34 | public String getPassword() { 35 | return password; 36 | } 37 | 38 | public void setPassword(String password) { 39 | this.password = password; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/model/request/UserLoginRequseModel.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.model.request; 2 | 3 | public class UserLoginRequseModel { 4 | 5 | private String email; 6 | private String password; 7 | 8 | public String getEmail() { 9 | return email; 10 | } 11 | 12 | public void setEmail(String email) { 13 | this.email = email; 14 | } 15 | 16 | public String getPassword() { 17 | return password; 18 | } 19 | 20 | public void setPassword(String password) { 21 | this.password = password; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/model/response/FoodDetailsResponse.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.model.response; 2 | 3 | public class FoodDetailsResponse { 4 | 5 | private String foodId; 6 | private String foodName; 7 | private float foodPrice; 8 | private String foodCategory; 9 | 10 | public String getFoodId() { 11 | return foodId; 12 | } 13 | 14 | public void setFoodId(String foodId) { 15 | this.foodId = foodId; 16 | } 17 | 18 | public String getFoodName() { 19 | return foodName; 20 | } 21 | 22 | public void setFoodName(String foodName) { 23 | this.foodName = foodName; 24 | } 25 | 26 | public float getFoodPrice() { 27 | return foodPrice; 28 | } 29 | 30 | public void setFoodPrice(float foodPrice) { 31 | this.foodPrice = foodPrice; 32 | } 33 | 34 | public String getFoodCategory() { 35 | return foodCategory; 36 | } 37 | 38 | public void setFoodCategory(String foodCategory) { 39 | this.foodCategory = foodCategory; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/model/response/OperationStatusModel.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.model.response; 2 | 3 | public class OperationStatusModel { 4 | 5 | private String operationResult; 6 | private String operationName; 7 | 8 | public String getOperationResult() { 9 | return operationResult; 10 | } 11 | 12 | public void setOperationResult(String operationResult) { 13 | this.operationResult = operationResult; 14 | } 15 | 16 | public String getOperationName() { 17 | return operationName; 18 | } 19 | 20 | public void setOperationName(String operationName) { 21 | this.operationName = operationName; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/model/response/OrderDetailsResponse.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.model.response; 2 | 3 | 4 | public class OrderDetailsResponse { 5 | 6 | private String orderId; 7 | private float cost; 8 | private String items[]; 9 | private String userId; 10 | private boolean status; 11 | 12 | public String getOrderId() { 13 | return orderId; 14 | } 15 | 16 | public void setOrderId(String orderId) { 17 | this.orderId = orderId; 18 | } 19 | 20 | public float getCost() { 21 | return cost; 22 | } 23 | 24 | public void setCost(float cost) { 25 | this.cost = cost; 26 | } 27 | 28 | public String[] getItems() { 29 | return items; 30 | } 31 | 32 | public void setItems(String[] items) { 33 | this.items = items; 34 | } 35 | 36 | public String getUserId() { 37 | return userId; 38 | } 39 | 40 | public void setUserId(String userId) { 41 | this.userId = userId; 42 | } 43 | 44 | public boolean isStatus() { 45 | return status; 46 | } 47 | 48 | public void setStatus(boolean status) { 49 | this.status = status; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/model/response/RequestOperationName.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.model.response; 2 | 3 | public enum RequestOperationName { 4 | 5 | DELETE 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/model/response/RequestOperationStatus.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.model.response; 2 | 3 | public enum RequestOperationStatus { 4 | 5 | ERROR, SUCCESS 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/model/response/UserRest.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.model.response; 2 | 3 | public class UserRest { 4 | 5 | private String userId; 6 | private String email; 7 | private String firstName; 8 | private String lastName; 9 | private String picURL; 10 | private String userType; 11 | 12 | public String getUserId() { 13 | return userId; 14 | } 15 | 16 | public void setUserId(String userId) { 17 | this.userId = userId; 18 | } 19 | 20 | public String getEmail() { 21 | return email; 22 | } 23 | 24 | public void setEmail(String email) { 25 | this.email = email; 26 | } 27 | 28 | public String getFirstName() { 29 | return firstName; 30 | } 31 | 32 | public void setFirstName(String firstName) { 33 | this.firstName = firstName; 34 | } 35 | 36 | public String getLastName() { 37 | return lastName; 38 | } 39 | 40 | public void setLastName(String lastName) { 41 | this.lastName = lastName; 42 | } 43 | 44 | public String getPicURL() { 45 | return picURL; 46 | } 47 | 48 | public void setPicURL(String picURL) { 49 | this.picURL = picURL; 50 | } 51 | 52 | public String getUserType() { 53 | return userType; 54 | } 55 | 56 | public void setUserType(String userType) { 57 | this.userType = userType; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/security/AuthenticationFilter.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.security; 2 | 3 | import java.io.IOException; 4 | import java.rmi.ServerException; 5 | import java.util.ArrayList; 6 | import java.util.Date; 7 | 8 | import javax.servlet.FilterChain; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | 12 | import org.springframework.security.authentication.AuthenticationManager; 13 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 14 | import org.springframework.security.core.Authentication; 15 | import org.springframework.security.core.AuthenticationException; 16 | import org.springframework.security.core.userdetails.User; 17 | import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; 18 | 19 | import com.fasterxml.jackson.databind.ObjectMapper; 20 | import com.food.delivery.app.ws.SpringApplicationContext; 21 | import com.food.delivery.app.ws.model.request.UserLoginRequseModel; 22 | import com.food.delivery.app.ws.service.UserService; 23 | import com.food.delivery.app.ws.shared.dto.UserDto; 24 | 25 | import io.jsonwebtoken.Jwts; 26 | import io.jsonwebtoken.SignatureAlgorithm; 27 | 28 | public class AuthenticationFilter extends UsernamePasswordAuthenticationFilter { 29 | 30 | private final AuthenticationManager authenticationManager; 31 | 32 | public AuthenticationFilter(AuthenticationManager authenticationManager) { 33 | this.authenticationManager = authenticationManager; 34 | } 35 | 36 | @Override 37 | public Authentication attemptAuthentication(HttpServletRequest req, HttpServletResponse res) 38 | throws AuthenticationException { 39 | 40 | try { 41 | UserLoginRequseModel creds = new ObjectMapper().readValue(req.getInputStream(), UserLoginRequseModel.class); 42 | 43 | return authenticationManager.authenticate( 44 | new UsernamePasswordAuthenticationToken(creds.getEmail(), creds.getPassword(), new ArrayList<>())); 45 | 46 | } catch (IOException e) { 47 | throw new RuntimeException(e); 48 | } 49 | } 50 | 51 | @Override 52 | protected void successfulAuthentication(HttpServletRequest req, HttpServletResponse res, FilterChain chain, 53 | Authentication auth) throws IOException, ServerException { 54 | 55 | String userName = ((User) auth.getPrincipal()).getUsername(); 56 | 57 | String token = Jwts.builder().setSubject(userName) 58 | .setExpiration(new Date(System.currentTimeMillis() + SecurityConstants.EXPIRATION_TIME)) 59 | .signWith(SignatureAlgorithm.HS512, SecurityConstants.TOKEN_SECRET).compact(); 60 | 61 | UserService userService = (UserService) SpringApplicationContext.getBean("userServiceImpl"); 62 | UserDto userDto = userService.getUser(userName); 63 | 64 | res.addHeader(SecurityConstants.HEADER_STRING, SecurityConstants.TOKEN_PREFIX + token); 65 | res.addHeader("UserID", userDto.getUserId()); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/security/AuthorizationFilter.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.security; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | 6 | import javax.servlet.FilterChain; 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | import org.springframework.security.authentication.AuthenticationManager; 12 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 13 | import org.springframework.security.core.context.SecurityContextHolder; 14 | import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; 15 | 16 | import io.jsonwebtoken.Jwts; 17 | 18 | public class AuthorizationFilter extends BasicAuthenticationFilter { 19 | 20 | public AuthorizationFilter(AuthenticationManager authManager) { 21 | super(authManager); 22 | } 23 | 24 | @Override 25 | protected void doFilterInternal(HttpServletRequest req, HttpServletResponse res, FilterChain chain) 26 | throws IOException, ServletException { 27 | String header = req.getHeader(SecurityConstants.HEADER_STRING); 28 | 29 | if (header == null || !header.startsWith(SecurityConstants.TOKEN_PREFIX)) { 30 | chain.doFilter(req, res); 31 | return; 32 | } 33 | 34 | UsernamePasswordAuthenticationToken authentication = getAuthentication(req); 35 | SecurityContextHolder.getContext().setAuthentication(authentication); 36 | chain.doFilter(req, res); 37 | } 38 | 39 | private UsernamePasswordAuthenticationToken getAuthentication(HttpServletRequest request) { 40 | String token = request.getHeader(SecurityConstants.HEADER_STRING); 41 | 42 | if (token != null) { 43 | token = token.replace(SecurityConstants.TOKEN_PREFIX, ""); 44 | 45 | String user = Jwts.parser().setSigningKey(SecurityConstants.TOKEN_SECRET).parseClaimsJws(token).getBody() 46 | .getSubject(); 47 | 48 | if (user != null) { 49 | return new UsernamePasswordAuthenticationToken(user, null, new ArrayList<>()); 50 | } 51 | } 52 | 53 | return null; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/security/SecurityConstants.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.security; 2 | 3 | public class SecurityConstants { 4 | 5 | public static final long EXPIRATION_TIME = 864000000; 6 | public static final String TOKEN_PREFIX = "Bearer "; 7 | public static final String HEADER_STRING = "Authorization"; 8 | public static final String SIGN_UP_URL = "/users"; 9 | public static final String TOKEN_SECRET = "Jsaf9GHasdf732rvas"; 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/security/WebSecurity.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.security; 2 | 3 | import java.util.Arrays; 4 | 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.http.HttpMethod; 7 | import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 8 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 9 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 10 | import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 11 | import org.springframework.security.config.http.SessionCreationPolicy; 12 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 13 | import org.springframework.web.cors.CorsConfiguration; 14 | import org.springframework.web.cors.CorsConfigurationSource; 15 | import org.springframework.web.cors.UrlBasedCorsConfigurationSource; 16 | 17 | import com.food.delivery.app.ws.service.UserService; 18 | 19 | @EnableWebSecurity 20 | public class WebSecurity extends WebSecurityConfigurerAdapter { 21 | 22 | private final UserService userDetailsService; 23 | private final BCryptPasswordEncoder bCryptPasswordEncoder; 24 | 25 | public WebSecurity(UserService userDetailsService, BCryptPasswordEncoder bCryptPasswordEncoder) { 26 | this.userDetailsService = userDetailsService; 27 | this.bCryptPasswordEncoder = bCryptPasswordEncoder; 28 | } 29 | 30 | @Override 31 | protected void configure(HttpSecurity http) throws Exception { 32 | 33 | http 34 | .cors().and() 35 | .csrf().authorizeRequests() 36 | .antMatchers(HttpMethod.POST, SecurityConstants.SIGN_UP_URL) 37 | .permitAll() 38 | .antMatchers("/v2/api-docs", "/configuration/**", "/swagger*/**", "/webjars/**") 39 | .permitAll() 40 | .anyRequest().authenticated().and() 41 | .addFilter(getAuthenticationFilter()) 42 | .addFilter(new AuthorizationFilter(authenticationManager())) 43 | .sessionManagement() 44 | .sessionCreationPolicy(SessionCreationPolicy.STATELESS); 45 | } 46 | 47 | @Bean 48 | CorsConfigurationSource corsConfigurationSource() { 49 | CorsConfiguration configuration = new CorsConfiguration(); 50 | 51 | configuration.setAllowedOrigins(Arrays.asList("*")); 52 | // or any domain that you want to restrict to 53 | configuration.addAllowedHeader("Authorization"); 54 | configuration.addAllowedHeader("Content-Type"); 55 | configuration.addAllowedHeader("Accept"); 56 | configuration.addAllowedHeader("UserID"); 57 | configuration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE")); 58 | configuration.setAllowedHeaders(Arrays.asList("*")); 59 | // Add the method support as you like 60 | UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); 61 | source.registerCorsConfiguration("/**", configuration); 62 | return source; 63 | } 64 | 65 | @Override 66 | public void configure(AuthenticationManagerBuilder auth) throws Exception { 67 | auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder); 68 | } 69 | 70 | public AuthenticationFilter getAuthenticationFilter() throws Exception { 71 | final AuthenticationFilter filter = new AuthenticationFilter(authenticationManager()); 72 | filter.setFilterProcessesUrl("/users/login"); 73 | return filter; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/service/FoodService.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.service; 2 | 3 | import java.util.List; 4 | 5 | import com.food.delivery.app.ws.shared.dto.FoodDto; 6 | 7 | public interface FoodService { 8 | 9 | FoodDto createFood(FoodDto food); 10 | FoodDto getFoodById(String foodId); 11 | FoodDto updateFoodDetails(String foodId, FoodDto foodDetails); 12 | void deleteFoodItem(String id); 13 | List getFoods(); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.service; 2 | 3 | import java.util.List; 4 | 5 | import com.food.delivery.app.ws.shared.dto.OrderDto; 6 | 7 | public interface OrderService { 8 | 9 | OrderDto createOrder(OrderDto order); 10 | OrderDto getOrderById(String orderId); 11 | OrderDto updateOrderDetails(String orderId, OrderDto order); 12 | void deleteOrder(String orderId); 13 | List getOrders(); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.service; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.security.core.userdetails.UserDetailsService; 6 | 7 | import com.food.delivery.app.ws.shared.dto.UserDto; 8 | 9 | public interface UserService extends UserDetailsService{ 10 | 11 | UserDto createUser(UserDto user); 12 | UserDto getUser(String email); 13 | UserDto getUserByUserId(String userId); 14 | UserDto updateUser(String userId, UserDto user); 15 | void deleteUser(String userId); 16 | List getUsers(); 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/service/impl/FoodServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.service.impl; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.modelmapper.ModelMapper; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.BeanUtils; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 11 | import org.springframework.stereotype.Service; 12 | 13 | import com.food.delivery.app.ws.io.entity.FoodEntity; 14 | import com.food.delivery.app.ws.io.repository.FoodRepository; 15 | import com.food.delivery.app.ws.service.FoodService; 16 | import com.food.delivery.app.ws.shared.Utils; 17 | import com.food.delivery.app.ws.shared.dto.FoodDto; 18 | 19 | @Service 20 | public class FoodServiceImpl implements FoodService { 21 | 22 | @Autowired 23 | FoodRepository foodRepository; 24 | 25 | @Autowired 26 | Utils utils; 27 | 28 | /** 29 | * Logger initialization 30 | */ 31 | org.slf4j.Logger logger = LoggerFactory.getLogger(UserServiceImpl.class); 32 | 33 | /** 34 | * Create food method 35 | */ 36 | @Override 37 | public FoodDto createFood(FoodDto food) { 38 | 39 | logger.info("FoodService -> createFood(food) method is called."); 40 | 41 | ModelMapper modelMapper = new ModelMapper(); 42 | FoodEntity foodEntity = modelMapper.map(food, FoodEntity.class); 43 | 44 | logger.info("Creating new food"); 45 | 46 | String publicFoodId = utils.generateFoodId(30); 47 | foodEntity.setFoodId(publicFoodId); 48 | 49 | logger.info("Saving the food to the database -> foods"); 50 | 51 | FoodEntity storedFood = foodRepository.save(foodEntity); 52 | 53 | FoodDto foodDto = new FoodDto(); 54 | foodDto = modelMapper.map(storedFood, FoodDto.class); 55 | 56 | logger.info("Returning the food details to the FoodController via FoodDto object"); 57 | 58 | return foodDto; 59 | } 60 | 61 | /** 62 | * Get food by food id method 63 | */ 64 | @Override 65 | public FoodDto getFoodById(String foodId) throws UsernameNotFoundException { 66 | 67 | logger.info("FoodService -> getFoodById(foodId) method is called. Finding the food"); 68 | 69 | FoodDto returnValue = new FoodDto(); 70 | ModelMapper modelMapper = new ModelMapper(); 71 | 72 | FoodEntity foodEntity = foodRepository.findByFoodId(foodId); 73 | 74 | if (foodEntity == null) { 75 | 76 | logger.error("Can't find the food id from the database"); 77 | 78 | throw new UsernameNotFoundException(foodId); 79 | } 80 | 81 | returnValue = modelMapper.map(foodEntity, FoodDto.class); 82 | 83 | logger.info("Food details found. Returning the food to the FoodController via FoodDto object"); 84 | 85 | return returnValue; 86 | } 87 | 88 | /** 89 | * Update food method 90 | */ 91 | @Override 92 | public FoodDto updateFoodDetails(String foodId, FoodDto foodDetails) throws UsernameNotFoundException { 93 | 94 | logger.info("FoodService -> updateFoodDetails(foodId, foodDetails) method is called. Finding the food"); 95 | 96 | FoodDto returnValue = new FoodDto(); 97 | ModelMapper modelMapper = new ModelMapper(); 98 | 99 | FoodEntity foodEntity = foodRepository.findByFoodId(foodId); 100 | 101 | if (foodEntity == null) { 102 | 103 | logger.error("Can't find the food id from the database"); 104 | 105 | throw new UsernameNotFoundException(foodId); 106 | } 107 | 108 | logger.info("Food details found. Updating food details"); 109 | 110 | foodEntity.setFoodCategory(foodDetails.getFoodCategory()); 111 | foodEntity.setFoodName(foodDetails.getFoodName()); 112 | foodEntity.setFoodPrice(foodDetails.getFoodPrice()); 113 | 114 | logger.info("Saving updated details to the database -> foods"); 115 | 116 | FoodEntity updatedFoodEntity = foodRepository.save(foodEntity); 117 | returnValue = modelMapper.map(updatedFoodEntity, FoodDto.class); 118 | 119 | logger.info("Returning the food to the FoodController via FoodDto object"); 120 | 121 | return returnValue; 122 | } 123 | 124 | /** 125 | * Delete use method 126 | */ 127 | @Override 128 | public void deleteFoodItem(String id) throws UsernameNotFoundException { 129 | 130 | logger.info("FoodService -> deleteFoodItem(foodId) method is called. Finding the food"); 131 | 132 | FoodEntity foodEntity = foodRepository.findByFoodId(id); 133 | 134 | if (foodEntity == null) { 135 | 136 | logger.error("Can't find the food id from the database"); 137 | 138 | throw new UsernameNotFoundException(id);} 139 | 140 | logger.info("Food details found. Deleting the food from the database -> foods"); 141 | 142 | foodRepository.delete(foodEntity); 143 | 144 | } 145 | 146 | @Override 147 | public List getFoods() { 148 | 149 | logger.info("FoodService -> getFoods() method is called. Collecting all food items details"); 150 | 151 | List returnValue = new ArrayList<>(); 152 | Iterable iterableObjects = foodRepository.findAll(); 153 | 154 | for (FoodEntity foodEntity : iterableObjects) { 155 | FoodDto foodDto = new FoodDto(); 156 | BeanUtils.copyProperties(foodEntity, foodDto); 157 | returnValue.add(foodDto); 158 | } 159 | 160 | logger.info("Foods' details found. Returning foods to the FoodController via List"); 161 | 162 | return returnValue; 163 | } 164 | 165 | } 166 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/service/impl/OrderServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.service.impl; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.modelmapper.ModelMapper; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.BeanUtils; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 11 | import org.springframework.stereotype.Service; 12 | 13 | import com.food.delivery.app.ws.io.entity.OrderEntity; 14 | import com.food.delivery.app.ws.io.repository.OrderRepository; 15 | import com.food.delivery.app.ws.service.OrderService; 16 | import com.food.delivery.app.ws.shared.Utils; 17 | import com.food.delivery.app.ws.shared.dto.OrderDto; 18 | 19 | @Service 20 | public class OrderServiceImpl implements OrderService { 21 | 22 | @Autowired 23 | OrderRepository orderRepository; 24 | 25 | @Autowired 26 | Utils utils; 27 | 28 | /** 29 | * Logger initialization 30 | */ 31 | org.slf4j.Logger logger = LoggerFactory.getLogger(UserServiceImpl.class); 32 | 33 | /** 34 | * Create order method 35 | */ 36 | @Override 37 | public OrderDto createOrder(OrderDto order) { 38 | 39 | logger.info("OrderService -> createOrder(order) method is called."); 40 | 41 | ModelMapper modelMapper = new ModelMapper(); 42 | OrderEntity orderEntity = modelMapper.map(order, OrderEntity.class); 43 | 44 | logger.info("Creating new order"); 45 | 46 | String orderId = utils.generateOrderId(10); 47 | orderEntity.setOrderId(orderId); 48 | orderEntity.setStatus(false); 49 | 50 | logger.info("Saving the order to the database -> orders"); 51 | 52 | OrderEntity storedOrder = orderRepository.save(orderEntity); 53 | OrderDto returnValue = modelMapper.map(storedOrder, OrderDto.class); 54 | 55 | logger.info("Returning the order details to the OrderController via OrderDto object"); 56 | 57 | return returnValue; 58 | } 59 | 60 | /** 61 | * Get order by order id method 62 | */ 63 | @Override 64 | public OrderDto getOrderById(String orderId) throws UsernameNotFoundException { 65 | 66 | logger.info("OrderService -> getOrderById(orderId) method is called. Finding the order"); 67 | 68 | OrderDto returnValue = new OrderDto(); 69 | ModelMapper modelMapper = new ModelMapper(); 70 | 71 | OrderEntity orderEntity = orderRepository.findByOrderId(orderId); 72 | 73 | if (orderEntity == null) { 74 | 75 | logger.error("Can't find the order id from the database"); 76 | 77 | throw new UsernameNotFoundException(orderId); 78 | } 79 | 80 | returnValue = modelMapper.map(orderEntity, OrderDto.class); 81 | 82 | logger.info("Order details found. Returning the order to the OrderController via OrderDto object"); 83 | 84 | return returnValue; 85 | } 86 | 87 | /** 88 | * Update food method 89 | */ 90 | @Override 91 | public OrderDto updateOrderDetails(String orderId, OrderDto order) { 92 | 93 | logger.info("OrderService -> updateOrderDetails(orderId, order) method is called. Finding the order"); 94 | 95 | OrderDto returnValue = new OrderDto(); 96 | ModelMapper modelMapper = new ModelMapper(); 97 | 98 | OrderEntity orderEntity = orderRepository.findByOrderId(orderId); 99 | if (orderEntity == null) { 100 | 101 | logger.error("Can't find the order id from the database"); 102 | 103 | throw new UsernameNotFoundException(orderId); 104 | } 105 | 106 | logger.info("Order details found. Updating order details"); 107 | 108 | orderEntity.setCost(order.getCost()); 109 | orderEntity.setItems(order.getItems()); 110 | orderEntity.setStatus(true); 111 | 112 | logger.info("Saving updated details to the database -> orders"); 113 | 114 | OrderEntity updatedOrder = orderRepository.save(orderEntity); 115 | returnValue = modelMapper.map(updatedOrder, OrderDto.class); 116 | 117 | logger.info("Returning the order to the OrderController via OrderDto object"); 118 | 119 | return returnValue; 120 | } 121 | 122 | @Override 123 | public void deleteOrder(String orderId) { 124 | 125 | logger.info("OrderService -> deleteOrder(orderId) method is called. Finding the order"); 126 | 127 | OrderEntity orderEntity = orderRepository.findByOrderId(orderId); 128 | if (orderEntity == null) { 129 | 130 | logger.error("Can't find the order id from the database"); 131 | 132 | throw new UsernameNotFoundException(orderId); 133 | } 134 | 135 | orderRepository.delete(orderEntity); 136 | 137 | } 138 | 139 | /** 140 | * Delete use method 141 | */ 142 | @Override 143 | public List getOrders() { 144 | 145 | logger.info("OrderService -> getOrders() method is called. Collecting all order details"); 146 | 147 | List returnValue = new ArrayList<>(); 148 | 149 | Iterable iteratableObjects = orderRepository.findAll(); 150 | 151 | for (OrderEntity orderEntity : iteratableObjects) { 152 | OrderDto orderDto = new OrderDto(); 153 | BeanUtils.copyProperties(orderEntity, orderDto); 154 | returnValue.add(orderDto); 155 | } 156 | 157 | logger.info("Orders' details found. Returning orders to the OrderController via List"); 158 | 159 | return returnValue; 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.service.impl; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.beans.BeanUtils; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.security.core.userdetails.User; 10 | import org.springframework.security.core.userdetails.UserDetails; 11 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 12 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 13 | import org.springframework.stereotype.Service; 14 | 15 | import com.food.delivery.app.ws.io.entity.UserEntity; 16 | import com.food.delivery.app.ws.io.repository.UserRepository; 17 | import com.food.delivery.app.ws.service.UserService; 18 | import com.food.delivery.app.ws.shared.Utils; 19 | import com.food.delivery.app.ws.shared.dto.UserDto; 20 | 21 | @Service 22 | public class UserServiceImpl implements UserService { 23 | 24 | @Autowired 25 | UserRepository userRepository; 26 | 27 | @Autowired 28 | Utils utils; 29 | 30 | @Autowired 31 | BCryptPasswordEncoder bCryptPasswordEncoder; 32 | 33 | /** 34 | * Logger initialization 35 | */ 36 | org.slf4j.Logger logger = LoggerFactory.getLogger(UserServiceImpl.class); 37 | 38 | /** 39 | * Create user method 40 | */ 41 | @Override 42 | public UserDto createUser(UserDto user) { 43 | 44 | logger.info("UserService -> createUser(user) method is called. Checking database for existing user details"); 45 | 46 | if (userRepository.findByEmail(user.getEmail()) != null) { 47 | 48 | logger.error("Error! Record already exists."); 49 | 50 | throw new RuntimeException("Record already exists!"); 51 | } 52 | 53 | logger.info("Creating new user"); 54 | 55 | UserEntity userEntity = new UserEntity(); 56 | BeanUtils.copyProperties(user, userEntity); 57 | 58 | userEntity.setPicURL("temporory_pic_url"); 59 | userEntity.setEncryptedPassword(bCryptPasswordEncoder.encode(user.getPassword())); 60 | 61 | String publicUserId = utils.generateUserId(30); 62 | userEntity.setUserId(publicUserId); 63 | userEntity.setUserType("user"); 64 | 65 | logger.info("Saving the user to the database -> users"); 66 | 67 | UserEntity storedUserDetails = userRepository.save(userEntity); 68 | 69 | UserDto returnValue = new UserDto(); 70 | BeanUtils.copyProperties(storedUserDetails, returnValue); 71 | 72 | logger.info("Returning the user details to the UserController via UserDto object"); 73 | 74 | return returnValue; 75 | } 76 | 77 | /** 78 | * load user by user name(user id) method 79 | */ 80 | @Override 81 | public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { 82 | 83 | logger.info("UserService -> loadUserByUsername(email) method is called. Finding the user"); 84 | 85 | UserEntity userEntity = userRepository.findByEmail(email); 86 | 87 | if (userEntity == null) { 88 | 89 | logger.error("Can't find the user id from the database"); 90 | 91 | throw new UsernameNotFoundException(email); 92 | } 93 | 94 | logger.info("User details found. Returning the user via new User object"); 95 | 96 | return new User(userEntity.getEmail(), userEntity.getEncryptedPassword(), new ArrayList<>()); 97 | } 98 | 99 | /** 100 | * Get user by email address method 101 | */ 102 | @Override 103 | public UserDto getUser(String email) throws UsernameNotFoundException { 104 | 105 | logger.info("UserService -> getUser(email) method is called. Finding the user"); 106 | 107 | UserEntity userEntity = userRepository.findByEmail(email); 108 | 109 | if (userEntity == null) { 110 | 111 | logger.error("Can't find the user id from the database"); 112 | 113 | throw new UsernameNotFoundException(email); 114 | } 115 | 116 | UserDto returnValue = new UserDto(); 117 | BeanUtils.copyProperties(userEntity, returnValue); 118 | 119 | logger.info("User details found. Returning the user to the UserController via UserDto"); 120 | 121 | return returnValue; 122 | } 123 | 124 | /** 125 | * Get user by user id method 126 | */ 127 | @Override 128 | public UserDto getUserByUserId(String userId) throws UsernameNotFoundException { 129 | 130 | logger.info("UserService -> getUser(userId) method is called. Finding the user"); 131 | 132 | UserDto returnValue = new UserDto(); 133 | UserEntity userEntity = userRepository.findByUserId(userId); 134 | 135 | if (userEntity == null) { 136 | 137 | logger.error("Can't find the user id from the database"); 138 | 139 | throw new UsernameNotFoundException(userId); 140 | } 141 | BeanUtils.copyProperties(userEntity, returnValue); 142 | 143 | logger.info("User details found. Returning the user to the UserController via UserDto object"); 144 | 145 | return returnValue; 146 | } 147 | 148 | /** 149 | * Update user method 150 | */ 151 | @Override 152 | public UserDto updateUser(String userId, UserDto user) throws UsernameNotFoundException { 153 | 154 | logger.info("UserService -> updateUser(userId, user) method is called. Finding the user"); 155 | 156 | UserDto returnValue = new UserDto(); 157 | 158 | UserEntity userEntity = userRepository.findByUserId(userId); 159 | 160 | if (userEntity == null) { 161 | 162 | logger.error("Can't find the user id from the database"); 163 | 164 | throw new UsernameNotFoundException(userId); 165 | } 166 | 167 | logger.info("User details found. Updating user details"); 168 | 169 | userEntity.setFirstName(user.getFirstName()); 170 | userEntity.setLastName(user.getLastName()); 171 | 172 | logger.info("Saving updated details to the database -> users"); 173 | 174 | UserEntity updatedUserDetails = userRepository.save(userEntity); 175 | BeanUtils.copyProperties(updatedUserDetails, returnValue); 176 | 177 | logger.info("Returning the user to the UserController via UserDto object"); 178 | 179 | return returnValue; 180 | } 181 | 182 | /** 183 | * Delete use method 184 | */ 185 | @Override 186 | public void deleteUser(String userId) throws UsernameNotFoundException { 187 | 188 | logger.info("UserService -> deleteUser(userId) method is called. Finding the user"); 189 | 190 | UserEntity userEntity = userRepository.findByUserId(userId); 191 | 192 | if (userEntity == null) { 193 | 194 | logger.error("Can't find the user id from the database"); 195 | 196 | throw new UsernameNotFoundException(userId); 197 | } 198 | 199 | logger.info("User details found. Deleting the user from the database -> users"); 200 | 201 | userRepository.delete(userEntity); 202 | } 203 | 204 | @Override 205 | public List getUsers() { 206 | 207 | logger.info("UserService -> getUsers() method is called. Collection all users details"); 208 | 209 | List returnValue = new ArrayList<>(); 210 | 211 | Iterable iterableObjects = userRepository.findAll(); 212 | 213 | for (UserEntity userEntity : iterableObjects) { 214 | UserDto userDto = new UserDto(); 215 | BeanUtils.copyProperties(userEntity, userDto); 216 | returnValue.add(userDto); 217 | } 218 | 219 | logger.info("Users' details found. Returning users to the UserController via List"); 220 | 221 | return returnValue; 222 | } 223 | 224 | } 225 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/shared/Utils.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.shared; 2 | 3 | import java.security.SecureRandom; 4 | import java.util.Random; 5 | 6 | import org.springframework.stereotype.Component; 7 | 8 | @Component 9 | public class Utils { 10 | 11 | private final Random RANDOM = new SecureRandom(); 12 | private final String ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 13 | 14 | public String generateUserId(int length) { 15 | return generateRandomString(length); 16 | } 17 | 18 | public String generateFoodId(int length) { 19 | return generateRandomString(length); 20 | } 21 | 22 | public String generateOrderId(int length) { 23 | return generateRandomString(length); 24 | } 25 | 26 | private String generateRandomString(int length) { 27 | StringBuilder returnValue = new StringBuilder(length); 28 | 29 | for (int i = 0; i < length; i++) { 30 | returnValue.append(ALPHABET.charAt(RANDOM.nextInt(ALPHABET.length()))); 31 | } 32 | 33 | return new String(returnValue); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/shared/dto/FoodDto.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.shared.dto; 2 | 3 | import java.io.Serializable; 4 | 5 | public class FoodDto implements Serializable { 6 | 7 | private static final long serialVersionUID = 5323277388000239262L; 8 | private long id; 9 | private String foodId; 10 | private String foodName; 11 | private String foodCategory; 12 | private float foodPrice; 13 | 14 | public long getId() { 15 | return id; 16 | } 17 | 18 | public void setId(long id) { 19 | this.id = id; 20 | } 21 | 22 | public String getFoodId() { 23 | return foodId; 24 | } 25 | 26 | public void setFoodId(String foodId) { 27 | this.foodId = foodId; 28 | } 29 | 30 | public String getFoodName() { 31 | return foodName; 32 | } 33 | 34 | public void setFoodName(String foodName) { 35 | this.foodName = foodName; 36 | } 37 | 38 | public String getFoodCategory() { 39 | return foodCategory; 40 | } 41 | 42 | public void setFoodCategory(String foodCategory) { 43 | this.foodCategory = foodCategory; 44 | } 45 | 46 | public float getFoodPrice() { 47 | return foodPrice; 48 | } 49 | 50 | public void setFoodPrice(float foodPrice) { 51 | this.foodPrice = foodPrice; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/shared/dto/OrderDto.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.shared.dto; 2 | 3 | import java.io.Serializable; 4 | 5 | public class OrderDto implements Serializable { 6 | 7 | private static final long serialVersionUID = 2500955288592764755L; 8 | private long id; 9 | private String orderId; 10 | private float cost; 11 | private String[] items; 12 | private String userId; 13 | private boolean status; 14 | 15 | public long getId() { 16 | return id; 17 | } 18 | 19 | public void setId(long id) { 20 | this.id = id; 21 | } 22 | 23 | public String getOrderId() { 24 | return orderId; 25 | } 26 | 27 | public void setOrderId(String orderId) { 28 | this.orderId = orderId; 29 | } 30 | 31 | public float getCost() { 32 | return cost; 33 | } 34 | 35 | public void setCost(float cost) { 36 | this.cost = cost; 37 | } 38 | 39 | public String [] getItems() { 40 | return items; 41 | } 42 | 43 | public void setItems(String [] items) { 44 | this.items = items; 45 | } 46 | 47 | public String getUserId() { 48 | return userId; 49 | } 50 | 51 | public void setUserId(String userId) { 52 | this.userId = userId; 53 | } 54 | 55 | public boolean isStatus() { 56 | return status; 57 | } 58 | 59 | public void setStatus(boolean status) { 60 | this.status = status; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/shared/dto/UserDto.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.shared.dto; 2 | 3 | import java.io.Serializable; 4 | 5 | public class UserDto implements Serializable { 6 | 7 | private static final long serialVersionUID = -5382713250745188694L; 8 | 9 | private long id; 10 | private String userId; 11 | private String firstName; 12 | private String lastName; 13 | private String email; 14 | private String password; 15 | private String encryptedPassword; 16 | private String userType; 17 | 18 | public long getId() { 19 | return id; 20 | } 21 | 22 | public void setId(long id) { 23 | this.id = id; 24 | } 25 | 26 | public String getUserId() { 27 | return userId; 28 | } 29 | 30 | public void setUserId(String userId) { 31 | this.userId = userId; 32 | } 33 | 34 | public String getFirstName() { 35 | return firstName; 36 | } 37 | 38 | public void setFirstName(String firstName) { 39 | this.firstName = firstName; 40 | } 41 | 42 | public String getLastName() { 43 | return lastName; 44 | } 45 | 46 | public void setLastName(String lastName) { 47 | this.lastName = lastName; 48 | } 49 | 50 | public String getEmail() { 51 | return email; 52 | } 53 | 54 | public void setEmail(String email) { 55 | this.email = email; 56 | } 57 | 58 | public String getPassword() { 59 | return password; 60 | } 61 | 62 | public void setPassword(String password) { 63 | this.password = password; 64 | } 65 | 66 | public String getEncryptedPassword() { 67 | return encryptedPassword; 68 | } 69 | 70 | public void setEncryptedPassword(String encryptedPassword) { 71 | this.encryptedPassword = encryptedPassword; 72 | } 73 | 74 | public String getUserType() { 75 | return userType; 76 | } 77 | 78 | public void setUserType(String userType) { 79 | this.userType = userType; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/ui/controller/AuthenticationController.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.ui.controller; 2 | 3 | import org.slf4j.LoggerFactory; 4 | import org.springframework.beans.BeanUtils; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RequestMethod; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import com.food.delivery.app.ws.model.request.LoginRequest; 14 | import com.food.delivery.app.ws.model.response.UserRest; 15 | import com.food.delivery.app.ws.service.UserService; 16 | import com.food.delivery.app.ws.shared.dto.UserDto; 17 | 18 | import io.swagger.annotations.ApiOperation; 19 | import io.swagger.annotations.ApiResponse; 20 | import io.swagger.annotations.ApiResponses; 21 | import io.swagger.annotations.ResponseHeader; 22 | 23 | @RestController 24 | public class AuthenticationController { 25 | 26 | org.slf4j.Logger logger = LoggerFactory.getLogger(UserController.class); 27 | 28 | @Autowired 29 | UserService userService; 30 | 31 | @ApiOperation("User login") 32 | @ApiResponses(value = { @ApiResponse(code = 200, message = "Response Headera", responseHeaders = { 33 | @ResponseHeader(name = "authorization", description = "Bearer ", response = String.class), 34 | @ResponseHeader(name = "userId", description = "", response = String.class) 35 | }) 36 | }) 37 | 38 | @PostMapping("/users/login") 39 | public void fakeLogin(@RequestBody LoginRequest login) { 40 | throw new IllegalStateException("You can't access this method using api documentation!"); 41 | } 42 | 43 | @RequestMapping(value = "/users/{email}", method = RequestMethod.GET) 44 | public UserRest getUserByEmail(@PathVariable String email) { 45 | 46 | UserRest returnValue = new UserRest(); 47 | 48 | UserDto user = userService.getUser(email); 49 | BeanUtils.copyProperties(user, returnValue); 50 | 51 | return returnValue; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/ui/controller/FoodController.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.ui.controller; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.modelmapper.ModelMapper; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.BeanUtils; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.http.MediaType; 11 | import org.springframework.web.bind.annotation.CrossOrigin; 12 | import org.springframework.web.bind.annotation.DeleteMapping; 13 | import org.springframework.web.bind.annotation.GetMapping; 14 | import org.springframework.web.bind.annotation.PathVariable; 15 | import org.springframework.web.bind.annotation.PostMapping; 16 | import org.springframework.web.bind.annotation.PutMapping; 17 | import org.springframework.web.bind.annotation.RequestBody; 18 | import org.springframework.web.bind.annotation.RequestMapping; 19 | import org.springframework.web.bind.annotation.RestController; 20 | 21 | import com.food.delivery.app.ws.model.request.FoodDetailsRequestModel; 22 | import com.food.delivery.app.ws.model.response.FoodDetailsResponse; 23 | import com.food.delivery.app.ws.model.response.OperationStatusModel; 24 | import com.food.delivery.app.ws.model.response.RequestOperationName; 25 | import com.food.delivery.app.ws.model.response.RequestOperationStatus; 26 | import com.food.delivery.app.ws.service.FoodService; 27 | import com.food.delivery.app.ws.shared.dto.FoodDto; 28 | 29 | import io.swagger.annotations.ApiImplicitParam; 30 | import io.swagger.annotations.ApiImplicitParams; 31 | import io.swagger.annotations.ApiOperation; 32 | 33 | @RestController 34 | @RequestMapping("/foods") 35 | public class FoodController { 36 | 37 | @Autowired 38 | FoodService foodService; 39 | 40 | /** 41 | * Initialize Logger object 42 | */ 43 | org.slf4j.Logger logger = LoggerFactory.getLogger(UserController.class); 44 | 45 | @CrossOrigin 46 | @ApiOperation(value = "The Get Food Details Web Service Endpoint", notes = "This web service endpoint returns the Food detials with json format or xml format") 47 | @ApiImplicitParams({ @ApiImplicitParam(name = "authorization", value = "Bearer JWT Token", paramType = "header")}) 48 | @GetMapping(path="/{id}", 49 | produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }) 50 | public FoodDetailsResponse getFood(@PathVariable String id) { 51 | 52 | logger.info("FoodController -> getFood(id) method has been called"); 53 | FoodDetailsResponse returnValue = new FoodDetailsResponse(); 54 | ModelMapper modelMapper = new ModelMapper(); 55 | 56 | FoodDto foodDto = foodService.getFoodById(id); 57 | returnValue = modelMapper.map(foodDto, FoodDetailsResponse.class); 58 | 59 | logger.info("Return the food to the requester"); 60 | return returnValue; 61 | } 62 | 63 | @CrossOrigin 64 | @ApiOperation(value = "The Create Food Web Service Endpoint", notes = "This web service endpoint returns the Food detials with json format or xml format when the food is created") 65 | @ApiImplicitParams({ @ApiImplicitParam(name = "authorization", value = "Bearer JWT Token", paramType = "header")}) 66 | @PostMapping( 67 | consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }, 68 | produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }) 69 | public FoodDetailsResponse createFood(@RequestBody FoodDetailsRequestModel foodDetails) { 70 | 71 | logger.info("FoodController -> createFood(foodDetails) method has been called"); 72 | FoodDetailsResponse returnValue = new FoodDetailsResponse(); 73 | ModelMapper modelMapper = new ModelMapper(); 74 | 75 | FoodDto foodDto = modelMapper.map(foodDetails, FoodDto.class); 76 | FoodDto createFood = foodService.createFood(foodDto); 77 | 78 | returnValue = modelMapper.map(createFood, FoodDetailsResponse.class); 79 | 80 | logger.info("Return the food to the requester"); 81 | return returnValue; 82 | } 83 | 84 | @CrossOrigin 85 | @ApiOperation(value = "The Food Details Update Web Service Endpoint", notes = "This web service endpoint returns the Food detials or success message with json format or xml format when the food is updated") 86 | @ApiImplicitParams({ @ApiImplicitParam(name = "authorization", value = "Bearer JWT Token", paramType = "header")}) 87 | @PutMapping(path="/{id}", 88 | consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }, 89 | produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }) 90 | public FoodDetailsResponse updateFood(@PathVariable String id, @RequestBody FoodDetailsRequestModel foodDetails) { 91 | 92 | logger.info("FoodController -> updateFood(id, foodDetails) method has been called"); 93 | FoodDetailsResponse returnValue = new FoodDetailsResponse(); 94 | ModelMapper modelMapper = new ModelMapper(); 95 | 96 | FoodDto foodDto = new FoodDto(); 97 | foodDto = modelMapper.map(foodDetails, FoodDto.class); 98 | 99 | FoodDto updatedUser = foodService.updateFoodDetails(id, foodDto); 100 | returnValue = modelMapper.map(updatedUser, FoodDetailsResponse.class); 101 | 102 | logger.info("Return the food to the requester"); 103 | return returnValue; 104 | } 105 | 106 | @CrossOrigin 107 | @ApiOperation(value = "The Food Deletion Web Service Endpoint", notes = "This web service endpoint returns success token with json format or xml format when the food is deleted") 108 | @ApiImplicitParams({ @ApiImplicitParam(name = "authorization", value = "Bearer JWT Token", paramType = "header")}) 109 | @DeleteMapping(path = "/{id}", 110 | produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }) 111 | public OperationStatusModel deleteFood(@PathVariable String id) { 112 | 113 | logger.info("FoodController -> deleteFood(id) method has been called"); 114 | OperationStatusModel returnValue = new OperationStatusModel(); 115 | returnValue.setOperationName(RequestOperationName.DELETE.name()); 116 | 117 | foodService.deleteFoodItem(id); 118 | 119 | returnValue.setOperationResult(RequestOperationStatus.SUCCESS.name()); 120 | 121 | logger.info("Return the message to the requester"); 122 | return returnValue; 123 | } 124 | 125 | @CrossOrigin 126 | @ApiOperation(value = "The Get Foods Web Service Endpoint", notes = "This web service endpoint returns List of Foods detials with json format or xml format") 127 | @ApiImplicitParams({ @ApiImplicitParam(name = "authorization", value = "Bearer JWT Token", paramType = "header")}) 128 | @GetMapping( 129 | produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }) 130 | public List getFoods() { 131 | 132 | logger.info("FoodController -> getFoods() method has been called"); 133 | List returnValue = new ArrayList<>(); 134 | 135 | List foods = foodService.getFoods(); 136 | 137 | for(FoodDto foodDto: foods) { 138 | FoodDetailsResponse response = new FoodDetailsResponse(); 139 | BeanUtils.copyProperties(foodDto, response); 140 | returnValue.add(response); 141 | } 142 | 143 | logger.info("Return the foods' list to the requester"); 144 | return returnValue; 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/ui/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.ui.controller; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.modelmapper.ModelMapper; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.BeanUtils; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.http.MediaType; 11 | import org.springframework.web.bind.annotation.CrossOrigin; 12 | import org.springframework.web.bind.annotation.DeleteMapping; 13 | import org.springframework.web.bind.annotation.GetMapping; 14 | import org.springframework.web.bind.annotation.PathVariable; 15 | import org.springframework.web.bind.annotation.PostMapping; 16 | import org.springframework.web.bind.annotation.PutMapping; 17 | import org.springframework.web.bind.annotation.RequestBody; 18 | import org.springframework.web.bind.annotation.RequestMapping; 19 | import org.springframework.web.bind.annotation.RestController; 20 | 21 | import com.food.delivery.app.ws.model.request.OrderDetailsRequestModel; 22 | import com.food.delivery.app.ws.model.response.OperationStatusModel; 23 | import com.food.delivery.app.ws.model.response.OrderDetailsResponse; 24 | import com.food.delivery.app.ws.model.response.RequestOperationName; 25 | import com.food.delivery.app.ws.model.response.RequestOperationStatus; 26 | import com.food.delivery.app.ws.service.OrderService; 27 | import com.food.delivery.app.ws.shared.dto.OrderDto; 28 | 29 | import io.swagger.annotations.ApiImplicitParam; 30 | import io.swagger.annotations.ApiImplicitParams; 31 | import io.swagger.annotations.ApiOperation; 32 | 33 | @RestController 34 | @RequestMapping("/orders") 35 | public class OrderController { 36 | 37 | @Autowired 38 | OrderService orderService; 39 | 40 | /** 41 | * Initialize Logger object 42 | */ 43 | org.slf4j.Logger logger = LoggerFactory.getLogger(UserController.class); 44 | 45 | @CrossOrigin 46 | @ApiOperation(value = "The Get Order Details Web Service Endpoint", notes = "This web service endpoint returns the Order detials with json format or xml format") 47 | @ApiImplicitParams({ @ApiImplicitParam(name = "authorization", value = "Bearer JWT Token", paramType = "header")}) 48 | @GetMapping(path="/{id}", 49 | produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }) 50 | public OrderDetailsResponse getOrder(@PathVariable String id) { 51 | 52 | logger.info("OrderController -> getOrder(id) method has been called"); 53 | OrderDetailsResponse returnValue = new OrderDetailsResponse(); 54 | ModelMapper modelMapper = new ModelMapper(); 55 | 56 | OrderDto orderDto = orderService.getOrderById(id); 57 | returnValue = modelMapper.map(orderDto, OrderDetailsResponse.class); 58 | 59 | logger.info("Return the order to the requester"); 60 | return returnValue; 61 | } 62 | 63 | @CrossOrigin 64 | @ApiOperation(value = "The Create Order Web Service Endpoint", notes = "This web service endpoint returns the Order detials with json format or xml format when the order is created") 65 | @ApiImplicitParams({ @ApiImplicitParam(name = "authorization", value = "Bearer JWT Token", paramType = "header")}) 66 | @PostMapping( 67 | consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }, 68 | produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }) 69 | public OrderDetailsResponse createOrder(@RequestBody OrderDetailsRequestModel order) { 70 | 71 | logger.info("OrderController -> createOrder(order) method has been called"); 72 | OrderDetailsResponse returnValue = new OrderDetailsResponse(); 73 | ModelMapper modelMapper = new ModelMapper(); 74 | 75 | OrderDto orderDto = new OrderDto(); 76 | BeanUtils.copyProperties(order, orderDto); 77 | 78 | OrderDto createdOrder = orderService.createOrder(orderDto); 79 | returnValue = modelMapper.map(createdOrder, OrderDetailsResponse.class); 80 | 81 | logger.info("Return the order to the requester"); 82 | return returnValue; 83 | } 84 | 85 | @CrossOrigin 86 | @ApiOperation(value = "The Order Details Update Web Service Endpoint", notes = "This web service endpoint returns the Order detials or success message with json format or xml format when the order is updated") 87 | @ApiImplicitParams({ @ApiImplicitParam(name = "authorization", value = "Bearer JWT Token", paramType = "header")}) 88 | @PutMapping(path="/{id}", 89 | consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }, 90 | produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }) 91 | public OrderDetailsResponse updateOrder(@PathVariable String id, @RequestBody OrderDetailsRequestModel order) { 92 | 93 | logger.info("OrderController -> updateOrder(id, order) method has been called"); 94 | OrderDetailsResponse returnValue = new OrderDetailsResponse(); 95 | ModelMapper modelMapper = new ModelMapper(); 96 | 97 | OrderDto orderDto = new OrderDto(); 98 | orderDto = modelMapper.map(order, OrderDto.class); 99 | 100 | OrderDto updatedOrder = orderService.updateOrderDetails(id, orderDto); 101 | returnValue = modelMapper.map(updatedOrder, OrderDetailsResponse.class); 102 | 103 | logger.info("Return the order to the requester"); 104 | return returnValue; 105 | } 106 | 107 | @CrossOrigin 108 | @ApiOperation(value = "The Order Deletion Web Service Endpoint", notes = "This web service endpoint returns success token with json format or xml format when the order is deleted") 109 | @ApiImplicitParams({ @ApiImplicitParam(name = "authorization", value = "Bearer JWT Token", paramType = "header")}) 110 | @DeleteMapping(path = "/{id}", 111 | produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }) 112 | public OperationStatusModel deleteOrder(@PathVariable String id) { 113 | 114 | logger.info("OrderController -> deleteOrder(id) method has been called"); 115 | OperationStatusModel returnValue = new OperationStatusModel(); 116 | returnValue.setOperationName(RequestOperationName.DELETE.name()); 117 | 118 | orderService.deleteOrder(id); 119 | 120 | returnValue.setOperationResult(RequestOperationStatus.SUCCESS.name()); 121 | 122 | logger.info("Return the message to the requester"); 123 | return returnValue; 124 | } 125 | 126 | @CrossOrigin 127 | @ApiOperation(value = "The Get Orders Web Service Endpoint", notes = "This web service endpoint returns List of Orders detials with json format or xml format") 128 | @ApiImplicitParams({ @ApiImplicitParam(name = "authorization", value = "Bearer JWT Token", paramType = "header")}) 129 | @GetMapping( 130 | produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }) 131 | public List getOrders() { 132 | 133 | logger.info("OrderController -> getOrders() method has been called"); 134 | List returnValue = new ArrayList<>(); 135 | 136 | List orders = orderService.getOrders(); 137 | 138 | for(OrderDto orderDto : orders) { 139 | OrderDetailsResponse response = new OrderDetailsResponse(); 140 | BeanUtils.copyProperties(orderDto, response); 141 | returnValue.add(response); 142 | } 143 | 144 | logger.info("Return the orders' list to the requester"); 145 | return returnValue; 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /src/main/java/com/food/delivery/app/ws/ui/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws.ui.controller; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.beans.BeanUtils; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.http.MediaType; 10 | import org.springframework.web.bind.annotation.CrossOrigin; 11 | import org.springframework.web.bind.annotation.DeleteMapping; 12 | import org.springframework.web.bind.annotation.GetMapping; 13 | import org.springframework.web.bind.annotation.PathVariable; 14 | import org.springframework.web.bind.annotation.PostMapping; 15 | import org.springframework.web.bind.annotation.PutMapping; 16 | import org.springframework.web.bind.annotation.RequestBody; 17 | import org.springframework.web.bind.annotation.RequestMapping; 18 | import org.springframework.web.bind.annotation.RestController; 19 | 20 | import com.food.delivery.app.ws.model.request.UserDetailsRequestModel; 21 | import com.food.delivery.app.ws.model.response.OperationStatusModel; 22 | import com.food.delivery.app.ws.model.response.RequestOperationName; 23 | import com.food.delivery.app.ws.model.response.RequestOperationStatus; 24 | import com.food.delivery.app.ws.model.response.UserRest; 25 | import com.food.delivery.app.ws.service.UserService; 26 | import com.food.delivery.app.ws.shared.dto.UserDto; 27 | 28 | import io.swagger.annotations.ApiImplicitParam; 29 | import io.swagger.annotations.ApiImplicitParams; 30 | import io.swagger.annotations.ApiOperation; 31 | 32 | @RestController 33 | @RequestMapping("/users") 34 | public class UserController { 35 | 36 | @Autowired 37 | UserService userService; 38 | 39 | /** 40 | * Initialize Logger object 41 | */ 42 | org.slf4j.Logger logger = LoggerFactory.getLogger(UserController.class); 43 | 44 | @CrossOrigin 45 | @ApiOperation(value = "The Get User Details Web Service Endpoint", notes = "This web service endpoint returns the User detials with json format or xml format") 46 | @ApiImplicitParams({ @ApiImplicitParam(name = "authorization", value = "Bearer JWT Token", paramType = "header")}) 47 | @GetMapping(path = "/{id}", 48 | produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }) 49 | public UserRest getUser(@PathVariable String id) { 50 | 51 | logger.info("UserController -> getUser(id) method has been called"); 52 | UserRest returnValue = new UserRest(); 53 | 54 | UserDto userDto = userService.getUserByUserId(id); 55 | BeanUtils.copyProperties(userDto, returnValue); 56 | 57 | logger.info("Return the user to the requester"); 58 | return returnValue; 59 | } 60 | 61 | @CrossOrigin 62 | @ApiOperation(value = "The User Registration Web Service Endpoint", notes = "This web service endpoint returns the User detials with json format or xml format when the user is created") 63 | @PostMapping( 64 | consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }, 65 | produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }) 66 | public UserRest createUser(@RequestBody UserDetailsRequestModel userDetails) { 67 | 68 | logger.info("UserController -> createUser(userDetails) method has been called"); 69 | UserRest returnValue = new UserRest(); 70 | 71 | UserDto userDto = new UserDto(); 72 | BeanUtils.copyProperties(userDetails, userDto); 73 | 74 | UserDto createUser = userService.createUser(userDto); 75 | BeanUtils.copyProperties(createUser, returnValue); 76 | 77 | logger.info("Return the user to the requester"); 78 | return returnValue; 79 | } 80 | 81 | @CrossOrigin 82 | @ApiOperation(value = "The User Details Update Web Service Endpoint", notes = "This web service endpoint returns the User detials or success message with json format or xml format when the user is updated") 83 | @ApiImplicitParams({ @ApiImplicitParam(name = "authorization", value = "Bearer JWT Token", paramType = "header")}) 84 | @PutMapping(path = "/{id}", 85 | consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }, 86 | produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }) 87 | public UserRest updateUser(@PathVariable String id, @RequestBody UserDetailsRequestModel userDetails) { 88 | 89 | logger.info("UserController -> updateUser(id, userDetails) method has been called"); 90 | UserRest returnValue = new UserRest(); 91 | 92 | UserDto userDto = new UserDto(); 93 | BeanUtils.copyProperties(userDetails, userDto); 94 | 95 | UserDto updateUser = userService.updateUser(id, userDto); 96 | BeanUtils.copyProperties(updateUser, returnValue); 97 | 98 | logger.info("Return the user to the requester"); 99 | return returnValue; 100 | } 101 | 102 | @CrossOrigin 103 | @ApiOperation(value = "The User Deletion Web Service Endpoint", notes = "This web service endpoint returns success token with json format or xml format when the user is deleted") 104 | @ApiImplicitParams({ @ApiImplicitParam(name = "authorization", value = "Bearer JWT Token", paramType = "header")}) 105 | @DeleteMapping(path = "/{id}", 106 | produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }) 107 | public OperationStatusModel deleteUser(@PathVariable String id) { 108 | 109 | logger.info("UserController -> deleteUser(id) method has been called"); 110 | OperationStatusModel returnValue = new OperationStatusModel(); 111 | returnValue.setOperationName(RequestOperationName.DELETE.name()); 112 | 113 | userService.deleteUser(id); 114 | 115 | returnValue.setOperationResult(RequestOperationStatus.SUCCESS.name()); 116 | 117 | logger.info("Return the message to the requester"); 118 | return returnValue; 119 | } 120 | 121 | @CrossOrigin 122 | @ApiOperation(value = "The Get Users Web Service Endpoint", notes = "This web service endpoint returns List of User detials with json format or xml format") 123 | @ApiImplicitParams({ @ApiImplicitParam(name = "authorization", value = "Bearer JWT Token", paramType = "header")}) 124 | @GetMapping(produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE }) 125 | public List getUsers(){ 126 | 127 | logger.info("UserController -> getUsers() method has been called"); 128 | List returnValue = new ArrayList<>(); 129 | 130 | List users = userService.getUsers(); 131 | 132 | for(UserDto userDto : users) { 133 | UserRest userModel = new UserRest(); 134 | BeanUtils.copyProperties(userDto, userModel); 135 | returnValue.add(userModel); 136 | } 137 | 138 | logger.info("Return the users' list to the requester"); 139 | return returnValue; 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.username=root 2 | spring.datasource.password= 3 | spring.datasource.url=jdbc:mysql://localhost:3306/delivery_app?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC 4 | spring.jpa.hibernate.ddl-auto=update 5 | server.servlet.context-path=/food-boot -------------------------------------------------------------------------------- /src/test/java/com/food/delivery/app/ws/FoodDeliveryWebAppApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.food.delivery.app.ws; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class FoodDeliveryWebAppApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | --------------------------------------------------------------------------------