├── .gitattributes ├── .gitignore ├── .mvn └── wrapper │ └── maven-wrapper.properties ├── CODE_OF_CONDUCT.md ├── Dockerfile ├── LICENSE ├── README.md ├── SECURITY.md ├── mvnw ├── mvnw.cmd ├── pom.xml ├── project.log ├── project.log.2025-05-31.0.gz └── src ├── main ├── java │ └── com │ │ └── starter │ │ └── backend │ │ ├── BackendApplication.java │ │ ├── aspects │ │ └── LoggingAspect.java │ │ ├── audits │ │ ├── InitiatorAudit.java │ │ └── TimeStampAudit.java │ │ ├── config │ │ ├── JacksonConfig.java │ │ ├── SwaggerApiDoc.java │ │ ├── WebSecurityConfig.java │ │ └── WebSocketConfig.java │ │ ├── controllers │ │ ├── AuthController.java │ │ ├── ChatController.java │ │ ├── EmailController.java │ │ ├── FileController.java │ │ ├── InventoryController.java │ │ ├── ProductController.java │ │ ├── TaskController.java │ │ └── UserController.java │ │ ├── dtos │ │ ├── ProductDto.java │ │ ├── SIgninDto.java │ │ ├── SignupDto.java │ │ ├── TaskDto.java │ │ ├── UpdateInventoryDto.java │ │ └── UserUpdateDto.java │ │ ├── enums │ │ ├── EGender.java │ │ ├── ERoleType.java │ │ ├── EStatus.java │ │ └── ETaskStatus.java │ │ ├── exceptions │ │ ├── ApiRequestException.java │ │ ├── AppException.java │ │ ├── BadRequestException.java │ │ └── ResourceNotFoundException.java │ │ ├── models │ │ ├── File.java │ │ ├── Inventory.java │ │ ├── Message.java │ │ ├── Product.java │ │ ├── Role.java │ │ ├── Task.java │ │ └── User.java │ │ ├── payload │ │ ├── ApiResponse.java │ │ └── JwtAuthResponse.java │ │ ├── repository │ │ ├── FileRepository.java │ │ ├── InventoryRepository.java │ │ ├── ProductRepository.java │ │ ├── RoleRepository.java │ │ ├── TaskRepository.java │ │ └── UserRepository.java │ │ ├── schedules │ │ └── LogCleanupTask.java │ │ ├── security │ │ ├── CustomUserDetailsService.java │ │ ├── JwtAuthEntryPoint.java │ │ ├── JwtAuthFilter.java │ │ ├── JwtTokenProvider.java │ │ ├── PasswordConstraintValidator.java │ │ ├── UserPrincipal.java │ │ ├── ValidPassword.java │ │ └── WebSocketSecurityConfig.java │ │ ├── services │ │ ├── EmailService.java │ │ ├── FIleService.java │ │ ├── InventoryService.java │ │ ├── ProductService.java │ │ ├── QueryResolver.java │ │ ├── TaskService.java │ │ └── UserService.java │ │ └── util │ │ ├── Constants.java │ │ └── Response.java └── resources │ ├── application.properties │ └── graphql │ └── task.graphqls └── test └── java └── com └── starter └── backend └── BackendApplicationTests.java /.gitattributes: -------------------------------------------------------------------------------- 1 | /mvnw text eol=lf 2 | *.cmd text eol=crlf 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | wrapperVersion=3.3.2 18 | distributionType=only-script 19 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip 20 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | ## Our Pledge 4 | We as members, contributors, and leaders pledge to make participation in our project and community a harassment-free experience for everyone, regardless of: 5 | - age, body size, visible or invisible disability, ethnicity, 6 | - sex characteristics, gender identity and expression, 7 | - level of experience, education, socio-economic status, nationality, 8 | - personal appearance, race, religion, or sexual identity and orientation. 9 | 10 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. 11 | 12 | ## Our Standards 13 | Examples of behavior that contributes to a positive environment include: 14 | - Showing empathy and kindness to others 15 | - Being respectful of differing opinions and experiences 16 | - Giving and gracefully accepting constructive feedback 17 | - Accepting responsibility and apologizing to those affected by mistakes 18 | 19 | Examples of unacceptable behavior include: 20 | - Harassment, discrimination, or derogatory comments 21 | - Personal attacks or insulting remarks 22 | - Publishing others’ private information without consent 23 | - Sustained disruption of discussions or communications 24 | 25 | ## Enforcement Responsibilities 26 | Community leaders are responsible for clarifying and enforcing the Code of Conduct. They will take appropriate action in response to any behavior they deem inappropriate, threatening, offensive, or harmful. 27 | 28 | ## Scope 29 | This Code of Conduct applies to: 30 | - All project spaces (GitHub issues, pull requests, discussions, etc.) 31 | - Public spaces when an individual is representing the project or community 32 | 33 | ## Enforcement 34 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the project team at **mugishapascal2008@gmail.com**. All reports will be reviewed and investigated. 35 | 36 | ## Attribution 37 | This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 2.1. -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM maven:3.9.9-eclipse-temurin-21 2 | 3 | EXPOSE 8081 4 | WORKDIR /app 5 | COPY . . 6 | RUN mvn clean install 7 | ENTRYPOINT ["java", "-jar", "target/backend-0.0.1-SNAPSHOT.jar"] 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 MUGISHA Pascal 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SpringBoot Advanced Starter 2 | 3 | ## Description 4 | 5 | SpringBoot Advanced Starter is an open-source Spring Boot starter project designed to help you jump-start your own applications with ease. It provides a foundational setup with essential configurations for building scalable and maintainable Spring Boot applications. This starter template is perfect for both small and large projects and helps streamline the development process. 6 | 7 | --- 8 | 9 | ## How to Contribute 10 | 11 | Thank you for your interest in contributing! We welcome contributions from everyone. Whether you're fixing bugs, adding new features, or improving documentation, your contributions are highly appreciated. 12 | 13 | ### How to Contribute 14 | 15 | 1. **Fork the Repository** 16 | Click the "Fork" button on the repository page to create a personal copy of the repository. 17 | 18 | 2. **Clone Your Fork** 19 | Clone your forked repository to your local machine using the following command: 20 | ```bash 21 | git clone git@github.com:MUGISHA-Pascal/SpringBoot-Advanced-Starter.git 22 | 23 | 3. **Create a New Branch** 24 | Create a new branch for your feature or bugfix: 25 | 26 | ```bash 27 | git checkout -b feature/your-feature-name 28 | 4. **Make Your Changes** 29 | Write clear, concise, and well-tested code. Ensure your changes are aligned with the existing project structure and conventions. 30 | 31 | 5. **Commit Your Changes** 32 | Commit your changes with a descriptive message: 33 | ```bash 34 | git commit -m "Add: Description of the changes you made" 35 | 6. **Push to Your Fork** 36 | Push your changes to your fork: 37 | ```bash 38 | git push origin feature/your-feature-name 39 | 7. **Create a Pull Request** 40 | Open a Pull Request from your fork to the main repository, describing your changes and their purpose. 41 | 42 | --- 43 | 44 | # Guidelines 45 | 46 | To ensure consistency and maintain quality across the project, please adhere to the following guidelines: 47 | 48 | - Follow the existing code style and structure. 49 | - Write clear and meaningful commit messages. 50 | - Include tests for new features or bug fixes where applicable. 51 | - Update documentation, such as the `README.md`, to reflect your changes. 52 | 53 | --- 54 | 55 | ## Code of Conduct 56 | 57 | This project adheres to a Code of Conduct. By participating, you agree to abide by its terms. We are committed to creating a welcoming and respectful environment for all contributors. 58 | 59 | --- 60 | 61 | ## Support 62 | 63 | We are here to assist you! If you encounter issues or need help, here's how you can get support: 64 | 65 | ## Where to Get Help 66 | 67 | - **Documentation**: Please refer to the `README.md` for setup and usage instructions. 68 | - **Issues**: If you discover a bug or face an issue, please open a new issue in the GitHub Issues tab. 69 | - **Feature Requests**: If you'd like to request a new feature, feel free to submit a feature request via GitHub issues. 70 | - **Discussions**: For general questions or community-driven support, visit our Discussions (if enabled). 71 | 72 | --- 73 | 74 | ## Contact 75 | 76 | For direct communication with the maintainers or if you have a private concern, you can email us at: 77 | 78 | **mugishapascal2008@gmail.com** 79 | 80 | We will respond within 48 hours. 81 | 82 | --- 83 | 84 | ## Contributing 85 | 86 | We are excited about your interest in contributing to this project! Please review our [`CONTRIBUTING.md`](CONTRIBUTING.md) for more detailed guidelines on how to contribute. 87 | 88 | --- 89 | 90 | ## Acknowledgments 91 | 92 | Thank you for your time and effort in making this project better. Your contributions help the community thrive and make this project a useful resource for others. 93 | 94 | --- 95 | 96 | ## License 97 | 98 | This project is licensed under the **MIT License** - see the [`LICENSE`](LICENSE) file for details. 99 | 100 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Reporting a Vulnerability 4 | 5 | If you discover a security vulnerability, please **do not** create a public GitHub issue. 6 | 7 | Instead, email us at **mugishapascal2008@gmail.com** with details. 8 | 9 | We will respond within **3 business days** and take necessary action as soon as possible. 10 | 11 | Please include: 12 | - A description of the issue 13 | - Steps to reproduce it (if applicable) 14 | - Any relevant logs or screenshots 15 | 16 | Thanks for helping keep our project secure! 17 | -------------------------------------------------------------------------------- /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 | # http://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 | # Apache Maven Wrapper startup batch script, version 3.3.2 23 | # 24 | # Optional ENV vars 25 | # ----------------- 26 | # JAVA_HOME - location of a JDK home dir, required when download maven via java source 27 | # MVNW_REPOURL - repo url base for downloading maven distribution 28 | # MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven 29 | # MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output 30 | # ---------------------------------------------------------------------------- 31 | 32 | set -euf 33 | [ "${MVNW_VERBOSE-}" != debug ] || set -x 34 | 35 | # OS specific support. 36 | native_path() { printf %s\\n "$1"; } 37 | case "$(uname)" in 38 | CYGWIN* | MINGW*) 39 | [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" 40 | native_path() { cygpath --path --windows "$1"; } 41 | ;; 42 | esac 43 | 44 | # set JAVACMD and JAVACCMD 45 | set_java_home() { 46 | # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched 47 | if [ -n "${JAVA_HOME-}" ]; then 48 | if [ -x "$JAVA_HOME/jre/sh/java" ]; then 49 | # IBM's JDK on AIX uses strange locations for the executables 50 | JAVACMD="$JAVA_HOME/jre/sh/java" 51 | JAVACCMD="$JAVA_HOME/jre/sh/javac" 52 | else 53 | JAVACMD="$JAVA_HOME/bin/java" 54 | JAVACCMD="$JAVA_HOME/bin/javac" 55 | 56 | if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then 57 | echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 58 | echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 59 | return 1 60 | fi 61 | fi 62 | else 63 | JAVACMD="$( 64 | 'set' +e 65 | 'unset' -f command 2>/dev/null 66 | 'command' -v java 67 | )" || : 68 | JAVACCMD="$( 69 | 'set' +e 70 | 'unset' -f command 2>/dev/null 71 | 'command' -v javac 72 | )" || : 73 | 74 | if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then 75 | echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 76 | return 1 77 | fi 78 | fi 79 | } 80 | 81 | # hash string like Java String::hashCode 82 | hash_string() { 83 | str="${1:-}" h=0 84 | while [ -n "$str" ]; do 85 | char="${str%"${str#?}"}" 86 | h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) 87 | str="${str#?}" 88 | done 89 | printf %x\\n $h 90 | } 91 | 92 | verbose() { :; } 93 | [ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } 94 | 95 | die() { 96 | printf %s\\n "$1" >&2 97 | exit 1 98 | } 99 | 100 | trim() { 101 | # MWRAPPER-139: 102 | # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. 103 | # Needed for removing poorly interpreted newline sequences when running in more 104 | # exotic environments such as mingw bash on Windows. 105 | printf "%s" "${1}" | tr -d '[:space:]' 106 | } 107 | 108 | # parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties 109 | while IFS="=" read -r key value; do 110 | case "${key-}" in 111 | distributionUrl) distributionUrl=$(trim "${value-}") ;; 112 | distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; 113 | esac 114 | done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" 115 | [ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" 116 | 117 | case "${distributionUrl##*/}" in 118 | maven-mvnd-*bin.*) 119 | MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ 120 | case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in 121 | *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; 122 | :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; 123 | :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; 124 | :Linux*x86_64*) distributionPlatform=linux-amd64 ;; 125 | *) 126 | echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 127 | distributionPlatform=linux-amd64 128 | ;; 129 | esac 130 | distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" 131 | ;; 132 | maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; 133 | *) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; 134 | esac 135 | 136 | # apply MVNW_REPOURL and calculate MAVEN_HOME 137 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ 138 | [ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" 139 | distributionUrlName="${distributionUrl##*/}" 140 | distributionUrlNameMain="${distributionUrlName%.*}" 141 | distributionUrlNameMain="${distributionUrlNameMain%-bin}" 142 | MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" 143 | MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" 144 | 145 | exec_maven() { 146 | unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : 147 | exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" 148 | } 149 | 150 | if [ -d "$MAVEN_HOME" ]; then 151 | verbose "found existing MAVEN_HOME at $MAVEN_HOME" 152 | exec_maven "$@" 153 | fi 154 | 155 | case "${distributionUrl-}" in 156 | *?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; 157 | *) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; 158 | esac 159 | 160 | # prepare tmp dir 161 | if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then 162 | clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } 163 | trap clean HUP INT TERM EXIT 164 | else 165 | die "cannot create temp dir" 166 | fi 167 | 168 | mkdir -p -- "${MAVEN_HOME%/*}" 169 | 170 | # Download and Install Apache Maven 171 | verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." 172 | verbose "Downloading from: $distributionUrl" 173 | verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" 174 | 175 | # select .zip or .tar.gz 176 | if ! command -v unzip >/dev/null; then 177 | distributionUrl="${distributionUrl%.zip}.tar.gz" 178 | distributionUrlName="${distributionUrl##*/}" 179 | fi 180 | 181 | # verbose opt 182 | __MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' 183 | [ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v 184 | 185 | # normalize http auth 186 | case "${MVNW_PASSWORD:+has-password}" in 187 | '') MVNW_USERNAME='' MVNW_PASSWORD='' ;; 188 | has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; 189 | esac 190 | 191 | if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then 192 | verbose "Found wget ... using wget" 193 | wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" 194 | elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then 195 | verbose "Found curl ... using curl" 196 | curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" 197 | elif set_java_home; then 198 | verbose "Falling back to use Java to download" 199 | javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" 200 | targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" 201 | cat >"$javaSource" <<-END 202 | public class Downloader extends java.net.Authenticator 203 | { 204 | protected java.net.PasswordAuthentication getPasswordAuthentication() 205 | { 206 | return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); 207 | } 208 | public static void main( String[] args ) throws Exception 209 | { 210 | setDefault( new Downloader() ); 211 | java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); 212 | } 213 | } 214 | END 215 | # For Cygwin/MinGW, switch paths to Windows format before running javac and java 216 | verbose " - Compiling Downloader.java ..." 217 | "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" 218 | verbose " - Running Downloader.java ..." 219 | "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" 220 | fi 221 | 222 | # If specified, validate the SHA-256 sum of the Maven distribution zip file 223 | if [ -n "${distributionSha256Sum-}" ]; then 224 | distributionSha256Result=false 225 | if [ "$MVN_CMD" = mvnd.sh ]; then 226 | echo "Checksum validation is not supported for maven-mvnd." >&2 227 | echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 228 | exit 1 229 | elif command -v sha256sum >/dev/null; then 230 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then 231 | distributionSha256Result=true 232 | fi 233 | elif command -v shasum >/dev/null; then 234 | if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then 235 | distributionSha256Result=true 236 | fi 237 | else 238 | echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 239 | echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 240 | exit 1 241 | fi 242 | if [ $distributionSha256Result = false ]; then 243 | echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 244 | echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 245 | exit 1 246 | fi 247 | fi 248 | 249 | # unzip and move 250 | if command -v unzip >/dev/null; then 251 | unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" 252 | else 253 | tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" 254 | fi 255 | printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" 256 | mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" 257 | 258 | clean || : 259 | exec_maven "$@" 260 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | <# : batch portion 2 | @REM ---------------------------------------------------------------------------- 3 | @REM Licensed to the Apache Software Foundation (ASF) under one 4 | @REM or more contributor license agreements. See the NOTICE file 5 | @REM distributed with this work for additional information 6 | @REM regarding copyright ownership. The ASF licenses this file 7 | @REM to you under the Apache License, Version 2.0 (the 8 | @REM "License"); you may not use this file except in compliance 9 | @REM with the License. You may obtain a copy of the License at 10 | @REM 11 | @REM http://www.apache.org/licenses/LICENSE-2.0 12 | @REM 13 | @REM Unless required by applicable law or agreed to in writing, 14 | @REM software distributed under the License is distributed on an 15 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | @REM KIND, either express or implied. See the License for the 17 | @REM specific language governing permissions and limitations 18 | @REM under the License. 19 | @REM ---------------------------------------------------------------------------- 20 | 21 | @REM ---------------------------------------------------------------------------- 22 | @REM Apache Maven Wrapper startup batch script, version 3.3.2 23 | @REM 24 | @REM Optional ENV vars 25 | @REM MVNW_REPOURL - repo url base for downloading maven distribution 26 | @REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven 27 | @REM MVNW_VERBOSE - true: enable verbose log; others: silence the output 28 | @REM ---------------------------------------------------------------------------- 29 | 30 | @IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) 31 | @SET __MVNW_CMD__= 32 | @SET __MVNW_ERROR__= 33 | @SET __MVNW_PSMODULEP_SAVE=%PSModulePath% 34 | @SET PSModulePath= 35 | @FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( 36 | IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) 37 | ) 38 | @SET PSModulePath=%__MVNW_PSMODULEP_SAVE% 39 | @SET __MVNW_PSMODULEP_SAVE= 40 | @SET __MVNW_ARG0_NAME__= 41 | @SET MVNW_USERNAME= 42 | @SET MVNW_PASSWORD= 43 | @IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) 44 | @echo Cannot start maven from wrapper >&2 && exit /b 1 45 | @GOTO :EOF 46 | : end batch / begin powershell #> 47 | 48 | $ErrorActionPreference = "Stop" 49 | if ($env:MVNW_VERBOSE -eq "true") { 50 | $VerbosePreference = "Continue" 51 | } 52 | 53 | # calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties 54 | $distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl 55 | if (!$distributionUrl) { 56 | Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" 57 | } 58 | 59 | switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { 60 | "maven-mvnd-*" { 61 | $USE_MVND = $true 62 | $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" 63 | $MVN_CMD = "mvnd.cmd" 64 | break 65 | } 66 | default { 67 | $USE_MVND = $false 68 | $MVN_CMD = $script -replace '^mvnw','mvn' 69 | break 70 | } 71 | } 72 | 73 | # apply MVNW_REPOURL and calculate MAVEN_HOME 74 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ 75 | if ($env:MVNW_REPOURL) { 76 | $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } 77 | $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" 78 | } 79 | $distributionUrlName = $distributionUrl -replace '^.*/','' 80 | $distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' 81 | $MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" 82 | if ($env:MAVEN_USER_HOME) { 83 | $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" 84 | } 85 | $MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' 86 | $MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" 87 | 88 | if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { 89 | Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" 90 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" 91 | exit $? 92 | } 93 | 94 | if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { 95 | Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" 96 | } 97 | 98 | # prepare tmp dir 99 | $TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile 100 | $TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" 101 | $TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null 102 | trap { 103 | if ($TMP_DOWNLOAD_DIR.Exists) { 104 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } 105 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } 106 | } 107 | } 108 | 109 | New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null 110 | 111 | # Download and Install Apache Maven 112 | Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." 113 | Write-Verbose "Downloading from: $distributionUrl" 114 | Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" 115 | 116 | $webclient = New-Object System.Net.WebClient 117 | if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { 118 | $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) 119 | } 120 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 121 | $webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null 122 | 123 | # If specified, validate the SHA-256 sum of the Maven distribution zip file 124 | $distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum 125 | if ($distributionSha256Sum) { 126 | if ($USE_MVND) { 127 | Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." 128 | } 129 | Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash 130 | if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { 131 | Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." 132 | } 133 | } 134 | 135 | # unzip and move 136 | Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null 137 | Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null 138 | try { 139 | Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null 140 | } catch { 141 | if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { 142 | Write-Error "fail to move MAVEN_HOME" 143 | } 144 | } finally { 145 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } 146 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } 147 | } 148 | 149 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" 150 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | 7 | org.springframework.boot 8 | spring-boot-starter-parent 9 | 3.4.3 10 | 11 | 12 | 13 | com.starter 14 | backend 15 | 0.0.1-SNAPSHOT 16 | backend 17 | Demo project for Spring Boot 18 | 19 | 20 | 21 21 | 21 22 | 21 23 | 24 | 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-data-jpa 30 | 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-security 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-actuator 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-devtools 44 | true 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-starter-web 50 | 51 | 52 | 53 | 54 | 55 | org.springframework.boot 56 | spring-boot-starter-validation 57 | 58 | 59 | 60 | 61 | org.postgresql 62 | postgresql 63 | [42.7.5,) 64 | 65 | 66 | 67 | 68 | org.projectlombok 69 | lombok 70 | true 71 | 72 | 73 | 74 | 75 | org.springframework.boot 76 | spring-boot-starter-test 77 | test 78 | 79 | 80 | 81 | 82 | 83 | org.springdoc 84 | springdoc-openapi-starter-webmvc-ui 85 | [2.3.0,) 86 | 87 | 88 | 89 | com.fasterxml.jackson 90 | jackson-bom 91 | 2.13.5 92 | pom 93 | import 94 | 95 | 96 | com.fasterxml.jackson.datatype 97 | jackson-datatype-hibernate5 98 | 2.15.2 99 | 100 | 101 | com.graphql-java 102 | java-dataloader 103 | 5.0.0 104 | 105 | 106 | org.springframework.boot 107 | spring-boot-starter-mail 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | org.springframework.boot 131 | spring-boot-starter-graphql 132 | 133 | 134 | org.springframework.boot 135 | spring-boot-starter-websocket 136 | 137 | 138 | org.springframework 139 | spring-messaging 140 | 141 | 142 | org.springframework.boot 143 | spring-boot-starter-oauth2-client 144 | 145 | 146 | org.springframework.graphql 147 | spring-graphql 148 | [1.0.0,) 149 | 150 | 151 | org.springframework.boot 152 | spring-boot-starter-websocket 153 | 154 | 155 | com.graphql-java 156 | graphql-java-extended-scalars 157 | 21.0 158 | 159 | 160 | com.graphql-java-kickstart 161 | graphql-spring-boot-starter 162 | 11.1.0 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | org.passay 182 | passay 183 | [1.6.0,) 184 | 185 | 186 | 187 | 188 | com.google.guava 189 | guava 190 | [31.1-jre,) 191 | 192 | 193 | 194 | io.jsonwebtoken 195 | jjwt-api 196 | [0.12.6,) 197 | 198 | 199 | io.jsonwebtoken 200 | jjwt-impl 201 | [0.12.6,) 202 | runtime 203 | 204 | 205 | 206 | 207 | io.jsonwebtoken 208 | jjwt-jackson 209 | [0.12.6,) 210 | runtime 211 | 212 | 213 | 214 | 215 | jakarta.xml.bind 216 | jakarta.xml.bind-api 217 | [3.0.0,) 218 | 219 | 220 | jakarta.servlet 221 | jakarta.servlet-api 222 | [6.0.0,) 223 | provided 224 | 225 | 226 | 227 | org.springframework.boot 228 | spring-boot-starter-logging 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | org.springframework.boot 285 | spring-boot-dependencies 286 | 3.4.4 287 | import 288 | pom 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | central 297 | Maven Central Repository 298 | https://repo.maven.apache.org/maven2 299 | 300 | true 301 | 302 | 303 | false 304 | 305 | 306 | 307 | 308 | 309 | 310 | org.springframework.boot 311 | spring-boot-maven-plugin 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | org.apache.maven.plugins 325 | maven-javadoc-plugin 326 | 3.5.0 327 | 328 | 329 | 330 | javadoc 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | -------------------------------------------------------------------------------- /project.log.2025-05-31.0.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MUGISHA-Pascal/SpringBoot-Advanced-Starter/427ed0377121b10118087bcadd120c68d3b29972/project.log.2025-05-31.0.gz -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/BackendApplication.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.data.jpa.repository.config.EnableJpaAuditing; 6 | import org.springframework.scheduling.annotation.EnableScheduling; 7 | 8 | @SpringBootApplication 9 | @EnableJpaAuditing 10 | @EnableScheduling 11 | public class BackendApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(BackendApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/aspects/LoggingAspect.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.aspects; 2 | 3 | import org.aspectj.lang.JoinPoint; 4 | import org.aspectj.lang.annotation.*; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.stereotype.Component; 8 | 9 | @Aspect 10 | @Component 11 | public class LoggingAspect { 12 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 13 | @Pointcut("execution(* com.starter.backend.controllers..*(..)) || execution( * com.starter.backend.services..*(..))") 14 | public void LoggingPointcut(){} 15 | 16 | @Before("LoggingPointcut()") 17 | public void logBefore(JoinPoint joinPoint){ 18 | logger.info("Entering method: {} with arguements : {}",joinPoint.getSignature(),joinPoint.getArgs()); 19 | } 20 | @AfterReturning(pointcut ="LoggingPointcut()",returning = "result") 21 | public void logAfterReturning(JoinPoint joinPoint,Object result){ 22 | logger.info("Exiting method: {} with result : {}",joinPoint.getSignature(),result); 23 | } 24 | @AfterThrowing(pointcut = "LoggingPointcut()" , throwing = "error") 25 | public void logAfterThrowing(JoinPoint joinPoint,Throwable error){ 26 | logger.info("Exiting method: {} with error : {}",joinPoint.getSignature(),error.getMessage()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/audits/InitiatorAudit.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.audits; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import jakarta.persistence.Column; 5 | import jakarta.persistence.MappedSuperclass; 6 | import lombok.Getter; 7 | import lombok.Setter; 8 | import org.springframework.data.annotation.CreatedBy; 9 | import org.springframework.data.annotation.LastModifiedBy; 10 | 11 | import java.util.UUID; 12 | 13 | @MappedSuperclass 14 | @JsonIgnoreProperties(value = {"createdBy","updatedBy"},allowGetters = true) 15 | @Getter 16 | @Setter 17 | public class InitiatorAudit extends TimeStampAudit{ 18 | private static final long serialVersionUID =1l; 19 | @CreatedBy 20 | @Column(name = "created_by") 21 | private UUID createdBy; 22 | @LastModifiedBy 23 | @Column(name = "updated_by") 24 | private UUID updatedBy; 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/audits/TimeStampAudit.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.audits; 2 | 3 | import com.fasterxml.jackson.annotation.JsonFormat; 4 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 5 | import jakarta.persistence.Column; 6 | import jakarta.persistence.EntityListeners; 7 | import jakarta.persistence.MappedSuperclass; 8 | import lombok.Getter; 9 | import lombok.Setter; 10 | import org.hibernate.annotations.CreationTimestamp; 11 | import org.hibernate.annotations.UpdateTimestamp; 12 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; 13 | 14 | import java.io.Serializable; 15 | import java.time.LocalDateTime; 16 | 17 | @Getter 18 | @Setter 19 | @MappedSuperclass 20 | @EntityListeners(AuditingEntityListener.class) 21 | @JsonIgnoreProperties(value = {"createdAt","updatedAt"},allowGetters = true) 22 | public class TimeStampAudit implements Serializable { 23 | private static final long serialVersionUID=1l; 24 | @CreationTimestamp 25 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 26 | @Column(name = "created_at") 27 | private LocalDateTime createdAt; 28 | @UpdateTimestamp 29 | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") 30 | private LocalDateTime updatedAt; 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/config/JacksonConfig.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.config; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | @Configuration 9 | public class JacksonConfig { 10 | 11 | @Bean 12 | public Hibernate5Module datatypeHibernateModule() { 13 | Hibernate5Module module = new Hibernate5Module(); 14 | module.disable(Hibernate5Module.Feature.USE_TRANSIENT_ANNOTATION); 15 | return module; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/config/SwaggerApiDoc.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.config; 2 | 3 | import io.swagger.v3.oas.models.OpenAPI; 4 | import io.swagger.v3.oas.models.info.Info; 5 | import io.swagger.v3.oas.models.info.Contact; 6 | import io.swagger.v3.oas.models.security.SecurityRequirement; 7 | import io.swagger.v3.oas.models.security.SecurityScheme; 8 | import io.swagger.v3.oas.models.Components; 9 | import org.springdoc.webmvc.ui.SwaggerConfig; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | 13 | @Configuration 14 | public class SwaggerApiDoc { 15 | 16 | @Bean 17 | public OpenAPI customOpenAPI() { 18 | final String securitySchemeName = "bearerAuth"; 19 | 20 | return new OpenAPI() 21 | .info(new Info() 22 | .title("Spring Boot Advanced Starter") 23 | .version("1.0.0") 24 | .description("A spring boot starter kit for your project") 25 | .termsOfService("https://github.com/MUGISHA-Pascal/SpringBoot-Advanced-Starter") 26 | .contact(new Contact() 27 | .name("MUGISHA Pascal") 28 | .url("https://mugisha-pascal.vercel.app/") 29 | .email("mugishapascal2008@gmail.com")) 30 | .license(new io.swagger.v3.oas.models.info.License() 31 | .name("MIT") 32 | .url("https://github.com/MUGISHA-Pascal/SpringBoot-Advanced-Starter/blob/main/LICENSE"))) 33 | .addSecurityItem(new SecurityRequirement().addList(securitySchemeName)) 34 | .components(new Components() 35 | .addSecuritySchemes(securitySchemeName, 36 | new SecurityScheme() 37 | .name(securitySchemeName) 38 | .type(SecurityScheme.Type.HTTP) 39 | .scheme("bearer") 40 | .bearerFormat("JWT"))); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/config/WebSecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.config; 2 | import com.starter.backend.security.CustomUserDetailsService; 3 | import com.starter.backend.security.JwtAuthEntryPoint; 4 | import com.starter.backend.security.JwtAuthFilter; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.security.authentication.AuthenticationManager; 9 | import org.springframework.security.authentication.AuthenticationManagerResolver; 10 | import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; 11 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 12 | import org.springframework.security.config.http.SessionCreationPolicy; 13 | import org.springframework.security.core.userdetails.UserDetailsService; 14 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 15 | import org.springframework.security.web.SecurityFilterChain; 16 | import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; 17 | import org.springframework.security.authentication.AuthenticationProvider; 18 | import org.springframework.security.authentication.dao.DaoAuthenticationProvider; 19 | import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration; 20 | import org.springframework.security.web.util.matcher.AntPathRequestMatcher; 21 | 22 | import org.springframework.security.config.Customizer; 23 | import org.springframework.security.web.authentication.Http403ForbiddenEntryPoint; 24 | import org.springframework.security.web.AuthenticationEntryPoint; 25 | import org.springframework.security.config.annotation.web.builders.HttpSecurity; 26 | 27 | @Configuration 28 | @EnableWebSecurity 29 | @EnableMethodSecurity(securedEnabled = true, jsr250Enabled = true, prePostEnabled = true) 30 | public class WebSecurityConfig { 31 | 32 | @Autowired 33 | private CustomUserDetailsService userService; 34 | 35 | @Autowired 36 | private JwtAuthEntryPoint unauthorizedHandler; 37 | 38 | @Bean 39 | public JwtAuthFilter jwtAuthenticationFilter() { 40 | return new JwtAuthFilter(); 41 | } 42 | 43 | @Bean 44 | public BCryptPasswordEncoder passwordEncoder() { 45 | return new BCryptPasswordEncoder(); 46 | } 47 | 48 | @Bean 49 | public AuthenticationProvider authenticationProvider() { 50 | DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider(); 51 | authProvider.setUserDetailsService(userService); 52 | authProvider.setPasswordEncoder(passwordEncoder()); 53 | return authProvider; 54 | } 55 | 56 | @Bean 57 | public AuthenticationManager authenticationManager(AuthenticationConfiguration authConfig) throws Exception { 58 | return authConfig.getAuthenticationManager(); 59 | } 60 | 61 | @Bean 62 | public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { 63 | http 64 | .csrf(csrf -> csrf.disable()) 65 | .cors(Customizer.withDefaults()) 66 | .exceptionHandling(ex -> ex.authenticationEntryPoint(unauthorizedHandler)) 67 | .sessionManagement(sess -> sess.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) 68 | .authorizeHttpRequests(auth -> auth 69 | .requestMatchers( 70 | new AntPathRequestMatcher("/"), 71 | new AntPathRequestMatcher("/favicon.ico"), 72 | new AntPathRequestMatcher("/**/*.png"), 73 | new AntPathRequestMatcher("/**/*.gif"), 74 | new AntPathRequestMatcher("/**/*.svg"), 75 | new AntPathRequestMatcher("/**/*.jpg"), 76 | new AntPathRequestMatcher("/**/*.html"), 77 | new AntPathRequestMatcher("/**/*.css"), 78 | new AntPathRequestMatcher("/**/*.js"), 79 | new AntPathRequestMatcher("/v2/api-docs"), 80 | new AntPathRequestMatcher("/graphql"), 81 | new AntPathRequestMatcher("/graphiql"), 82 | new AntPathRequestMatcher("/v3/api-docs/**"), 83 | new AntPathRequestMatcher("/configuration/ui"), 84 | new AntPathRequestMatcher("/swagger-resources/**"), 85 | new AntPathRequestMatcher("/configuration/security"), 86 | new AntPathRequestMatcher("/swagger-ui.html"), 87 | new AntPathRequestMatcher("/swagger-ui/index.html"), 88 | new AntPathRequestMatcher("/webjars/**"), 89 | new AntPathRequestMatcher("/api/v1/auth/**"), 90 | new AntPathRequestMatcher("/api/v1/email/**"), 91 | new AntPathRequestMatcher("/api/v1/products/**"), 92 | new AntPathRequestMatcher("/api/v1/files/**"), 93 | new AntPathRequestMatcher("/api/v1/users/**") 94 | ).permitAll() 95 | .anyRequest().authenticated() 96 | ); 97 | 98 | http.addFilterBefore(jwtAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class); 99 | 100 | return http.build(); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/config/WebSocketConfig.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.messaging.simp.config.MessageBrokerRegistry; 5 | import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; 6 | import org.springframework.web.socket.config.annotation.StompEndpointRegistry; 7 | import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; 8 | 9 | @Configuration 10 | @EnableWebSocketMessageBroker 11 | public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { 12 | @Override 13 | public void configureMessageBroker(MessageBrokerRegistry config) { 14 | config.enableSimpleBroker("/topic"); 15 | config.setApplicationDestinationPrefixes("/app"); 16 | } 17 | 18 | @Override 19 | public void registerStompEndpoints(StompEndpointRegistry registry) { 20 | registry.addEndpoint("/chat").withSockJS(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/controllers/AuthController.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.controllers; 2 | 3 | import com.starter.backend.dtos.SIgninDto; 4 | import com.starter.backend.dtos.SignupDto; 5 | import com.starter.backend.exceptions.ApiRequestException; 6 | import com.starter.backend.models.Role; 7 | import com.starter.backend.models.User; 8 | import com.starter.backend.payload.JwtAuthResponse; 9 | import com.starter.backend.repository.RoleRepository; 10 | import com.starter.backend.repository.UserRepository; 11 | import com.starter.backend.security.JwtTokenProvider; 12 | import com.starter.backend.services.UserService; 13 | import com.starter.backend.util.Response; 14 | 15 | import io.swagger.v3.oas.annotations.Operation; 16 | import jakarta.validation.Valid; 17 | import org.springframework.beans.factory.annotation.Autowired; 18 | import org.springframework.http.HttpStatus; 19 | import org.springframework.http.ResponseEntity; 20 | import org.springframework.security.authentication.AuthenticationManager; 21 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 22 | import org.springframework.security.core.Authentication; 23 | import org.springframework.security.core.context.SecurityContextHolder; 24 | import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 25 | import org.springframework.web.bind.annotation.*; 26 | 27 | import java.time.ZonedDateTime; 28 | import java.util.Collections; 29 | 30 | @RestController 31 | @RequestMapping("/api/v1/auth") 32 | public class AuthController { 33 | @Autowired 34 | private UserService userService; 35 | @Autowired 36 | private AuthenticationManager authenticationManager; 37 | @Autowired 38 | private JwtTokenProvider jwtTokenProvider; 39 | @Autowired 40 | private RoleRepository roleRepository; 41 | @Autowired 42 | private BCryptPasswordEncoder bCryptPasswordEncoder; 43 | @Autowired 44 | private UserRepository userRepository; 45 | @PostMapping(path = "/signin") 46 | @Operation(summary = "signin into your account") 47 | public ResponseEntity signin(@Valid @RequestBody SIgninDto signInRequest){ 48 | Authentication authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(signInRequest.getEmail(),signInRequest.getPassword())); 49 | SecurityContextHolder.getContext().setAuthentication(authentication); 50 | String jwt=null; 51 | try{ 52 | jwt=jwtTokenProvider.generateToken(authentication); 53 | }catch(Exception e){ 54 | System.out.println("error generating jwt"); 55 | e.printStackTrace(); 56 | } 57 | return ResponseEntity.ok(new JwtAuthResponse(jwt)); 58 | } 59 | @PostMapping(path = "/signup") 60 | @Operation(summary="create new user") 61 | public ResponseEntity signup(@RequestBody @Valid SignupDto signupRequest){ 62 | User user = new User(signupRequest.getEmail(),signupRequest.getFirstName(),signupRequest.getLastName(),signupRequest.getMobile(),signupRequest.getGender(),signupRequest.getPassword()); 63 | boolean userExists = userRepository.findByEmail(user.getEmail()).isPresent(); 64 | if(userRepository.existsByMobile(user.getMobile())){ 65 | throw new ApiRequestException("phone number already in use"); 66 | } 67 | if(user.getEmail() != null && userExists){ 68 | throw new ApiRequestException("Email already in use"); 69 | } 70 | String encodedPassword = bCryptPasswordEncoder.encode(user.getPassword()); 71 | user.setPassword(encodedPassword); 72 | Role userRole = roleRepository.findByName(signupRequest.getRole()).orElseThrow(()-> new ApiRequestException("User Role not set")); 73 | user.setRoles(Collections.singleton(userRole)); 74 | userRepository.save(user); 75 | return new ResponseEntity<>(new Response("Registered Successfully", ZonedDateTime.now(),true), HttpStatus.CREATED); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/controllers/ChatController.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.controllers; 2 | 3 | import com.starter.backend.models.Message; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.messaging.handler.annotation.MessageMapping; 6 | import org.springframework.messaging.handler.annotation.Payload; 7 | import org.springframework.messaging.handler.annotation.SendTo; 8 | import org.springframework.messaging.simp.SimpMessageHeaderAccessor; 9 | import org.springframework.messaging.simp.SimpMessagingTemplate; 10 | import org.springframework.stereotype.Controller; 11 | 12 | @Controller 13 | public class ChatController { 14 | 15 | private final SimpMessagingTemplate template; 16 | public ChatController(SimpMessagingTemplate template) { 17 | this.template = template; 18 | } 19 | @MessageMapping("/send") 20 | @SendTo("/topic/messages") 21 | public Message sendMessage(Message message){ 22 | return message; 23 | } 24 | @MessageMapping("/private-message") 25 | public void sendPrivateMessage(@Payload Message message, SimpMessageHeaderAccessor headerAccessor) { 26 | // Access the current user's identity (username) 27 | String sender = (String) headerAccessor.getSessionAttributes().get("username"); 28 | message.setSender(sender); // Set the sender to the current authenticated user 29 | 30 | // Send the private message to the recipient 31 | // template.convertAndSendToUser( 32 | // message.getRecipient(), // recipient username 33 | // "/queue/messages", // destination queue 34 | // message // message payload 35 | // ); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/controllers/EmailController.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.controllers; 2 | 3 | import com.starter.backend.services.EmailService; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.PostMapping; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestParam; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | @RestController 11 | @RequestMapping("/api/v1/email") 12 | public class EmailController { 13 | @Autowired 14 | private EmailService emailService; 15 | @PostMapping("/send") 16 | public String sendEmail(@RequestParam String to, @RequestParam String subject, @RequestParam String text){ 17 | emailService.sendSimpleMessage(to, subject, text); 18 | return "Email sent successfully"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/controllers/FileController.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.controllers; 2 | 3 | import com.starter.backend.models.File; 4 | import com.starter.backend.services.FIleService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.http.MediaType; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.*; 9 | import org.springframework.web.multipart.MultipartFile; 10 | 11 | import java.io.IOException; 12 | import java.util.UUID; 13 | 14 | @RestController 15 | @RequestMapping("/api/v1/files") 16 | public class FileController { 17 | @Autowired 18 | private FIleService fIleService; 19 | @PostMapping("/upload") 20 | public ResponseEntity uploadFile(@RequestParam("file")MultipartFile file){ 21 | try{ 22 | fIleService.storeFile(file); 23 | return ResponseEntity.ok("File uploaded"); 24 | }catch(IOException e){ 25 | return ResponseEntity.status(500).body("error uploading file"); 26 | } 27 | } 28 | @GetMapping("/download/{id}") 29 | public ResponseEntity getFile(@PathVariable UUID id){ 30 | File file = fIleService.getFile(id); 31 | if(file != null){ 32 | return ResponseEntity.ok() 33 | .header("Content-Disposition", "attachment; filename=\"" + file.getFilename() + "\"") 34 | .body(file.getFile()); 35 | }else{ 36 | return ResponseEntity.status(404).body(null); 37 | } 38 | } 39 | @GetMapping("/preview/{id}") 40 | public ResponseEntity previewFile(@PathVariable UUID id) { 41 | File fileEntity = fIleService.getFile(id); 42 | 43 | if (fileEntity == null) { 44 | return ResponseEntity.notFound().build(); 45 | } 46 | 47 | String filename = fileEntity.getFilename().toLowerCase(); 48 | String contentType = "application/octet-stream"; 49 | 50 | if (filename.endsWith(".png")) { 51 | contentType = MediaType.IMAGE_PNG_VALUE; 52 | } else if (filename.endsWith(".jpg") || filename.endsWith(".jpeg")) { 53 | contentType = MediaType.IMAGE_JPEG_VALUE; 54 | } else if (filename.endsWith(".pdf")) { 55 | contentType = "application/pdf"; 56 | } else if (filename.endsWith(".txt")) { 57 | contentType = MediaType.TEXT_PLAIN_VALUE; 58 | } 59 | 60 | return ResponseEntity.ok() 61 | .contentType(MediaType.parseMediaType(contentType)) 62 | .body(fileEntity.getFile()); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/controllers/InventoryController.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.controllers; 2 | 3 | import com.starter.backend.dtos.UpdateInventoryDto; 4 | import com.starter.backend.models.Product; 5 | import com.starter.backend.services.InventoryService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.*; 9 | 10 | import java.util.UUID; 11 | 12 | @RestController 13 | @RequestMapping("api/v1/inventory") 14 | public class InventoryController { 15 | @Autowired 16 | InventoryService inventoryService; 17 | @PutMapping("/update/{id}") 18 | public ResponseEntity updateInventory(@PathVariable("id") UUID id, @RequestBody UpdateInventoryDto updateInventoryDto) { 19 | return inventoryService.updateInventory(id,updateInventoryDto); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/controllers/ProductController.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.controllers; 2 | 3 | import com.starter.backend.dtos.ProductDto; 4 | import com.starter.backend.models.Product; 5 | import com.starter.backend.services.ProductService; 6 | import com.starter.backend.util.Constants; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.data.domain.Page; 9 | import org.springframework.web.bind.annotation.*; 10 | 11 | import java.util.List; 12 | import java.util.UUID; 13 | 14 | @RestController 15 | @RequestMapping("/api/v1/products") 16 | public class ProductController { 17 | 18 | private final ProductService productService; 19 | 20 | @Autowired 21 | public ProductController(ProductService productService){ 22 | this.productService = productService; 23 | } 24 | 25 | @GetMapping("/order") 26 | public Page getPaginatedAndSortedProducts(@RequestParam(value = "page" ,defaultValue = Constants.DEFAULT_PAGE_NUMBER) int page, @RequestParam(value = "size",defaultValue = Constants.DEFAULT_PAGE_SIZE) int size, @RequestParam(value = "column") String column){ 27 | return productService.productsPagination(page,size,column); 28 | } 29 | @GetMapping 30 | public List getAllProducts(){ 31 | return productService.getAllProducts(); 32 | } 33 | @GetMapping("/category/{category}") 34 | public List getAllProductsByCategory(@PathVariable String category){ 35 | return this.productService.findProductsByCategory(category); 36 | } 37 | 38 | @GetMapping("/{id}") 39 | public Product getProduct(@PathVariable UUID id){ 40 | return productService.getProduct(id); 41 | } 42 | 43 | @PostMapping 44 | public Product addProduct(@RequestBody ProductDto productDto){ 45 | System.out.println("product log in controller"+productDto.getInventory().getLocation()); 46 | return productService.addProduct(productDto); 47 | } 48 | 49 | @PutMapping("/{id}") 50 | public Product updateProduct(@PathVariable UUID id, @RequestBody ProductDto productDto){ 51 | return productService.updateProduct(id, productDto); 52 | } 53 | 54 | @DeleteMapping("/{id}") 55 | public String deleteProduct(@PathVariable UUID id){ 56 | productService.deleteProduct(id); 57 | return "Product with id " + id + " has been deleted successfully."; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/controllers/TaskController.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.controllers; 2 | 3 | import com.starter.backend.dtos.TaskDto; 4 | import com.starter.backend.models.Task; 5 | import com.starter.backend.services.TaskService; 6 | import graphql.GraphQLContext; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.graphql.data.method.annotation.Argument; 9 | import org.springframework.graphql.data.method.annotation.MutationMapping; 10 | import org.springframework.graphql.data.method.annotation.QueryMapping; 11 | import org.springframework.stereotype.Controller; 12 | 13 | import java.util.List; 14 | import java.util.UUID; 15 | 16 | @Controller 17 | public class TaskController { 18 | @Autowired 19 | private TaskService taskService; 20 | @QueryMapping 21 | public List getAllTasks(GraphQLContext context){ 22 | String authorization = context.get("Authorization"); 23 | System.out.println("token "+authorization); 24 | return taskService.getAllTasks(); 25 | } 26 | @MutationMapping 27 | public Task addTask(@Argument("input") TaskDto task){ 28 | try{ 29 | return taskService.addTask(task);}catch (Exception e){ 30 | System.out.println("-----"+e.getMessage()+"-----"); 31 | } 32 | return null; 33 | } 34 | @MutationMapping 35 | public Task updateTask(@Argument("input") TaskDto task, @Argument("id")UUID id){ 36 | return taskService.updateTask(task,id); 37 | } 38 | @MutationMapping 39 | public String deleteTask(@Argument("id") UUID id){ 40 | return taskService.deleteTask(id); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/controllers/UserController.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.controllers; 2 | 3 | import com.starter.backend.dtos.UserUpdateDto; 4 | import com.starter.backend.models.User; 5 | import com.starter.backend.payload.ApiResponse; 6 | import com.starter.backend.services.UserService; 7 | import com.starter.backend.util.Constants; 8 | import io.swagger.v3.oas.annotations.Parameter; 9 | import jakarta.validation.Valid; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.data.domain.Page; 12 | import org.springframework.http.ResponseEntity; 13 | import org.springframework.web.bind.annotation.*; 14 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder; 15 | 16 | import java.net.URI; 17 | import java.util.UUID; 18 | 19 | @RestController 20 | @RequestMapping("/api/v1/users") 21 | public class UserController { 22 | @Autowired 23 | private UserService userService; 24 | @GetMapping 25 | public Page getUsers(@RequestParam(value = "page" ,defaultValue = Constants.DEFAULT_PAGE_NUMBER) int page,@RequestParam(value = "size",defaultValue = Constants.DEFAULT_PAGE_SIZE) int size,@RequestParam(value = "column") String column){ 26 | return userService.getAllUsers(page,size,column); 27 | } 28 | @DeleteMapping(path = "/{userId}") 29 | public ResponseEntity deleteUser(@Parameter(description = "userId",required = true) @PathVariable("userId") UUID userId){ 30 | return ResponseEntity.ok(new ApiResponse(true,"user removed successfully",userService.deleteUser(userId))); 31 | } 32 | @PutMapping(path = "/{userId}") 33 | public ResponseEntity updateUser(@PathVariable("userId") UUID userId, @Valid @RequestBody UserUpdateDto userdataRequest){ 34 | userService.updateUser(userId,userdataRequest); 35 | User user = userService.getUser(userId); 36 | URI location = ServletUriComponentsBuilder.fromCurrentContextPath().path("/users/{email}").buildAndExpand(user.getEmail()).toUri(); 37 | return ResponseEntity.created(location).body(new ApiResponse(true,"user updated successfully",user)); 38 | } 39 | @GetMapping(path = "/{userId}") 40 | public ResponseEntity getUser(@Parameter(description="Get user by id",required = true) @PathVariable("userId") UUID userId ){ 41 | return ResponseEntity.ok(new ApiResponse(true,"user found",this.userService.getUser(userId))); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/dtos/ProductDto.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.dtos; 2 | 3 | import com.starter.backend.models.Inventory; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Getter; 6 | import lombok.Setter; 7 | import lombok.ToString; 8 | 9 | @Getter 10 | @Setter 11 | @AllArgsConstructor 12 | @ToString 13 | public class ProductDto { 14 | private String name; 15 | private String description; 16 | private int price; 17 | private int quantity; 18 | private String category; 19 | private UpdateInventoryDto inventory; 20 | // private String image_url; 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/dtos/SIgninDto.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.dtos; 2 | 3 | import jakarta.validation.constraints.Email; 4 | import jakarta.validation.constraints.NotBlank; 5 | import lombok.Getter; 6 | import lombok.Setter; 7 | 8 | @Setter 9 | @Getter 10 | public class SIgninDto { 11 | @NotBlank 12 | @Email 13 | private String email; 14 | @NotBlank 15 | private String password; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/dtos/SignupDto.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.dtos; 2 | 3 | import com.starter.backend.enums.EGender; 4 | import com.starter.backend.enums.ERoleType; 5 | import com.starter.backend.security.ValidPassword; 6 | import jakarta.validation.constraints.Email; 7 | import jakarta.validation.constraints.NotBlank; 8 | import jakarta.validation.constraints.Size; 9 | import lombok.Getter; 10 | import lombok.Setter; 11 | 12 | @Getter 13 | @Setter 14 | public class SignupDto { 15 | @Size(max=100) 16 | @Email 17 | private String email; 18 | @NotBlank 19 | @Size(min=4,max = 40) 20 | private String firstName; 21 | @NotBlank 22 | @Size(min=4,max=40) 23 | private String lastName; 24 | @NotBlank 25 | private String mobile; 26 | private EGender gender; 27 | private ERoleType role; 28 | @ValidPassword 29 | private String password; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/dtos/TaskDto.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.dtos; 2 | 3 | import com.starter.backend.enums.ETaskStatus; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | 9 | import java.util.UUID; 10 | @Getter 11 | @Setter 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | public class TaskDto { 15 | private String title; 16 | private String description; 17 | private ETaskStatus status; 18 | private String assignedTo; 19 | public TaskDto(String title, String description, ETaskStatus status){ 20 | this.title = title; 21 | this.description = description; 22 | this.status = status; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/dtos/UpdateInventoryDto.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.dtos; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.NoArgsConstructor; 6 | import lombok.Setter; 7 | 8 | import java.util.UUID; 9 | @Getter 10 | @Setter 11 | @AllArgsConstructor 12 | @NoArgsConstructor 13 | public class UpdateInventoryDto { 14 | private int quantity; 15 | private String location; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/dtos/UserUpdateDto.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.dtos; 2 | 3 | import com.starter.backend.enums.EGender; 4 | import jakarta.validation.constraints.Email; 5 | import jakarta.validation.constraints.NotBlank; 6 | import jakarta.validation.constraints.Pattern; 7 | import jakarta.validation.constraints.Size; 8 | import lombok.Getter; 9 | import lombok.Setter; 10 | 11 | @Getter 12 | @Setter 13 | public class UserUpdateDto { 14 | @Size(max=100) 15 | @Email 16 | private String email; 17 | @NotBlank 18 | @Size(min=4,max=20) 19 | private String firstName; 20 | @NotBlank 21 | @Size(min=4,max = 40) 22 | private String lastName; 23 | @NotBlank 24 | @Size(min = 4,max=40) 25 | @Pattern(regexp = "[0-9]{12}") 26 | private String mobile; 27 | private EGender gender; 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/enums/EGender.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.enums; 2 | 3 | public enum EGender { 4 | MALE,FEMALE 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/enums/ERoleType.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.enums; 2 | 3 | public enum ERoleType { 4 | ADMIN, 5 | USER, 6 | GUEST 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/enums/EStatus.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.enums; 2 | 3 | public enum EStatus { 4 | ACTIVE,INACTIVE 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/enums/ETaskStatus.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.enums; 2 | 3 | public enum ETaskStatus { 4 | TODO,IN_PROGRESS,COMPLETED 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/exceptions/ApiRequestException.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.exceptions; 2 | 3 | public class ApiRequestException extends RuntimeException{ 4 | public ApiRequestException(String message){ 5 | super(message); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/exceptions/AppException.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.exceptions; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.bind.annotation.ResponseStatus; 5 | 6 | @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) 7 | public class AppException extends RuntimeException{ 8 | public AppException(String message){ 9 | super(message); 10 | } 11 | public AppException(String message,Throwable cause){ 12 | super(message,cause); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/exceptions/BadRequestException.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.exceptions; 2 | 3 | import org.springframework.http.HttpStatus; 4 | import org.springframework.web.bind.annotation.ResponseStatus; 5 | 6 | @ResponseStatus(HttpStatus.BAD_REQUEST) 7 | public class BadRequestException extends RuntimeException { 8 | public BadRequestException(String message) { 9 | super(message); 10 | } 11 | public BadRequestException(String message,Throwable cause){ 12 | super(message,cause); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/exceptions/ResourceNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.exceptions; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | 6 | @Getter 7 | @Setter 8 | public class ResourceNotFoundException extends RuntimeException { 9 | private String resourceName; 10 | private String fieldName; 11 | private Object fieldValue; 12 | public ResourceNotFoundException(String resourceName,String fieldName,Object fieldValue) 13 | { 14 | super(String.format("%s with %s ['%s'] not found",resourceName,fieldName,fieldValue)); 15 | this.resourceName=resourceName; 16 | this.fieldName=fieldName; 17 | this.fieldValue=fieldValue; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/models/File.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.models; 2 | 3 | import jakarta.persistence.*; 4 | import lombok.Getter; 5 | import lombok.Setter; 6 | 7 | import java.util.UUID; 8 | 9 | @Entity 10 | @Getter 11 | @Setter 12 | public class File { 13 | @Id 14 | @GeneratedValue(strategy = GenerationType.AUTO) 15 | private UUID id; 16 | private String filename; 17 | @Lob 18 | private byte[] file; 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/models/Inventory.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; 4 | import jakarta.persistence.*; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Getter; 7 | import lombok.NoArgsConstructor; 8 | import lombok.Setter; 9 | import org.springframework.data.annotation.CreatedDate; 10 | import org.springframework.data.annotation.LastModifiedDate; 11 | import org.springframework.data.jpa.domain.support.AuditingEntityListener; 12 | 13 | import java.time.LocalDateTime; 14 | import java.util.UUID; 15 | 16 | @Entity 17 | @Getter 18 | @Setter 19 | @AllArgsConstructor 20 | @NoArgsConstructor 21 | @EntityListeners(AuditingEntityListener.class) 22 | public class Inventory { 23 | @Id 24 | @GeneratedValue(strategy = GenerationType.AUTO) 25 | private UUID id; 26 | private int quantity; 27 | private String location; 28 | @OneToOne(mappedBy = "inventory") 29 | @JsonIgnore 30 | private Product product; 31 | @CreatedDate 32 | private LocalDateTime createdAt; 33 | @LastModifiedDate 34 | private LocalDateTime updatedAt; 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/models/Message.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.models; 2 | 3 | import jakarta.persistence.Entity; 4 | import jakarta.persistence.GeneratedValue; 5 | import jakarta.persistence.GenerationType; 6 | import jakarta.persistence.Id; 7 | import lombok.Getter; 8 | import lombok.Setter; 9 | 10 | import java.util.UUID; 11 | @Getter 12 | @Setter 13 | @Entity 14 | public class Message { 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.AUTO) 17 | private UUID id; 18 | private String message; 19 | private String sender; 20 | private String receiver; 21 | private String is_read; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/models/Product.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.models; 2 | 3 | import jakarta.persistence.*; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | 9 | import java.util.UUID; 10 | 11 | @Getter 12 | @Setter 13 | @NoArgsConstructor 14 | @AllArgsConstructor 15 | @Entity 16 | public class Product { 17 | @Id 18 | @GeneratedValue(strategy = GenerationType.AUTO) 19 | private UUID id; 20 | private String name; 21 | private String description; 22 | private int price; 23 | private int quantity; 24 | @OneToOne(cascade = CascadeType.ALL,fetch=FetchType.LAZY) 25 | @JoinColumn(name = "inventory_id",referencedColumnName = "id") 26 | private Inventory inventory; 27 | private String category; 28 | public Product(String name, String description, int price, int quantity, String category,String inventoryLocation,int inventoryQuantity) { 29 | this.name = name; 30 | this.description = description; 31 | this.price = price; 32 | this.quantity = quantity; 33 | this.category = category; 34 | this.inventory = new Inventory(); 35 | this.inventory.setLocation(inventoryLocation); 36 | this.inventory.setQuantity(inventoryQuantity); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/models/Role.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.models; 2 | 3 | import com.starter.backend.enums.ERoleType; 4 | import jakarta.persistence.*; 5 | import lombok.Getter; 6 | import lombok.NoArgsConstructor; 7 | import lombok.Setter; 8 | 9 | import java.util.UUID; 10 | 11 | @Getter 12 | @Setter 13 | @NoArgsConstructor 14 | @Entity 15 | @Table(name="role") 16 | public class Role { 17 | @Id 18 | @GeneratedValue(strategy = GenerationType.AUTO) 19 | private UUID id; 20 | @Enumerated(EnumType.STRING) 21 | private ERoleType name; 22 | public Role(ERoleType name){ 23 | this.name=name; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/models/Task.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.models; 2 | 3 | import com.starter.backend.enums.ETaskStatus; 4 | import jakarta.persistence.*; 5 | import jakarta.validation.constraints.NotBlank; 6 | import lombok.AllArgsConstructor; 7 | import lombok.Getter; 8 | import lombok.NoArgsConstructor; 9 | import lombok.Setter; 10 | 11 | import java.util.UUID; 12 | 13 | @Entity 14 | @Setter 15 | @Getter 16 | @AllArgsConstructor 17 | @NoArgsConstructor 18 | public class Task { 19 | @Id 20 | @GeneratedValue(strategy = GenerationType.AUTO) 21 | private UUID id; 22 | private String title; 23 | private String description; 24 | @Enumerated(EnumType.STRING) 25 | private ETaskStatus status; 26 | @Column(nullable = true) 27 | private String assignedTo; 28 | public Task(String title, String description, ETaskStatus status) { 29 | this.title = title; 30 | this.description = description; 31 | this.status = status; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/models/User.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.models; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; 4 | import com.starter.backend.enums.EGender; 5 | import com.starter.backend.enums.EStatus; 6 | import jakarta.persistence.*; 7 | import lombok.Getter; 8 | import lombok.NoArgsConstructor; 9 | import lombok.Setter; 10 | 11 | import java.util.HashSet; 12 | import java.util.Set; 13 | import java.util.UUID; 14 | 15 | @Getter 16 | @Setter 17 | @NoArgsConstructor 18 | @Entity 19 | @Table(name="users",uniqueConstraints = {@UniqueConstraint(columnNames = {"mobile"}),@UniqueConstraint(columnNames = {"email"})}) 20 | public class User { 21 | @Id 22 | @GeneratedValue(strategy = GenerationType.AUTO) 23 | private UUID id; 24 | private String email; 25 | private String firstName; 26 | private String lastName; 27 | private String mobile; 28 | @Enumerated(EnumType.STRING) 29 | private EGender gender; 30 | @Enumerated(EnumType.STRING) 31 | @Column(name="status") 32 | private EStatus status = EStatus.ACTIVE; 33 | @ManyToMany(fetch = FetchType.EAGER) 34 | @JoinTable(name = "user_roles",joinColumns = @JoinColumn(name="user_id"),inverseJoinColumns = @JoinColumn(name="role_id")) 35 | private Set roles = new HashSet<>(); 36 | @JsonIgnore 37 | private String password; 38 | public User(String email,String firstName,String lastName,String mobile,EGender gender,String password){ 39 | this.email=email; 40 | this.firstName=firstName; 41 | this.lastName=lastName; 42 | this.mobile = mobile; 43 | this.gender = gender; 44 | this.password=password; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/payload/ApiResponse.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.payload; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.Setter; 6 | 7 | @Getter 8 | @Setter 9 | @AllArgsConstructor 10 | public class ApiResponse { 11 | private boolean success; 12 | private String message; 13 | private Object data; 14 | 15 | public ApiResponse(boolean success, String message) { 16 | this.success = success; 17 | this.message = message; 18 | } 19 | 20 | public ApiResponse(boolean success, Object data) { 21 | this.success = success; 22 | this.data=data; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/payload/JwtAuthResponse.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.payload; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | 6 | @Getter 7 | @Setter 8 | public class JwtAuthResponse { 9 | private String accessToken; 10 | private String tokenType="Bearer"; 11 | public JwtAuthResponse(String accessToken){ 12 | this.accessToken=accessToken; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/repository/FileRepository.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.repository; 2 | 3 | import com.starter.backend.models.File; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import java.util.UUID; 7 | 8 | public interface FileRepository extends JpaRepository { 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/repository/InventoryRepository.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.repository; 2 | 3 | import com.starter.backend.models.Inventory; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import java.util.UUID; 7 | 8 | public interface InventoryRepository extends JpaRepository { 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/repository/ProductRepository.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.repository; 2 | 3 | import com.starter.backend.models.Product; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.data.jpa.repository.Query; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | import java.util.UUID; 10 | 11 | @Repository 12 | public interface ProductRepository extends JpaRepository { 13 | @Query(value="SELECT * from Product where category = :category",nativeQuery = true) 14 | List findByCategory(String category); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/repository/RoleRepository.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.repository; 2 | 3 | import com.starter.backend.enums.ERoleType; 4 | import com.starter.backend.models.Role; 5 | import org.springframework.data.jpa.repository.JpaRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.Optional; 9 | import java.util.UUID; 10 | 11 | @Repository 12 | public interface RoleRepository extends JpaRepository { 13 | 14 | Optional findByName(ERoleType roleType); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/repository/TaskRepository.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.repository; 2 | 3 | import com.starter.backend.models.Task; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | import java.util.UUID; 7 | 8 | public interface TaskRepository extends JpaRepository { 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.repository; 2 | 3 | import com.starter.backend.models.User; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | import java.util.Optional; 8 | import java.util.UUID; 9 | @Repository 10 | public interface UserRepository extends JpaRepository { 11 | Optional findByEmail(String email); 12 | Optional findByEmailOrMobile(String email,String mobile); 13 | Optional findById(UUID id); 14 | Boolean existsByMobile(String mobile); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/schedules/LogCleanupTask.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.schedules; 2 | 3 | import org.springframework.scheduling.annotation.Scheduled; 4 | import org.springframework.stereotype.Component; 5 | 6 | import java.io.File; 7 | import java.time.Instant; 8 | import java.time.temporal.ChronoUnit; 9 | 10 | @Component 11 | public class LogCleanupTask { 12 | private static final String LOG_DIR = "./"; 13 | private static final String LOG_FILE_PREFIX ="project."; 14 | private static final int RETENTION_DAYS = 30; 15 | @Scheduled(cron = "0 0 1 * * ?") 16 | public void cleanOldLogs(){ 17 | File folder = new File(LOG_DIR); 18 | if(!folder.exists() || !folder.isDirectory()){ 19 | return; 20 | } 21 | File[] files = folder.listFiles((dir,name)->name.startsWith(LOG_FILE_PREFIX)&&name.endsWith(".log")); 22 | if(files==null){ 23 | return; 24 | } 25 | Instant cutoff = Instant.now().minus(RETENTION_DAYS, ChronoUnit.DAYS); 26 | for(File file : files){ 27 | if(Instant.ofEpochMilli(file.lastModified()).isBefore(cutoff)){ 28 | boolean deleted = file.delete(); 29 | if(deleted){ 30 | System.out.println("Deleted file: " +file.getName()); 31 | } 32 | } 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/security/CustomUserDetailsService.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.security; 2 | 3 | import com.starter.backend.models.User; 4 | import com.starter.backend.repository.UserRepository; 5 | import jakarta.transaction.Transactional; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.security.core.userdetails.UserDetails; 8 | import org.springframework.security.core.userdetails.UserDetailsService; 9 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 10 | import org.springframework.stereotype.Service; 11 | 12 | import java.util.UUID; 13 | 14 | @Service 15 | public class CustomUserDetailsService implements UserDetailsService { 16 | @Autowired 17 | UserRepository userRepository; 18 | 19 | @Transactional 20 | public UserDetails loadUserById(UUID id){ 21 | User user = userRepository.findById(id).orElseThrow(()->new UsernameNotFoundException("user not found with id : "+id)); 22 | return UserPrincipal.create(user); 23 | } 24 | @Transactional 25 | public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException{ 26 | User user = userRepository.findByEmailOrMobile(s,s).orElseThrow(()-> new UsernameNotFoundException("user not found with email or mobile of "+s)); 27 | System.out.println("user in the user details service "+user.getPassword()); 28 | return UserPrincipal.create(user); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/security/JwtAuthEntryPoint.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.security; 2 | 3 | import jakarta.servlet.ServletException; 4 | import jakarta.servlet.http.HttpServletRequest; 5 | import jakarta.servlet.http.HttpServletResponse; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.security.core.AuthenticationException; 9 | import org.springframework.security.web.AuthenticationEntryPoint; 10 | import org.springframework.stereotype.Component; 11 | 12 | import java.io.IOException; 13 | 14 | @Component 15 | public class JwtAuthEntryPoint implements AuthenticationEntryPoint { 16 | private static final Logger logger = LoggerFactory.getLogger(JwtAuthEntryPoint.class); 17 | @Override 18 | public void commence( HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException { 19 | logger.error("responding with unauthorized error.message - {}",e.getMessage()); 20 | httpServletResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED,"Sorry , you are not authorised to access this resource"+e.getMessage()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/security/JwtAuthFilter.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.security; 2 | 3 | import jakarta.servlet.FilterChain; 4 | import jakarta.servlet.ServletException; 5 | import jakarta.servlet.http.HttpServletRequest; 6 | import jakarta.servlet.http.HttpServletResponse; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 11 | import org.springframework.security.core.context.SecurityContextHolder; 12 | import org.springframework.security.core.userdetails.UserDetails; 13 | import org.springframework.stereotype.Component; 14 | import org.springframework.util.StringUtils; 15 | import org.springframework.web.filter.OncePerRequestFilter; 16 | 17 | import java.io.IOException; 18 | import java.util.UUID; 19 | 20 | @Component 21 | public class JwtAuthFilter extends OncePerRequestFilter { 22 | 23 | @Autowired 24 | private JwtTokenProvider tokenProvider; 25 | 26 | @Autowired 27 | private CustomUserDetailsService customUserDetailsService; 28 | 29 | private static final Logger logger = LoggerFactory.getLogger(JwtAuthFilter.class); 30 | 31 | @Override 32 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) 33 | throws ServletException, IOException { 34 | try { 35 | String jwt = getJwtFromRequest(request); 36 | 37 | if (StringUtils.hasText(jwt) && tokenProvider.validateToken(jwt)) { 38 | String userId = tokenProvider.getUserIdFromToken(jwt); 39 | System.out.println("user id in token "+userId); 40 | UserDetails userDetails = customUserDetailsService.loadUserById(UUID.fromString(userId)); 41 | 42 | if (SecurityContextHolder.getContext().getAuthentication() == null) { 43 | UsernamePasswordAuthenticationToken authenticationToken = 44 | new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()); 45 | 46 | SecurityContextHolder.getContext().setAuthentication(authenticationToken); 47 | } 48 | } 49 | 50 | } catch (Exception e) { 51 | logger.error("Could not set user authentication context", e); 52 | } 53 | 54 | filterChain.doFilter(request, response); 55 | } 56 | 57 | private String getJwtFromRequest(HttpServletRequest request) { 58 | String bearerToken = request.getHeader("Authorization"); 59 | System.out.println("authentication token on retrival "+bearerToken); 60 | if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer ")) { 61 | System.out.println("validity is good "+bearerToken.substring(7)); 62 | return bearerToken.substring(7); // remove "Bearer " 63 | } 64 | return null; 65 | } 66 | @Override 67 | protected boolean shouldNotFilter(HttpServletRequest request) { 68 | String path = request.getRequestURI(); 69 | return path.startsWith("/swagger-ui.html") || path.startsWith("/swagger-ui/index.html"); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/security/JwtTokenProvider.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.security; 2 | 3 | import com.starter.backend.models.User; 4 | import com.starter.backend.repository.UserRepository; 5 | import io.jsonwebtoken.*; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.beans.factory.annotation.Value; 10 | import org.springframework.security.core.Authentication; 11 | import org.springframework.security.core.GrantedAuthority; 12 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 13 | import org.springframework.stereotype.Component; 14 | 15 | import java.util.*; 16 | @Component 17 | public class JwtTokenProvider { 18 | private static final Logger logger = LoggerFactory.getLogger(JwtTokenProvider.class); 19 | 20 | @Autowired 21 | private UserRepository userRepository; 22 | 23 | @Value("${jwt.secret}") 24 | private String jwtSecret; 25 | @Value("${jwt.expiresIn}") 26 | private int jwtExpirationInMs; 27 | public String generateToken(Authentication authentication){ 28 | System.out.println("Authentication "+authentication.getPrincipal()); 29 | UserPrincipal userPrincipal = (UserPrincipal) authentication.getPrincipal(); 30 | Date now = new Date(); 31 | Date expiryDate = new Date(now.getTime()+jwtExpirationInMs); 32 | Set grantedAuthorities = new HashSet<>(); 33 | for(GrantedAuthority role : userPrincipal.getAuthorities()){ 34 | grantedAuthorities.add(new SimpleGrantedAuthority(role.getAuthority())); 35 | } 36 | User authUser = userRepository.findById(userPrincipal.getId()).get(); 37 | System.out.println("authUser in the Jwt auth Provider"+authUser); 38 | String token = Jwts.builder().setId(authUser.getId()+"") 39 | .setSubject(userPrincipal.getId()+"") 40 | .claim("authorities",grantedAuthorities) 41 | .claim("user",authUser) 42 | .setIssuedAt(new 43 | Date(System.currentTimeMillis())) .setExpiration(expiryDate) 44 | .signWith(SignatureAlgorithm.HS512, jwtSecret).compact(); 45 | return token; 46 | } 47 | public String getUserIdFromToken(String token) { 48 | Claims claims = Jwts.parser() 49 | .setSigningKey(jwtSecret).build() 50 | .parseClaimsJws(token) 51 | .getBody(); 52 | return claims.getSubject(); 53 | } 54 | public boolean validateToken(String authToken){ 55 | try{ 56 | Jwts.parser().setSigningKey(jwtSecret).build().parseClaimsJws(authToken); 57 | return true; 58 | }catch(SignatureException ex){ 59 | logger.error("Invalid JWT Signature"); 60 | }catch(MalformedJwtException ex){ 61 | logger.error("Invalid JWT Token",ex); 62 | }catch(ExpiredJwtException ex){ 63 | logger.error("Expired JWT Token"+ex); 64 | }catch(UnsupportedJwtException ex){ 65 | logger.error("Unsupported JWT Token"+ex); 66 | }catch(IllegalArgumentException ex){ 67 | logger.error("JWT Claims String is empty"+ex); 68 | } 69 | return false; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/security/PasswordConstraintValidator.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.security; 2 | 3 | import com.google.common.base.Joiner; 4 | import jakarta.validation.ConstraintValidator; 5 | import jakarta.validation.ConstraintValidatorContext; 6 | import org.passay.*; 7 | 8 | import java.util.Arrays; 9 | 10 | public class PasswordConstraintValidator implements ConstraintValidator { 11 | @Override 12 | public boolean isValid(String password, ConstraintValidatorContext context){ 13 | PasswordValidator validator = new PasswordValidator(Arrays.asList(new LengthRule(8,30),new WhitespaceRule())); 14 | RuleResult result = validator.validate(new PasswordData(password)); 15 | if(result.isValid()){ 16 | return true; 17 | } 18 | context.disableDefaultConstraintViolation(); 19 | context.buildConstraintViolationWithTemplate(Joiner.on(",").join(validator.getMessages(result))).addConstraintViolation(); 20 | return false; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/security/UserPrincipal.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.security; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; 4 | import com.starter.backend.models.User; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Getter; 7 | import lombok.Setter; 8 | import org.springframework.security.core.GrantedAuthority; 9 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 10 | import org.springframework.security.core.userdetails.UserDetails; 11 | 12 | import java.util.*; 13 | import java.util.stream.Collectors; 14 | @Getter 15 | @Setter 16 | @AllArgsConstructor 17 | public class UserPrincipal implements UserDetails { 18 | private UUID id; 19 | @JsonIgnore 20 | private String email; 21 | private String firstName; 22 | private String lastName; 23 | @JsonIgnore 24 | private String mobile; 25 | @JsonIgnore 26 | private String password; 27 | private Collection authorities; 28 | public static UserPrincipal create(User user){ 29 | List authorities = user.getRoles().stream().map(role -> new SimpleGrantedAuthority(role.getName().name())).collect(Collectors.toList()); 30 | return new UserPrincipal(user.getId(),user.getEmail(),user.getFirstName(),user.getLastName(),user.getMobile(),user.getPassword(),authorities); 31 | } 32 | @Override 33 | public Collection getAuthorities(){ 34 | return authorities; 35 | } 36 | @Override 37 | public String getPassword(){ 38 | 39 | System.out.println("password being called "+password); 40 | return password; 41 | } 42 | @Override 43 | public String getUsername(){ 44 | return email; 45 | } 46 | @Override 47 | public boolean isAccountNonExpired(){ 48 | return true; 49 | } 50 | @Override 51 | public boolean isAccountNonLocked(){ 52 | return true; 53 | } 54 | @Override 55 | public boolean isCredentialsNonExpired(){ 56 | return true; 57 | } 58 | @Override 59 | public boolean isEnabled(){ 60 | return true; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/security/ValidPassword.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.security; 2 | 3 | import jakarta.validation.Constraint; 4 | import jakarta.validation.Payload; 5 | 6 | import java.lang.annotation.*; 7 | 8 | @Documented 9 | @Constraint(validatedBy =PasswordConstraintValidator.class) 10 | @Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE,ElementType.FIELD,ElementType.METHOD}) 11 | @Retention(RetentionPolicy.RUNTIME) 12 | public @interface ValidPassword { 13 | String message() default "Invalid Password"; 14 | Class[] groups() default {}; 15 | Class[] payload() default {}; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/security/WebSocketSecurityConfig.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.security; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | 5 | import org.springframework.security.core.Authentication; 6 | import org.springframework.security.core.context.SecurityContextHolder; 7 | import org.springframework.web.socket.WebSocketHandler; 8 | import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; 9 | import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; 10 | import org.springframework.web.socket.server.HandshakeInterceptor; 11 | import org.springframework.http.server.ServerHttpRequest; 12 | import org.springframework.http.server.ServerHttpResponse; 13 | 14 | import java.util.Map; 15 | 16 | @Configuration 17 | @EnableWebSocketMessageBroker 18 | public class WebSocketSecurityConfig implements WebSocketMessageBrokerConfigurer { 19 | public static class HttpSessionHandshakeInterceptor implements HandshakeInterceptor { 20 | 21 | @Override 22 | public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, 23 | WebSocketHandler wsHandler, Map attributes) throws Exception { 24 | Authentication auth = SecurityContextHolder.getContext().getAuthentication(); 25 | if (auth != null && auth.isAuthenticated()) { 26 | String username = auth.getName(); 27 | attributes.put("username", username); // Add username to WebSocket session attributes 28 | } 29 | return true; 30 | } 31 | 32 | @Override 33 | public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, 34 | WebSocketHandler wsHandler, Exception exception) { 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/services/EmailService.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.services; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.mail.SimpleMailMessage; 5 | import org.springframework.mail.javamail.JavaMailSender; 6 | import org.springframework.stereotype.Service; 7 | 8 | @Service 9 | public class EmailService { 10 | @Autowired 11 | JavaMailSender mailSender; 12 | public void sendSimpleMessage(String to , String subject , String text){ 13 | SimpleMailMessage message = new SimpleMailMessage(); 14 | message.setFrom("mugishapascal2008@gmail.com"); 15 | message.setTo(to); 16 | message.setSubject(subject); 17 | message.setText(text); 18 | mailSender.send(message); 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/services/FIleService.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.services; 2 | 3 | import com.starter.backend.models.File; 4 | import com.starter.backend.repository.FileRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.web.multipart.MultipartFile; 8 | 9 | import java.io.IOException; 10 | import java.util.UUID; 11 | 12 | @Service 13 | public class FIleService { 14 | @Autowired 15 | private FileRepository fileRepository; 16 | public File storeFile(MultipartFile file) throws IOException { 17 | File newFile = new File(); 18 | newFile.setFilename(file.getOriginalFilename()); 19 | newFile.setFile(file.getBytes()); 20 | return fileRepository.save(newFile); 21 | } 22 | public File getFile(UUID id){ 23 | return fileRepository.findById(id).orElse(null); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/services/InventoryService.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.services; 2 | 3 | import com.starter.backend.dtos.UpdateInventoryDto; 4 | import com.starter.backend.models.Inventory; 5 | import com.starter.backend.models.Product; 6 | import com.starter.backend.repository.InventoryRepository; 7 | import com.starter.backend.repository.ProductRepository; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.http.ResponseEntity; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.web.bind.annotation.PathVariable; 12 | 13 | import java.util.UUID; 14 | 15 | @Service 16 | public class InventoryService { 17 | @Autowired 18 | private InventoryRepository inventoryRepository; 19 | @Autowired 20 | private ProductRepository productRepository; 21 | public ResponseEntity updateInventory( UUID id, UpdateInventoryDto updateInventoryDto){ 22 | return productRepository.findById(id).map(existingProduct -> { 23 | if(updateInventoryDto != null) { 24 | Inventory existingInventory = existingProduct.getInventory(); 25 | existingInventory.setQuantity(updateInventoryDto.getQuantity()); 26 | existingInventory.setLocation(updateInventoryDto.getLocation()); 27 | } 28 | Product updatedProduct = productRepository.save(existingProduct); 29 | return ResponseEntity.ok(updatedProduct); 30 | }).orElse(ResponseEntity.notFound().build()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/services/ProductService.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.services; 2 | 3 | import com.starter.backend.dtos.ProductDto; 4 | import com.starter.backend.exceptions.ApiRequestException; 5 | import com.starter.backend.models.Product; 6 | import com.starter.backend.repository.ProductRepository; 7 | import com.starter.backend.util.Constants; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.data.domain.Page; 10 | import org.springframework.data.domain.PageRequest; 11 | import org.springframework.data.domain.Pageable; 12 | import org.springframework.data.domain.Sort; 13 | import org.springframework.stereotype.Service; 14 | 15 | import java.util.*; 16 | 17 | @Service 18 | public class ProductService { 19 | private final ProductRepository productRepository; 20 | 21 | @Autowired 22 | public ProductService(ProductRepository productRepository){ 23 | this.productRepository = productRepository; 24 | } 25 | 26 | public List getAllProducts(){ 27 | return productRepository.findAll(); 28 | } 29 | 30 | public Product addProduct(ProductDto productDto){ 31 | System.out.println("product log in service"+productDto.getInventory().getLocation()); 32 | Product product = new Product( 33 | productDto.getName(), 34 | productDto.getDescription(), 35 | productDto.getPrice(), 36 | productDto.getQuantity(), 37 | productDto.getCategory(), 38 | productDto.getInventory().getLocation(), 39 | productDto.getInventory().getQuantity() 40 | ); 41 | return productRepository.save(product); 42 | } 43 | 44 | public Product getProduct(UUID id){ 45 | return productRepository.findById(id) 46 | .orElseThrow(() -> new ApiRequestException("Product with id " + id + " not found")); 47 | } 48 | 49 | public Product updateProduct(UUID id, ProductDto productDto){ 50 | Product existingProduct = productRepository.findById(id) 51 | .orElseThrow(() -> new ApiRequestException("Product with id " + id + " not found")); 52 | 53 | existingProduct.setName(productDto.getName()); 54 | existingProduct.setDescription(productDto.getDescription()); 55 | existingProduct.setPrice(productDto.getPrice()); 56 | existingProduct.setQuantity(productDto.getQuantity()); 57 | existingProduct.setCategory(productDto.getCategory()); 58 | 59 | return productRepository.save(existingProduct); 60 | } 61 | 62 | public void deleteProduct(UUID id){ 63 | Product product = productRepository.findById(id) 64 | .orElseThrow(() -> new ApiRequestException("Product with id " + id + " not found")); 65 | productRepository.delete(product); 66 | } 67 | public List findProductsByCategory(String category){ 68 | List products = productRepository.findByCategory(category); 69 | return products; 70 | } 71 | public Page productsPagination(int page,int size,String column){ 72 | Constants.validatePageNumberAndPageSize(page,size); 73 | Pageable pageable =(Pageable) PageRequest.of(page,size, Sort.Direction.ASC,column); 74 | Page products = productRepository.findAll(pageable); 75 | return products; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/services/QueryResolver.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.services; 2 | 3 | import graphql.kickstart.tools.GraphQLQueryResolver; 4 | import org.springframework.stereotype.Component; 5 | 6 | @Component 7 | public class QueryResolver implements GraphQLQueryResolver { 8 | public String hello() { 9 | System.out.println("working"); 10 | return "Hello, GraphQL!"; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/services/TaskService.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.services; 2 | 3 | import com.starter.backend.dtos.TaskDto; 4 | import com.starter.backend.models.Task; 5 | import com.starter.backend.repository.TaskRepository; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import java.util.List; 10 | import java.util.UUID; 11 | 12 | @Service 13 | public class TaskService { 14 | @Autowired 15 | private TaskRepository taskRepository; 16 | public Task addTask(TaskDto taskDto){ 17 | Task task = new Task(taskDto.getTitle(), taskDto.getDescription(),taskDto.getStatus()); 18 | return taskRepository.save(task); 19 | } 20 | public Task updateTask(TaskDto taskDto, UUID id){ 21 | Task task = taskRepository.findById(id).orElseThrow(()-> new RuntimeException("Task not found")); 22 | task.setTitle(taskDto.getTitle()); 23 | task.setDescription(taskDto.getDescription()); 24 | task.setStatus(taskDto.getStatus()); 25 | return taskRepository.save(task); 26 | } 27 | public String deleteTask(UUID id){ 28 | Task task = taskRepository.findById(id).orElseThrow(()-> new RuntimeException("Task not found")); 29 | if(taskRepository.existsById(id)){ 30 | taskRepository.deleteById(id); 31 | return "Task deleted"; 32 | }else{ 33 | return "Task not found"; 34 | } 35 | } 36 | public List getAllTasks(){ 37 | return taskRepository.findAll(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/services/UserService.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.services; 2 | 3 | import com.starter.backend.dtos.UserUpdateDto; 4 | import com.starter.backend.exceptions.ApiRequestException; 5 | import com.starter.backend.exceptions.AppException; 6 | import com.starter.backend.exceptions.ResourceNotFoundException; 7 | import com.starter.backend.models.User; 8 | import com.starter.backend.repository.RoleRepository; 9 | import com.starter.backend.repository.UserRepository; 10 | import com.starter.backend.util.Constants; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.data.domain.Page; 13 | import org.springframework.data.domain.PageRequest; 14 | import org.springframework.data.domain.Pageable; 15 | import org.springframework.data.domain.Sort; 16 | import org.springframework.security.core.context.SecurityContextHolder; 17 | import org.springframework.security.core.userdetails.UserDetails; 18 | import org.springframework.stereotype.Service; 19 | 20 | import java.util.UUID; 21 | 22 | @Service 23 | public class UserService { 24 | private final UserRepository userRepository; 25 | private final RoleRepository roleRepository; 26 | @Autowired 27 | public UserService(UserRepository userRepository,RoleRepository roleRepository){ 28 | this.userRepository=userRepository; 29 | this.roleRepository=roleRepository; 30 | } 31 | public User getUser(UUID userId){ 32 | return this.userRepository.findById(userId).orElseThrow(()-> new ApiRequestException("user with id "+userId+" not found")); 33 | } 34 | public User deleteUser(UUID userId){ 35 | User user = userRepository.findById(userId).orElseThrow(()-> new ApiRequestException("user with id "+userId+" not found")); 36 | this.userRepository.delete(user); 37 | 38 | return user; 39 | } 40 | public Page getAllUsers(int page,int size,String column){ 41 | Constants.validatePageNumberAndPageSize(page,size); 42 | Pageable pageable = (Pageable) PageRequest.of(page,size, Sort.Direction.ASC,column); 43 | Page users = userRepository.findAll(pageable); 44 | return users; 45 | } 46 | public User getLoggedInUser(){ 47 | String email; 48 | Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); 49 | if(principal instanceof UserDetails){ 50 | email = ((UserDetails) principal).getUsername(); 51 | }else{ 52 | email=principal.toString(); 53 | } 54 | User findByEmail = userRepository.findByEmail(email).orElseThrow(()-> new ApiRequestException("user with email "+email+" not found")); 55 | return findByEmail; 56 | } 57 | public User updateUser(UUID userId, UserUpdateDto userUpdateRequest){ 58 | User user = userRepository.findById(userId).orElseThrow(()->new ResourceNotFoundException("get user by id",""+userId,new User())); 59 | if(getLoggedInUser().getId() != user.getId()){ 60 | throw new AppException("you are not authorized to update"); 61 | } 62 | if(userRepository.existsByMobile(userUpdateRequest.getMobile()) && !(userUpdateRequest.getMobile().equalsIgnoreCase(user.getMobile()))){ 63 | throw new AppException("Phone number already in use"); 64 | }else{ 65 | user.setMobile(userUpdateRequest.getMobile()); 66 | } 67 | user.setFirstName(userUpdateRequest.getFirstName()); 68 | user.setLastName(userUpdateRequest.getLastName()); 69 | user.setGender(userUpdateRequest.getGender()); 70 | user.setEmail(userUpdateRequest.getEmail()); 71 | userRepository.save(user); 72 | return user; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/util/Constants.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.util; 2 | 3 | import com.starter.backend.exceptions.BadRequestException; 4 | import org.springframework.security.core.parameters.P; 5 | 6 | public interface Constants { 7 | public String DEFAULT_PAGE_NUMBER = "0"; 8 | public String DEFAULT_PAGE_SIZE = "100"; 9 | public int MAX_PAGE_SIZE=1000; 10 | public static void validatePageNumberAndPageSize(int pageNumber,int pageSize){ 11 | if(pageNumber<0){ 12 | throw new BadRequestException("Page number is less than zero"); 13 | } 14 | if(pageSize>Constants.MAX_PAGE_SIZE){ 15 | throw new BadRequestException("page size is greater then "+Constants.MAX_PAGE_SIZE); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/starter/backend/util/Response.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend.util; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Getter; 5 | import lombok.Setter; 6 | 7 | import java.time.ZonedDateTime; 8 | 9 | @Getter 10 | @Setter 11 | @AllArgsConstructor 12 | public class Response { 13 | private String message; 14 | private ZonedDateTime timstamp; 15 | private Boolean success; 16 | } 17 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=backend 2 | spring.devtools.livereload.enabled=true 3 | server.port=8081 4 | debug=false 5 | logging.level.org.springframework=ERROR 6 | 7 | spring.datasource.driver-class-name=org.postgresql.Driver 8 | spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect 9 | 10 | 11 | # Server settings 12 | server.error.include-message=always 13 | server.error.include-binding-errors=always 14 | #server.servlet.register-default-servlet=on 15 | 16 | # Spring profile 17 | spring.profiles.active=dev 18 | 19 | # DataSource config 20 | spring.datasource.url=jdbc:postgresql://localhost:5432/javadb 21 | spring.datasource.username=postgres 22 | spring.datasource.password=postgres 23 | 24 | # JPA & Hibernate config 25 | spring.jpa.hibernate.ddl-auto=validate 26 | spring.jpa.generate-ddl=true 27 | spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect 28 | spring.jpa.properties.hibernate.format_sql=true 29 | spring.jpa.show-sql=true 30 | 31 | ## JWT settings 32 | jwt.secret=YJKvG2v5rHpYvtcDfNllMeJX9cTtqth0HmnDPtWAV3fR3lIpm3kmRTLLYYUpAmgpCWx7McfEIjNRmFkhiWiECMw 33 | jwt.expiresIn=86400000 34 | 35 | # graphql 36 | spring.graphql.path=/graphql 37 | spring.graphql.schema.locations=classpath:graphql/ 38 | spring.graphql.graphiql.enabled=true 39 | 40 | # google auth 41 | spring.security.oauth2.client.registration.google.client-id=${GOOGLE_CLIENT_ID} 42 | spring.security.oauth2.client.registration.google.client-secret=${GOOGLE_CLIENT_SECRET} 43 | spring.security.oauth2.client.registration.google.scope=email,profile 44 | 45 | spring.security.oauth2.client.registration.google.redirect-uri=http://localhost:8081/custom/oauth2/callback 46 | 47 | #logging into the file 48 | logging.file.name=project.log 49 | logging.level.root=INFO 50 | 51 | #flyway configuration 52 | #spring.flyway.baseline-on-migrate=true 53 | #spring.flyway.enabled=true 54 | #spring.flyway.locations=classpath:db/migration 55 | 56 | #send email props 57 | spring.mail.password=aihh ndty kvky ltmv 58 | spring.mail.host=smtp.gmail.com 59 | spring.mail.port=587 60 | spring.mail.username=mugishapascal2008@gmail.com 61 | spring.mail.properties.mail.smtp.auth=true 62 | spring.mail.properties.mail.smtp.starttls.enable=true 63 | -------------------------------------------------------------------------------- /src/main/resources/graphql/task.graphqls: -------------------------------------------------------------------------------- 1 | type Query { 2 | getAllTasks: [Task!]! 3 | } 4 | 5 | type Mutation { 6 | addTask(input: TaskInput): Task 7 | updateTask(input : TaskInput ,id : ID):Task 8 | deleteTask(id:ID):String 9 | } 10 | 11 | 12 | type Task { 13 | id: ID 14 | title: String 15 | description: String 16 | status: String 17 | assignableTo: String 18 | error:String 19 | } 20 | 21 | input TaskInput { 22 | title: String 23 | description: String 24 | status: String 25 | assignableTo: String 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/starter/backend/BackendApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.starter.backend; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class BackendApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | --------------------------------------------------------------------------------