diff --git a/.gradle/8.2/checksums/checksums.lock b/.gradle/8.2/checksums/checksums.lock new file mode 100644 index 0000000..66e521b Binary files /dev/null and b/.gradle/8.2/checksums/checksums.lock differ diff --git a/.gradle/8.2/dependencies-accessors/dependencies-accessors.lock b/.gradle/8.2/dependencies-accessors/dependencies-accessors.lock new file mode 100644 index 0000000..f44eed4 Binary files /dev/null and b/.gradle/8.2/dependencies-accessors/dependencies-accessors.lock differ diff --git a/src/main/resources/db/migration/V3__go_away_something.sql b/.gradle/8.2/dependencies-accessors/gc.properties similarity index 100% rename from src/main/resources/db/migration/V3__go_away_something.sql rename to .gradle/8.2/dependencies-accessors/gc.properties diff --git a/.gradle/8.2/executionHistory/executionHistory.bin b/.gradle/8.2/executionHistory/executionHistory.bin new file mode 100644 index 0000000..3c64bf9 Binary files /dev/null and b/.gradle/8.2/executionHistory/executionHistory.bin differ diff --git a/.gradle/8.2/executionHistory/executionHistory.lock b/.gradle/8.2/executionHistory/executionHistory.lock new file mode 100644 index 0000000..b68addd Binary files /dev/null and b/.gradle/8.2/executionHistory/executionHistory.lock differ diff --git a/.gradle/8.2/fileChanges/last-build.bin b/.gradle/8.2/fileChanges/last-build.bin new file mode 100644 index 0000000..f76dd23 Binary files /dev/null and b/.gradle/8.2/fileChanges/last-build.bin differ diff --git a/.gradle/8.2/fileHashes/fileHashes.bin b/.gradle/8.2/fileHashes/fileHashes.bin new file mode 100644 index 0000000..8242661 Binary files /dev/null and b/.gradle/8.2/fileHashes/fileHashes.bin differ diff --git a/.gradle/8.2/fileHashes/fileHashes.lock b/.gradle/8.2/fileHashes/fileHashes.lock new file mode 100644 index 0000000..bae14ad Binary files /dev/null and b/.gradle/8.2/fileHashes/fileHashes.lock differ diff --git a/.gradle/8.2/fileHashes/resourceHashesCache.bin b/.gradle/8.2/fileHashes/resourceHashesCache.bin new file mode 100644 index 0000000..0280fdc Binary files /dev/null and b/.gradle/8.2/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/8.2/gc.properties b/.gradle/8.2/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock new file mode 100644 index 0000000..5b06803 Binary files /dev/null and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties new file mode 100644 index 0000000..f80d72a --- /dev/null +++ b/.gradle/buildOutputCleanup/cache.properties @@ -0,0 +1,2 @@ +#Mon Oct 02 17:10:24 IST 2023 +gradle.version=8.2 diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin new file mode 100644 index 0000000..b1c0385 Binary files /dev/null and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe new file mode 100644 index 0000000..991c5a2 Binary files /dev/null and b/.gradle/file-system.probe differ diff --git a/.gradle/vcs-1/gc.properties b/.gradle/vcs-1/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.jpb/jpb-settings.xml b/.jpb/jpb-settings.xml deleted file mode 100644 index c6d2fb3..0000000 --- a/.jpb/jpb-settings.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar deleted file mode 100644 index cb28b0e..0000000 Binary files a/.mvn/wrapper/maven-wrapper.jar and /dev/null differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties deleted file mode 100644 index 2e76e18..0000000 --- a/.mvn/wrapper/maven-wrapper.properties +++ /dev/null @@ -1,2 +0,0 @@ -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.4/apache-maven-3.9.4-bin.zip -wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar diff --git a/README.md b/README.md new file mode 100644 index 0000000..75d4d6c --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +### start mysql container +docker run -p 3306:3306 --name my-mysql -e MYSQL_ROOT_PASSWORD=secret -v $HOME/mysql-data:/var/lib/mysql -d mysql:latest \ No newline at end of file diff --git a/backend module.json b/backend module.json new file mode 100644 index 0000000..476cbc8 --- /dev/null +++ b/backend module.json @@ -0,0 +1,103 @@ +{ + "client": "Thunder Client", + "collectionName": "backend module", + "dateExported": "2023-09-23T11:13:46.818Z", + "version": "1.1", + "folders": [], + "requests": [ + { + "_id": "b6e1c5dd-e2cb-4922-b1df-4b8027ff2093", + "colId": "94371b6c-0274-4884-a2b4-e7c59641ae59", + "containerId": "", + "name": "get product", + "url": "http://localhost:8080/products/2", + "method": "GET", + "sortNum": 10000, + "created": "2023-09-07T13:35:25.110Z", + "modified": "2023-09-19T11:20:44.240Z", + "headers": [], + "params": [], + "tests": [] + }, + { + "_id": "b170e220-6a4e-48c2-8b73-83bffe820c48", + "colId": "94371b6c-0274-4884-a2b4-e7c59641ae59", + "containerId": "", + "name": "update product", + "url": "http://localhost:8080/products/1", + "method": "PUT", + "sortNum": 20000, + "created": "2023-09-07T13:50:26.018Z", + "modified": "2023-09-19T11:37:43.927Z", + "headers": [], + "params": [], + "body": { + "type": "json", + "raw": "{\n \"title\": \"samsung galaxy 2\",\n \"price\": 25000.50,\n \"description\": \"lorem ipsum set\",\n \"image\": \"https://i.pravatar.cc\",\n \"category\": \"mobile\"\n}", + "form": [] + }, + "tests": [] + }, + { + "_id": "877bcd65-e71b-4beb-81fd-6de44c07e228", + "colId": "94371b6c-0274-4884-a2b4-e7c59641ae59", + "containerId": "", + "name": "create product", + "url": "http://localhost:8080/products/", + "method": "POST", + "sortNum": 30000, + "created": "2023-09-19T10:39:37.695Z", + "modified": "2023-09-23T10:43:05.370Z", + "headers": [], + "params": [], + "body": { + "type": "json", + "raw": "{\n \"title\": \"macbook m2\",\n \"price\": 195000.00,\n \"description\": \"lorem ipsum set\",\n \"image\": \"https://i.pravatar.cc\",\n \"category\": \"laptop\"\n}", + "form": [] + }, + "tests": [] + }, + { + "_id": "7b3b931e-8358-42b1-9e18-bbadb883000e", + "colId": "94371b6c-0274-4884-a2b4-e7c59641ae59", + "containerId": "", + "name": "delete product", + "url": "http://localhost:8080/products/52", + "method": "DELETE", + "sortNum": 40000, + "created": "2023-09-19T10:39:53.512Z", + "modified": "2023-09-23T10:44:50.188Z", + "headers": [], + "params": [], + "tests": [] + }, + { + "_id": "0344dfd2-d823-4ae7-9b9b-6c42888ea2ba", + "colId": "94371b6c-0274-4884-a2b4-e7c59641ae59", + "containerId": "", + "name": "get all product", + "url": "http://localhost:8080/products/", + "method": "GET", + "sortNum": 50000, + "created": "2023-09-19T10:40:40.504Z", + "modified": "2023-09-19T10:40:40.504Z", + "headers": [], + "params": [], + "tests": [] + }, + { + "_id": "a497f3d5-ef54-454f-a8c3-356dfcac61ad", + "colId": "94371b6c-0274-4884-a2b4-e7c59641ae59", + "containerId": "", + "name": "get all products of a category", + "url": "http://localhost:8080/categories/computer/products", + "method": "GET", + "sortNum": 60000, + "created": "2023-09-22T13:35:37.939Z", + "modified": "2023-09-22T16:07:23.326Z", + "headers": [], + "params": [], + "tests": [] + } + ] +} \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..f31640b --- /dev/null +++ b/build.gradle @@ -0,0 +1,42 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.1.3' + id 'io.spring.dependency-management' version '1.1.3' +} + +group = 'dev.biswajit.ecomm' +version = '0.0.1-SNAPSHOT' + +java { + sourceCompatibility = '17' +} + +configurations { + compileOnly { + extendsFrom annotationProcessor + } +} + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-webflux' + compileOnly 'org.projectlombok:lombok' + implementation 'mysql:mysql-connector-java:8.0.26' + developmentOnly 'org.springframework.boot:spring-boot-devtools' + annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' + annotationProcessor 'org.projectlombok:lombok' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'io.projectreactor:reactor-test' +} + +tasks.named('test') { + useJUnitPlatform() +} + +tasks.withType(Test) { + enabled=false +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..033e24c Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..62f495d --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..fcb6fca --- /dev/null +++ b/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..6689b85 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/mvnw b/mvnw deleted file mode 100755 index 66df285..0000000 --- a/mvnw +++ /dev/null @@ -1,308 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Apache Maven Wrapper startup batch script, version 3.2.0 -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /usr/local/etc/mavenrc ] ; then - . /usr/local/etc/mavenrc - fi - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "$(uname)" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - JAVA_HOME="$(/usr/libexec/java_home)"; export JAVA_HOME - else - JAVA_HOME="/Library/Java/Home"; export JAVA_HOME - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=$(java-config --jre-home) - fi -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$JAVA_HOME" ] && - JAVA_HOME=$(cygpath --unix "$JAVA_HOME") - [ -n "$CLASSPATH" ] && - CLASSPATH=$(cygpath --path --unix "$CLASSPATH") -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] && - JAVA_HOME="$(cd "$JAVA_HOME" || (echo "cannot cd into $JAVA_HOME."; exit 1); pwd)" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="$(which javac)" - if [ -n "$javaExecutable" ] && ! [ "$(expr "\"$javaExecutable\"" : '\([^ ]*\)')" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=$(which readlink) - if [ ! "$(expr "$readLink" : '\([^ ]*\)')" = "no" ]; then - if $darwin ; then - javaHome="$(dirname "\"$javaExecutable\"")" - javaExecutable="$(cd "\"$javaHome\"" && pwd -P)/javac" - else - javaExecutable="$(readlink -f "\"$javaExecutable\"")" - fi - javaHome="$(dirname "\"$javaExecutable\"")" - javaHome=$(expr "$javaHome" : '\(.*\)/bin') - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="$(\unset -f command 2>/dev/null; \command -v java)" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=$(cd "$wdir/.." || exit 1; pwd) - fi - # end of workaround - done - printf '%s' "$(cd "$basedir" || exit 1; pwd)" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - # Remove \r in case we run on Windows within Git Bash - # and check out the repository with auto CRLF management - # enabled. Otherwise, we may read lines that are delimited with - # \r\n and produce $'-Xarg\r' rather than -Xarg due to word - # splitting rules. - tr -s '\r\n' ' ' < "$1" - fi -} - -log() { - if [ "$MVNW_VERBOSE" = true ]; then - printf '%s\n' "$1" - fi -} - -BASE_DIR=$(find_maven_basedir "$(dirname "$0")") -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR -log "$MAVEN_PROJECTBASEDIR" - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -wrapperJarPath="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" -if [ -r "$wrapperJarPath" ]; then - log "Found $wrapperJarPath" -else - log "Couldn't find $wrapperJarPath, downloading it ..." - - if [ -n "$MVNW_REPOURL" ]; then - wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" - else - wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" - fi - while IFS="=" read -r key value; do - # Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' ) - safeValue=$(echo "$value" | tr -d '\r') - case "$key" in (wrapperUrl) wrapperUrl="$safeValue"; break ;; - esac - done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" - log "Downloading from: $wrapperUrl" - - if $cygwin; then - wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") - fi - - if command -v wget > /dev/null; then - log "Found wget ... using wget" - [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet" - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" - else - wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" - fi - elif command -v curl > /dev/null; then - log "Found curl ... using curl" - [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent" - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" - else - curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" - fi - else - log "Falling back to using Java to download" - javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java" - javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaSource=$(cygpath --path --windows "$javaSource") - javaClass=$(cygpath --path --windows "$javaClass") - fi - if [ -e "$javaSource" ]; then - if [ ! -e "$javaClass" ]; then - log " - Compiling MavenWrapperDownloader.java ..." - ("$JAVA_HOME/bin/javac" "$javaSource") - fi - if [ -e "$javaClass" ]; then - log " - Running MavenWrapperDownloader.java ..." - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath" - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -# If specified, validate the SHA-256 sum of the Maven wrapper jar file -wrapperSha256Sum="" -while IFS="=" read -r key value; do - case "$key" in (wrapperSha256Sum) wrapperSha256Sum=$value; break ;; - esac -done < "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" -if [ -n "$wrapperSha256Sum" ]; then - wrapperSha256Result=false - if command -v sha256sum > /dev/null; then - if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c > /dev/null 2>&1; then - wrapperSha256Result=true - fi - elif command -v shasum > /dev/null; then - if echo "$wrapperSha256Sum $wrapperJarPath" | shasum -a 256 -c > /dev/null 2>&1; then - wrapperSha256Result=true - fi - else - echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." - echo "Please install either command, or disable validation by removing 'wrapperSha256Sum' from your maven-wrapper.properties." - exit 1 - fi - if [ $wrapperSha256Result = false ]; then - echo "Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised." >&2 - echo "Investigate or delete $wrapperJarPath to attempt a clean download." >&2 - echo "If you updated your Maven version, you need to update the specified wrapperSha256Sum property." >&2 - exit 1 - fi -fi - -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$JAVA_HOME" ] && - JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") - [ -n "$CLASSPATH" ] && - CLASSPATH=$(cygpath --path --windows "$CLASSPATH") - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $*" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -# shellcheck disable=SC2086 # safe args -exec "$JAVACMD" \ - $MAVEN_OPTS \ - $MAVEN_DEBUG_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd deleted file mode 100644 index 95ba6f5..0000000 --- a/mvnw.cmd +++ /dev/null @@ -1,205 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM https://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Apache Maven Wrapper startup batch script, version 3.2.0 -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* -if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" - -FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %WRAPPER_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file -SET WRAPPER_SHA_256_SUM="" -FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B -) -IF NOT %WRAPPER_SHA_256_SUM%=="" ( - powershell -Command "&{"^ - "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ - "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ - " Write-Output 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ - " Write-Output 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ - " Write-Output 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ - " exit 1;"^ - "}"^ - "}" - if ERRORLEVEL 1 goto error -) - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% ^ - %JVM_CONFIG_MAVEN_PROPS% ^ - %MAVEN_OPTS% ^ - %MAVEN_DEBUG_OPTS% ^ - -classpath %WRAPPER_JAR% ^ - "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ - %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" -if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%"=="on" pause - -if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% - -cmd /C exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 19a39f7..0000000 --- a/pom.xml +++ /dev/null @@ -1,87 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 3.1.3 - - - dev.naman - productservice - 0.0.1-SNAPSHOT - productservice - productservice - - 17 - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-devtools - runtime - true - - - - org.springframework.boot - spring-boot-configuration-processor - true - - - org.projectlombok - lombok - true - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.boot - spring-boot-starter-actuator - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - com.mysql - mysql-connector-j - runtime - - - - org.flywaydb - flyway-mysql - 9.22.2 - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - - - - - - diff --git a/queries.sql b/queries.sql deleted file mode 100644 index 50d245f..0000000 --- a/queries.sql +++ /dev/null @@ -1,82 +0,0 @@ -select u1_0.id, u1_0.clazz_, u1_0.email, u1_0.name, u1_0.average_rating, u1_0.attendance, u1_0.psp -from (select id, email, name, null as average_rating, null as attendance, null as psp, 0 as clazz_ - from tpc_user - union all - select id, email, name, average_rating, null as attendance, null as psp, 1 as clazz_ - from tpc_mentor - union all - select id, email, name, null as average_rating, attendance, psp, 2 as clazz_ - from tpc_student - union all - select id, email, name, average_rating, null as attendance, null as psp, 3 as clazz_ - from tpc_ta) u1_0 - - -select c1_0.id, - c1_0.name, - p1_0.category_id, - p1_0.id, - p1_0.description, - p1_0.image, - p1_0.price, - p1_0.title -from category c1_0 - left join product p1_0 on c1_0.id = p1_0.category_id -where c1_0.id = ? - -select c1_0.id, c1_0.name -from category c1_0 -where c1_0.id = ? - -select p1_0.category, - p1_0.id, - p1_0.description, - p1_0.image, - p2_0.id, - p2_0.currency, - p2_0.price, - p1_0.title -from product p1_0 - left join price p2_0 on p2_0.id = p1_0.price_id -where p1_0.category = ? - -select p1_0.category, - p1_0.id, - p1_0.description, - p1_0.image, - p2_0.id, - p2_0.currency, - p2_0.price, - p1_0.title -from product p1_0 - left join price p2_0 on p2_0.id = p1_0.price_id -where p1_0.category = ? - -select c1_0.id, - c1_0.name, - p1_0.category, - p1_0.id, - p1_0.description, - p1_0.image, - p2_0.id, - p2_0.currency, - p2_0.price, - p1_0.title -from category c1_0 - left join product p1_0 on c1_0.id = p1_0.category - left join price p2_0 on p2_0.id = p1_0.price_id -where c1_0.id = ? Hibernate: -select c1_0.id, - c1_0.name, - p1_0.category, - p1_0.id, - p1_0.description, - p1_0.image, - p2_0.id, - p2_0.currency, - p2_0.price, - p1_0.title -from category c1_0 - left join product p1_0 on c1_0.id = p1_0.category - left join price p2_0 on p2_0.id = p1_0.price_id -where c1_0.id = ? \ No newline at end of file diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..b489814 --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'productservice' diff --git a/src/main/java/dev/biswajit/ecomm/productservice/ProductServiceApplication.java b/src/main/java/dev/biswajit/ecomm/productservice/ProductServiceApplication.java new file mode 100644 index 0000000..655b18c --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/ProductServiceApplication.java @@ -0,0 +1,13 @@ +package dev.biswajit.ecomm.productservice; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ProductServiceApplication { + + public static void main(String[] args) { + SpringApplication.run(ProductServiceApplication.class, args); + } + +} diff --git a/src/main/java/dev/biswajit/ecomm/productservice/controller/CategoryController.java b/src/main/java/dev/biswajit/ecomm/productservice/controller/CategoryController.java new file mode 100644 index 0000000..715a489 --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/controller/CategoryController.java @@ -0,0 +1,42 @@ +package dev.biswajit.ecomm.productservice.controller; + +import dev.biswajit.ecomm.productservice.dto.CategoryDto; +import dev.biswajit.ecomm.productservice.dto.ProductDto; +import dev.biswajit.ecomm.productservice.service.CategoryService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.util.List; + +@RestController +@RequestMapping("/categories") +public class CategoryController { + + private final CategoryService categoryService; + + public CategoryController(@Autowired CategoryService categoryService) { + this.categoryService = categoryService; + } + + @GetMapping(value = "/") + Flux getAllCategories() { + + return categoryService.allCategories() + .flatMapMany(Flux::fromIterable) + .flatMap(it -> Mono.just(CategoryDto.builder() + .categoryId(it.getId()) + .title(it.getTitle()) + .build())); + } + + @GetMapping("/{title}/products") + public Mono> getProductsIn(@PathVariable String title) { + return categoryService.findProductsByCategory(title); + } + +} diff --git a/src/main/java/dev/biswajit/ecomm/productservice/controller/ProductController.java b/src/main/java/dev/biswajit/ecomm/productservice/controller/ProductController.java new file mode 100644 index 0000000..af39adf --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/controller/ProductController.java @@ -0,0 +1,52 @@ +package dev.biswajit.ecomm.productservice.controller; + +import dev.biswajit.ecomm.productservice.dto.ProductDto; +import dev.biswajit.ecomm.productservice.exception.ErrorDto; +import dev.biswajit.ecomm.productservice.exception.ProductNotFoundException; +import dev.biswajit.ecomm.productservice.service.ProductService; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import reactor.core.publisher.Mono; + +import java.util.List; +import java.util.UUID; + +import static dev.biswajit.ecomm.productservice.exception.ErrorCode.PRODUCT_NOT_FOUND; + +@RestController +@RequestMapping("/products") +public class ProductController { + + private final ProductService productService; + + public ProductController(ProductService productService) { + this.productService = productService; + } + + @GetMapping("/") + public Mono> getAll() { + return productService.allProducts(); + } + + @GetMapping("/{id}") + public Mono getBy(@PathVariable("id") Long productId) throws ProductNotFoundException { + return productService.productBy(productId); + } + + @PostMapping("/") + @ResponseStatus(code = HttpStatus.CREATED) + public Mono add(@RequestBody ProductDto newProduct) { + return productService.add(newProduct); + } + + @PutMapping("/{id}") + public Mono updateBy(@PathVariable("id") Long id, @RequestBody ProductDto updateProductDto) throws ProductNotFoundException { + return productService.updateBy(id, updateProductDto); + } + + @DeleteMapping("/{id}") + public Mono deleteBy(@PathVariable Long id) throws ProductNotFoundException { + return productService.deleteBy(id); + } +} diff --git a/src/main/java/dev/biswajit/ecomm/productservice/dto/CategoryDto.java b/src/main/java/dev/biswajit/ecomm/productservice/dto/CategoryDto.java new file mode 100644 index 0000000..08af6cc --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/dto/CategoryDto.java @@ -0,0 +1,16 @@ +package dev.biswajit.ecomm.productservice.dto; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; + +import java.util.UUID; + +@Builder +public class CategoryDto { + @JsonProperty(value = "id") + private UUID categoryId; + @JsonProperty(value = "title") + @JsonInclude(JsonInclude.Include.NON_NULL) + private String title; +} diff --git a/src/main/java/dev/biswajit/ecomm/productservice/dto/ProductDto.java b/src/main/java/dev/biswajit/ecomm/productservice/dto/ProductDto.java new file mode 100644 index 0000000..c4c6899 --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/dto/ProductDto.java @@ -0,0 +1,25 @@ +package dev.biswajit.ecomm.productservice.dto; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class ProductDto { + private Long id; + private String title; + private String price; + private String category; + @JsonInclude(JsonInclude.Include.NON_NULL) + private String description; + @JsonProperty("image") + private String imageUrl; +} diff --git a/src/main/java/dev/biswajit/ecomm/productservice/exception/ErrorCode.java b/src/main/java/dev/biswajit/ecomm/productservice/exception/ErrorCode.java new file mode 100644 index 0000000..932b774 --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/exception/ErrorCode.java @@ -0,0 +1,6 @@ +package dev.biswajit.ecomm.productservice.exception; + +public enum ErrorCode { + PRODUCT_NOT_FOUND, + INTERNAL_SERVER_ERROR +} diff --git a/src/main/java/dev/biswajit/ecomm/productservice/exception/ErrorDto.java b/src/main/java/dev/biswajit/ecomm/productservice/exception/ErrorDto.java new file mode 100644 index 0000000..7600804 --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/exception/ErrorDto.java @@ -0,0 +1,11 @@ +package dev.biswajit.ecomm.productservice.exception; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; + +@JsonIgnoreProperties(ignoreUnknown = true) +@Data +public class ErrorDto { + private final ErrorCode code; + private final String message; +} diff --git a/src/main/java/dev/biswajit/ecomm/productservice/exception/ProductControllerAdvice.java b/src/main/java/dev/biswajit/ecomm/productservice/exception/ProductControllerAdvice.java new file mode 100644 index 0000000..bb3d9a8 --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/exception/ProductControllerAdvice.java @@ -0,0 +1,27 @@ +package dev.biswajit.ecomm.productservice.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import reactor.core.publisher.Mono; + +import static dev.biswajit.ecomm.productservice.exception.ErrorCode.INTERNAL_SERVER_ERROR; +import static dev.biswajit.ecomm.productservice.exception.ErrorCode.PRODUCT_NOT_FOUND; + +@ControllerAdvice +public class ProductControllerAdvice { + @ExceptionHandler(value = ProductNotFoundException.class) + private ResponseEntity> productNotFoundException(ProductNotFoundException exception) { + return ResponseEntity.status(HttpStatus.NOT_FOUND) + .body(Mono.just(new ErrorDto(PRODUCT_NOT_FOUND, exception.getMessage()))); + } + + @ExceptionHandler + private ResponseEntity> handleDefaultException(Exception e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .body(Mono.just(new ErrorDto(INTERNAL_SERVER_ERROR, e.getMessage()))); + } + + +} diff --git a/src/main/java/dev/biswajit/ecomm/productservice/exception/ProductNotFoundException.java b/src/main/java/dev/biswajit/ecomm/productservice/exception/ProductNotFoundException.java new file mode 100644 index 0000000..83fa634 --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/exception/ProductNotFoundException.java @@ -0,0 +1,12 @@ +package dev.biswajit.ecomm.productservice.exception; + +public class ProductNotFoundException extends Exception{ + private ProductNotFoundException(String message) { + super(message); + } + + public static ProductNotFoundException with(String message) { + return new ProductNotFoundException(message); + } + +} diff --git a/src/main/java/dev/biswajit/ecomm/productservice/model/Category.java b/src/main/java/dev/biswajit/ecomm/productservice/model/Category.java new file mode 100644 index 0000000..2f523a8 --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/model/Category.java @@ -0,0 +1,44 @@ +package dev.biswajit.ecomm.productservice.model; + +import jakarta.persistence.*; +import lombok.*; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; + +import java.util.Objects; +import java.util.Set; +import java.util.UUID; + +@NoArgsConstructor +@Getter +@Setter +@Entity +@Table(name = "CATEGORIES") +public class Category { + @Id + @GeneratedValue(strategy = GenerationType.UUID) + private UUID id; + + private String title; + + @OneToMany(mappedBy = "category", fetch = FetchType.LAZY) + @Fetch(FetchMode.JOIN) + private Set products; + + public Category(String category) { + this.title = category; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Category category = (Category) o; + return Objects.equals(title, category.title); + } + + @Override + public int hashCode() { + return Objects.hash(title); + } +} diff --git a/src/main/java/dev/biswajit/ecomm/productservice/model/Currency.java b/src/main/java/dev/biswajit/ecomm/productservice/model/Currency.java new file mode 100644 index 0000000..68246c3 --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/model/Currency.java @@ -0,0 +1,6 @@ +package dev.biswajit.ecomm.productservice.model; + +public enum Currency { + RUPEE, + DOLLAR +} diff --git a/src/main/java/dev/biswajit/ecomm/productservice/model/Price.java b/src/main/java/dev/biswajit/ecomm/productservice/model/Price.java new file mode 100644 index 0000000..ba8cc40 --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/model/Price.java @@ -0,0 +1,42 @@ +package dev.biswajit.ecomm.productservice.model; + +import jakarta.persistence.*; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.Objects; +import java.util.UUID; + +@Data +@NoArgsConstructor +@Entity +@Table(name = "PRICES") +public class Price { + @Id + @GeneratedValue(strategy = GenerationType.UUID) + private UUID id; + + private Double value; + + @Enumerated(value = EnumType.STRING) + private Currency currency; + + public Price(Double value, Currency currency) { + this.value = value; + this.currency = currency; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Price price = (Price) o; + return Objects.equals(value, price.value) && currency == price.currency; + } + + @Override + public int hashCode() { + return Objects.hash(value, currency); + } +} + diff --git a/src/main/java/dev/biswajit/ecomm/productservice/model/Product.java b/src/main/java/dev/biswajit/ecomm/productservice/model/Product.java new file mode 100644 index 0000000..c8b3125 --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/model/Product.java @@ -0,0 +1,42 @@ +package dev.biswajit.ecomm.productservice.model; + +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.BatchSize; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; + +@AllArgsConstructor +@NoArgsConstructor +@Data +@Entity +@Table(name = "PRODUCTS") +public class Product { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String name; + + @ManyToOne(cascade = {CascadeType.PERSIST}, fetch = FetchType.LAZY) + @JoinColumn(name = "category_id", referencedColumnName = "id") + private Category category; + + @OneToOne(cascade = {CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE}, + fetch = FetchType.LAZY, optional = false) + @JoinColumn(name = "price_id", referencedColumnName = "id") + @BatchSize(size = 10) + @Fetch(FetchMode.SELECT) + private Price price; + + private String image; + + public Product(String title, Category category, Price price, String imageUrl) { + this.name = title; + this.category = category; + this.price = price; + this.image = imageUrl; + } +} diff --git a/src/main/java/dev/biswajit/ecomm/productservice/repository/CategoryRepository.java b/src/main/java/dev/biswajit/ecomm/productservice/repository/CategoryRepository.java new file mode 100644 index 0000000..fc520ad --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/repository/CategoryRepository.java @@ -0,0 +1,14 @@ +package dev.biswajit.ecomm.productservice.repository; + +import dev.biswajit.ecomm.productservice.model.Category; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.Optional; + +public interface CategoryRepository extends JpaRepository { + @Query("select c from Category c where lower(c.title) like lower(concat('%', :title, '%') ) ") + Optional findByTitle(@Param("title") String title); + +} diff --git a/src/main/java/dev/biswajit/ecomm/productservice/repository/PriceRepository.java b/src/main/java/dev/biswajit/ecomm/productservice/repository/PriceRepository.java new file mode 100644 index 0000000..ecd1bc8 --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/repository/PriceRepository.java @@ -0,0 +1,13 @@ +package dev.biswajit.ecomm.productservice.repository; + +import dev.biswajit.ecomm.productservice.model.Price; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import java.util.Optional; +import java.util.UUID; + +public interface PriceRepository extends JpaRepository { + @Query("SELECT p FROM Price p where abs(p.value-0.01) <= :price and abs(p.value+0.01) >= :price") + Optional findByPriceValue(double price); +} diff --git a/src/main/java/dev/biswajit/ecomm/productservice/repository/ProductRepository.java b/src/main/java/dev/biswajit/ecomm/productservice/repository/ProductRepository.java new file mode 100644 index 0000000..271cd5f --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/repository/ProductRepository.java @@ -0,0 +1,23 @@ +package dev.biswajit.ecomm.productservice.repository; + +import dev.biswajit.ecomm.productservice.model.Product; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Primary +@Repository(value = "PRODUCT_REPOSITORY") +public interface ProductRepository extends JpaRepository { + +// Mono findProductById(Long id); + + @Query("select p from Product p join fetch p.category c join fetch p.price pr where c.title=:title") + List findProductsByCategory(@Param("title") String title); + + @Query("select p from Product p join fetch p.category c join fetch p.price pr") + List findAllProducts(); +} diff --git a/src/main/java/dev/biswajit/ecomm/productservice/service/CategoryService.java b/src/main/java/dev/biswajit/ecomm/productservice/service/CategoryService.java new file mode 100644 index 0000000..7baf454 --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/service/CategoryService.java @@ -0,0 +1,13 @@ +package dev.biswajit.ecomm.productservice.service; + +import dev.biswajit.ecomm.productservice.dto.ProductDto; +import dev.biswajit.ecomm.productservice.model.Category; +import reactor.core.publisher.Mono; + +import java.util.List; + +public interface CategoryService { + Mono> allCategories(); + + Mono> findProductsByCategory(String category); +} diff --git a/src/main/java/dev/biswajit/ecomm/productservice/service/CategoryServiceImpl.java b/src/main/java/dev/biswajit/ecomm/productservice/service/CategoryServiceImpl.java new file mode 100644 index 0000000..f21bddb --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/service/CategoryServiceImpl.java @@ -0,0 +1,50 @@ +package dev.biswajit.ecomm.productservice.service; + +import dev.biswajit.ecomm.productservice.dto.ProductDto; +import dev.biswajit.ecomm.productservice.model.Category; +import dev.biswajit.ecomm.productservice.model.Product; +import dev.biswajit.ecomm.productservice.repository.CategoryRepository; +import dev.biswajit.ecomm.productservice.repository.ProductRepository; +import jakarta.transaction.Transactional; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; + +import java.util.List; +import java.util.Objects; + +@Service +public class CategoryServiceImpl implements CategoryService{ + + private final CategoryRepository categoryRepository; + private final ProductRepository productRepository; + + public CategoryServiceImpl(CategoryRepository categoryRepository, + ProductRepository productRepository) { + this.categoryRepository = categoryRepository; + this.productRepository = productRepository; + } + + @Override + public Mono> allCategories() { + return Mono.just(categoryRepository.findAll() + .stream() + .filter(category -> Objects.nonNull(category.getTitle())).toList()); + } + + @Override + public Mono> findProductsByCategory(String title) { + List productsByCategory = productRepository.findProductsByCategory(title); + + List productDtoList = productsByCategory + .stream() + .map(product -> ProductDto.builder() + .id(product.getId()) + .title(product.getName()) + .category(product.getCategory().getTitle()) + .price(product.getPrice().getValue().toString()) + .imageUrl(product.getImage()) + .build()) + .toList(); + return Mono.just(productDtoList); + } +} diff --git a/src/main/java/dev/biswajit/ecomm/productservice/service/FakeStoreProductService.java b/src/main/java/dev/biswajit/ecomm/productservice/service/FakeStoreProductService.java new file mode 100644 index 0000000..2beb5b7 --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/service/FakeStoreProductService.java @@ -0,0 +1,75 @@ +package dev.biswajit.ecomm.productservice.service; + +import dev.biswajit.ecomm.productservice.thirdparty.FakeStoreClient; +import dev.biswajit.ecomm.productservice.thirdparty.ThirdPartyProductDto; +import dev.biswajit.ecomm.productservice.dto.ProductDto; +import dev.biswajit.ecomm.productservice.exception.ProductNotFoundException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.stereotype.Service; +import org.springframework.web.reactive.function.BodyInserters; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +import java.util.List; + +@Service("FAKE_STORE_SERVICE") +@ConditionalOnProperty(name = "app.service.type", havingValue = "FAKE_STORE_SERVICE") +public class FakeStoreProductService implements ProductService { + + private FakeStoreClient fakeStoreClient; + + public FakeStoreProductService(FakeStoreClient fakeStoreClient) { + this.fakeStoreClient = fakeStoreClient; + } + + @Override + public Mono productBy(Long id) { + return fakeStoreClient.getProductBy(id) + .switchIfEmpty(Mono.error(ProductNotFoundException.with("no product with id " + id + " found"))) + .map(product -> + new ProductDto(product.getId(), product.getTitle(), product.getPrice(), product.getCategory(), + product.getDescription(), product.getImageUrl())) + .log(); + } + + @Override + public Mono> allProducts() { + return fakeStoreClient.getAllProducts() + .flatMap(list -> { + List products = list.stream().map(it -> new ProductDto(it.getId(), it.getTitle(), it.getPrice(), it.getCategory(), + it.getDescription(), it.getImageUrl() + )).toList(); + return Mono.just(products); + }); + } + + @Override + public Mono add(ProductDto newProduct) { + + return fakeStoreClient.add(newProduct) + .map(it -> + new ProductDto(it.getId(), it.getTitle(), it.getPrice(), it.getCategory(), it.getDescription(), + it.getImageUrl())).log(); + } + + @Override + public Mono deleteBy(Long id) { + + return fakeStoreClient.deleteBy(id) + .map(it -> + new ProductDto(it.getId(), it.getTitle(), it.getPrice(), it.getCategory(), it.getDescription(), + it.getImageUrl())).log(); + } + + @Override + public Mono updateBy(Long id, ProductDto updateProductDto) { + + return fakeStoreClient.updateBy(id, updateProductDto) + .map(it -> + new ProductDto(it.getId(), it.getTitle(), it.getPrice(), it.getCategory(), + it.getDescription(), it.getImageUrl())).log(); + } +} diff --git a/src/main/java/dev/biswajit/ecomm/productservice/service/ProductService.java b/src/main/java/dev/biswajit/ecomm/productservice/service/ProductService.java new file mode 100644 index 0000000..aa94bce --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/service/ProductService.java @@ -0,0 +1,21 @@ +package dev.biswajit.ecomm.productservice.service; + +import dev.biswajit.ecomm.productservice.dto.ProductDto; +import dev.biswajit.ecomm.productservice.exception.ProductNotFoundException; +import reactor.core.publisher.Mono; + +import java.util.List; +import java.util.UUID; + +public interface ProductService { + Mono productBy(Long id) throws ProductNotFoundException; + + Mono> allProducts(); + + Mono add(ProductDto newProduct); + + Mono deleteBy(Long id) throws ProductNotFoundException; + + Mono updateBy(Long id, ProductDto updateProductDto) throws ProductNotFoundException; + +} diff --git a/src/main/java/dev/biswajit/ecomm/productservice/service/SelfManagedProductService.java b/src/main/java/dev/biswajit/ecomm/productservice/service/SelfManagedProductService.java new file mode 100644 index 0000000..7ce0942 --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/service/SelfManagedProductService.java @@ -0,0 +1,115 @@ +package dev.biswajit.ecomm.productservice.service; + +import dev.biswajit.ecomm.productservice.dto.ProductDto; +import dev.biswajit.ecomm.productservice.exception.ProductNotFoundException; +import dev.biswajit.ecomm.productservice.model.Category; +import dev.biswajit.ecomm.productservice.model.Currency; +import dev.biswajit.ecomm.productservice.model.Price; +import dev.biswajit.ecomm.productservice.model.Product; +import dev.biswajit.ecomm.productservice.repository.CategoryRepository; +import dev.biswajit.ecomm.productservice.repository.PriceRepository; +import dev.biswajit.ecomm.productservice.repository.ProductRepository; +import jakarta.transaction.Transactional; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; + +import java.util.List; +import java.util.Optional; + +@Primary +@Service("SELF_STORE_SERVICE") +@ConditionalOnProperty(name = "app.service.type", havingValue = "SELF_STORE_SERVICE") +public class SelfManagedProductService implements ProductService{ + private final ProductRepository productRepository; + private final CategoryRepository categoryRepository; + private final PriceRepository priceRepository; + + @Autowired + public SelfManagedProductService(@Autowired ProductRepository productRepository, + CategoryRepository categoryRepository, PriceRepository priceRepository) { + this.productRepository = productRepository; + this.categoryRepository = categoryRepository; + this.priceRepository = priceRepository; + } + + @Override + @Transactional + public Mono productBy(Long id) throws ProductNotFoundException { + +// has N+1 query issue since each call to a product will fetch category and price details + Product productFound = productRepository.findById(id) + .orElseThrow(() -> ProductNotFoundException.with(String.format("Product with %d not found", id))); + ProductDto productDto = new ProductDto(productFound.getId(), productFound.getName(), productFound.getPrice().getValue().toString(), + productFound.getCategory().getTitle(), productFound.getName(), productFound.getImage()); + + return Mono.just(productDto); + + } + + @Override + public Mono> allProducts() { + + return Mono.just(productRepository.findAllProducts() + .stream() + .map(productFound -> new ProductDto(productFound.getId(), productFound.getName(), productFound.getPrice().getValue().toString(), + productFound.getCategory().getTitle(), productFound.getName(), productFound.getImage())) + .toList()); + } + + @Override + @Transactional + public Mono add(ProductDto newProduct) { + Category categoryToBeSaved = categoryRepository.findByTitle(newProduct.getCategory()) + .orElse(new Category(newProduct.getCategory())); + Price price = new Price(Double.parseDouble(newProduct.getPrice()), Currency.RUPEE); + + Product product = new Product(newProduct.getTitle(), + categoryToBeSaved, price, newProduct.getImageUrl()); + + Product savedProduct = productRepository.save(product); + + return Mono.just( + new ProductDto(savedProduct.getId(), savedProduct.getName(), savedProduct.getPrice().getValue().toString(), + savedProduct.getCategory().getTitle(), savedProduct.getName(), savedProduct.getImage()) + ); + } + + @Override + @Transactional + public Mono deleteBy(Long id) throws ProductNotFoundException { + + Mono productDto = productBy(id); + + productRepository.deleteById(id); + + return productDto; + } + + @Override + @Transactional + public Mono updateBy(Long id, ProductDto updateProductDto) throws ProductNotFoundException { + Mono productDto = productBy(id); + + Category category = categoryRepository.findByTitle(updateProductDto.getTitle()) + .orElse(new Category(updateProductDto.getCategory())); + + Price price = priceRepository.findByPriceValue(Double.parseDouble(updateProductDto.getPrice())) + .orElse(new Price(Double.parseDouble(updateProductDto.getPrice()), Currency.RUPEE)); + + Mono updatedProduct = productDto.map(productToBeSaved -> + new Product(productToBeSaved.getId(), + updateProductDto.getTitle(), + category, + price, + updateProductDto.getImageUrl())) + .map(productRepository::save); + + return updatedProduct.map(product -> + new ProductDto(product.getId(), product.getName(), product.getPrice().getValue().toString(), + product.getCategory().getTitle(), product.getName(), product.getImage())); + } + +} diff --git a/src/main/java/dev/biswajit/ecomm/productservice/thirdparty/FakeStoreClient.java b/src/main/java/dev/biswajit/ecomm/productservice/thirdparty/FakeStoreClient.java new file mode 100644 index 0000000..99077f3 --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/thirdparty/FakeStoreClient.java @@ -0,0 +1,70 @@ +package dev.biswajit.ecomm.productservice.thirdparty; + +import dev.biswajit.ecomm.productservice.dto.ProductDto; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.BodyInserters; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + +import java.util.List; + +@Component +public class FakeStoreClient { + private final WebClient webclient; + + public FakeStoreClient(@Autowired WebClient.Builder builder, @Value("${app.fakestore.url}") String baseUrl) { + this.webclient = builder.baseUrl(baseUrl).build(); + } + + public Mono getProductBy(Long id) { + return webclient + .get() + .uri("/products/{id}", id) + .retrieve() + .bodyToMono(ThirdPartyProductDto.class) + .log(); + } + + public Mono> getAllProducts() { + return webclient + .get() + .uri("/products") + .retrieve() + .bodyToMono(new ParameterizedTypeReference>() { + }) + .log(); + } + + public Mono add(ProductDto newProduct) { + return webclient + .post() + .uri("/products") + .body(BodyInserters.fromValue(newProduct)) + .retrieve() + .bodyToMono(ThirdPartyProductDto.class) + .log(); + } + + // todo - refactor to pass third party product dto instead of ProductDto + public Mono updateBy(Long id, ProductDto updateProductDto) { + return webclient + .put() + .uri("/products/{id}", id) + .body(BodyInserters.fromValue(updateProductDto)) + .retrieve() + .bodyToMono(ThirdPartyProductDto.class) + .log(); + } + + public Mono deleteBy(Long id) { + return webclient + .delete() + .uri("/products/{id}", id) + .retrieve() + .bodyToMono(ThirdPartyProductDto.class) + .log(); + } +} diff --git a/src/main/java/dev/biswajit/ecomm/productservice/thirdparty/ThirdPartyProductDto.java b/src/main/java/dev/biswajit/ecomm/productservice/thirdparty/ThirdPartyProductDto.java new file mode 100644 index 0000000..2310c7a --- /dev/null +++ b/src/main/java/dev/biswajit/ecomm/productservice/thirdparty/ThirdPartyProductDto.java @@ -0,0 +1,18 @@ +package dev.biswajit.ecomm.productservice.thirdparty; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.*; + +@NoArgsConstructor +@Getter +@Setter +@JsonIgnoreProperties(ignoreUnknown = true) +@Data +public class ThirdPartyProductDto { + private Long id; + private String title; + private String price; + private String category; + private String description; + private String imageUrl; +} diff --git a/src/main/java/dev/naman/productservice/ProductserviceApplication.java b/src/main/java/dev/naman/productservice/ProductserviceApplication.java deleted file mode 100644 index 1620741..0000000 --- a/src/main/java/dev/naman/productservice/ProductserviceApplication.java +++ /dev/null @@ -1,119 +0,0 @@ -package dev.naman.productservice; - -import dev.naman.productservice.inheritancedemo.joinedtable.Mentor; -import dev.naman.productservice.inheritancedemo.joinedtable.MentorRepository; -import dev.naman.productservice.inheritancedemo.joinedtable.User; -import dev.naman.productservice.inheritancedemo.joinedtable.UserRepository; -import dev.naman.productservice.models.Category; -import dev.naman.productservice.models.Price; -import dev.naman.productservice.models.Product; -import dev.naman.productservice.repositories.CategoryRepository; -import dev.naman.productservice.repositories.PriceRepository; -import dev.naman.productservice.repositories.ProductRepository; -import jakarta.transaction.Transactional; -import org.hibernate.Hibernate; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -import java.util.List; -import java.util.Optional; -import java.util.UUID; - -@SpringBootApplication -public class ProductserviceApplication {// implements CommandLineRunner { - -// private MentorRepository mentorRepository; -// -// -// private UserRepository userRepository; -// private final ProductRepository productRepository; -// private final CategoryRepository categoryRepository; -// private final PriceRepository priceRepository; -// -// public ProductserviceApplication(@Qualifier("jt_mr") MentorRepository mentorRepository, -// @Qualifier("jt_ur") UserRepository userRepository, -// ProductRepository productRepository, -// CategoryRepository categoryRepository, -// PriceRepository priceRepository) { -// this.mentorRepository = mentorRepository; -// this.userRepository = userRepository; -// this.productRepository = productRepository; -// this.categoryRepository = categoryRepository; -// this.priceRepository = priceRepository; -// } - - public static void main(String[] args) { - SpringApplication.run(ProductserviceApplication.class, args); - } - -// @Transactional() -// @Override -// public void run(String... args) throws Exception { -//// Mentor mentor = new Mentor(); -//// mentor.setName("Naman"); -//// mentor.setEmail("Naman@scaler.com"); -//// mentor.setAverageRating(4.65); -//// mentorRepository.save(mentor); -//// -//// User user = new User(); -//// user.setName("Sarath"); -//// user.setEmail("sarathcool@yopmail.com"); -//// userRepository.save(user); -//// -//// List users = userRepository.findAll(); -//// for (User user1: users) { -//// System.out.println(user1); -//// } -// -// Category category = new Category(); -// category.setName("Apple Devices"); -//// Category savedCategory = categoryRepository.save(category); -// -// Price price = new Price("Rupee", 10); -//// Price savedPrice = priceRepository.save(price); -// -// Product product = new Product(); -// product.setTitle("iPhone 15 Pro"); -// product.setDescription("The best iPhone Ever"); -// product.setCategory(category); -// product.setPrice(price); -// -// productRepository.save(product); -// -// productRepository.deleteById(UUID.fromString("95672ed6-3127-4248-ae33-97a261c0a6f4")); -// -// System.out.println(productRepository.countAllByPrice_Currency("Rupee")); -// List products = productRepository.findAllByPrice_Currency("Rupee"); -//// Category category1 = categoryRepository.findById(UUID.fromString("5e6f679e-f326-44ae-b220-544b3822ab00")).get(); -//// System.out.println("Category name is: " + category1.getName()); -//// System.out.println("Printing all products in the category"); -////// Thread.sleep(1000); -//// -//// System.out.println(category1.getProducts().size()); -//// category1.getProducts().forEach( -//// product1 -> System.out.println(product1.getTitle()) -//// ); -//// -//// for (Product product1: category1.getProducts()) { -//// try { -//// System.out.println(product1.getTitle()); -//// } catch (Exception e) { -//// System.out.println(e.getMessage()); -//// } -//// } -// -// List products1 = productRepository.findAllByTitle("iPhone 15 Pro"); -// -// System.out.println("Fetching category b8f1f459-f9e9-4d3d-b115-f1f5267bd54f"); -// Thread.sleep(1000); -// Category category1 = categoryRepository.findById(UUID.fromString("b8f1f459-f9e9-4d3d-b115-f1f5267bd54f")).get(); -//// Category category1 = category1Optional.get(); -// -// System.out.println("Fetching products for category"); -// Thread.sleep(1000); -// List products11 = category1.getProducts(); -// } - -} diff --git a/src/main/java/dev/naman/productservice/controllers/CategoryController.java b/src/main/java/dev/naman/productservice/controllers/CategoryController.java deleted file mode 100644 index be875bb..0000000 --- a/src/main/java/dev/naman/productservice/controllers/CategoryController.java +++ /dev/null @@ -1,49 +0,0 @@ -package dev.naman.productservice.controllers; - -import dev.naman.productservice.dtos.GetProductTitlesRequestDto; -import dev.naman.productservice.dtos.ProductDto; -import dev.naman.productservice.models.Category; -import dev.naman.productservice.models.Product; -import dev.naman.productservice.services.CategoryService; -import org.springframework.web.bind.annotation.*; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -@RestController -@RequestMapping("/categories") -public class CategoryController { - private CategoryService categoryService; - - public CategoryController(CategoryService categoryService) { - this.categoryService = categoryService; - } - - @GetMapping("/{uuid}") - public List getCategory(@PathVariable("uuid") String uuid) { - List products = categoryService.getCategory(uuid).getProducts(); - - List productDtos = new ArrayList<>(); - - for (Product product: products) { - ProductDto productDto = new ProductDto(); - productDto.setDescription(product.getDescription()); - productDto.setTitle(product.getTitle()); - productDto.setImage(product.getImage()); - productDto.setPrice(product.getPrice()); - productDtos.add(productDto); -// productDto.se - } - - return productDtos; - } - - @GetMapping("/titles/") - public List getProductTitles(@RequestBody GetProductTitlesRequestDto requestDto) { - - List uuids = requestDto.getUuids(); - - return categoryService.getProductTitles(uuids); - } -} diff --git a/src/main/java/dev/naman/productservice/controllers/ProductController.java b/src/main/java/dev/naman/productservice/controllers/ProductController.java deleted file mode 100644 index 2602c25..0000000 --- a/src/main/java/dev/naman/productservice/controllers/ProductController.java +++ /dev/null @@ -1,73 +0,0 @@ -package dev.naman.productservice.controllers; - -import dev.naman.productservice.dtos.ExceptionDto; -import dev.naman.productservice.dtos.GenericProductDto; -import dev.naman.productservice.exceptions.NotFoundException; -import dev.naman.productservice.services.ProductService; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@RestController -@RequestMapping("/products") -public class ProductController { -// @Autowired - // field injection - private ProductService productService; - // ....; - // ...; - - - - // constructor injection -// @Autowired - public ProductController(ProductService productService) { - this.productService = productService; - } -// - - // setter injection -// @Autowired -// public void setProductService(ProductService productService) { -// this.productService = productService; -// } - - // GET /products {} - @GetMapping - public List getAllProducts() { - return productService.getAllProducts(); - } - - // localhost:8080/products/{id} - // localhost:8080/products/123 - @GetMapping("{id}") - public GenericProductDto getProductById(@PathVariable("id") Long id) throws NotFoundException { - GenericProductDto productDto = productService.getProductById(id); - if (productDto == null) { - // throw NotFoundException - } - return productDto; - } - - @DeleteMapping("{id}") - public ResponseEntity deleteProductById(@PathVariable("id") Long id) { - return new ResponseEntity<>( - productService.deleteProduct(id), - HttpStatus.OK - ); - } - - @PostMapping - public GenericProductDto createProduct(@RequestBody GenericProductDto product) { -// System.out.println(product.name); - return productService.createProduct(product); - } - - @PutMapping("{id}") - public void updateProductById() { - - } -} diff --git a/src/main/java/dev/naman/productservice/dtos/CategoryDto.java b/src/main/java/dev/naman/productservice/dtos/CategoryDto.java deleted file mode 100644 index fabb541..0000000 --- a/src/main/java/dev/naman/productservice/dtos/CategoryDto.java +++ /dev/null @@ -1,14 +0,0 @@ -package dev.naman.productservice.dtos; - -import lombok.Getter; -import lombok.Setter; - -import java.util.List; - -@Getter -@Setter -public class CategoryDto { - private String name; - - private List products; -} diff --git a/src/main/java/dev/naman/productservice/dtos/ExceptionDto.java b/src/main/java/dev/naman/productservice/dtos/ExceptionDto.java deleted file mode 100644 index 8fe5a05..0000000 --- a/src/main/java/dev/naman/productservice/dtos/ExceptionDto.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.naman.productservice.dtos; - -import lombok.Getter; -import lombok.Setter; -import org.springframework.http.HttpStatus; - -@Getter -@Setter -public class ExceptionDto { - private HttpStatus errorCode; - private String message; - - public ExceptionDto(HttpStatus status, String message) { - this.errorCode = status; - this.message = message; - } -} diff --git a/src/main/java/dev/naman/productservice/dtos/GenericProductDto.java b/src/main/java/dev/naman/productservice/dtos/GenericProductDto.java deleted file mode 100644 index ea81d6c..0000000 --- a/src/main/java/dev/naman/productservice/dtos/GenericProductDto.java +++ /dev/null @@ -1,16 +0,0 @@ -package dev.naman.productservice.dtos; - -import dev.naman.productservice.models.Category; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class GenericProductDto { - private Long id; - private String title; - private String description; - private String image; - private String category; - private double price; -} diff --git a/src/main/java/dev/naman/productservice/dtos/GetProductTitlesRequestDto.java b/src/main/java/dev/naman/productservice/dtos/GetProductTitlesRequestDto.java deleted file mode 100644 index bb61e86..0000000 --- a/src/main/java/dev/naman/productservice/dtos/GetProductTitlesRequestDto.java +++ /dev/null @@ -1,12 +0,0 @@ -package dev.naman.productservice.dtos; - -import lombok.Getter; -import lombok.Setter; - -import java.util.List; - -@Getter -@Setter -public class GetProductTitlesRequestDto { - private List uuids; -} diff --git a/src/main/java/dev/naman/productservice/dtos/ProductDto.java b/src/main/java/dev/naman/productservice/dtos/ProductDto.java deleted file mode 100644 index 9f2d39f..0000000 --- a/src/main/java/dev/naman/productservice/dtos/ProductDto.java +++ /dev/null @@ -1,25 +0,0 @@ -package dev.naman.productservice.dtos; - -import dev.naman.productservice.models.Category; -import dev.naman.productservice.models.Price; -import jakarta.persistence.CascadeType; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import jakarta.persistence.OneToOne; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class ProductDto { - private String title; - - private String description; - - private String image; - // P : C - // => L to R: 1 : 1 - // => R to L: m : 1 - // => Ans: m : 1 - private Price price; -} diff --git a/src/main/java/dev/naman/productservice/exceptions/ControllerAdvices.java b/src/main/java/dev/naman/productservice/exceptions/ControllerAdvices.java deleted file mode 100644 index a1c2361..0000000 --- a/src/main/java/dev/naman/productservice/exceptions/ControllerAdvices.java +++ /dev/null @@ -1,32 +0,0 @@ -package dev.naman.productservice.exceptions; - -import dev.naman.productservice.dtos.ExceptionDto; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; - -@ControllerAdvice -public class ControllerAdvices { -// @ExceptionHandler(NotFoundException.class) -// private ResponseEntity handleNotFoundException( -// NotFoundException notFoundException -// ) { -// -// return new ResponseEntity( -// new ExceptionDto(HttpStatus.NOT_FOUND, notFoundException.getMessage()), -// HttpStatus.NOT_FOUND -// ); -// } -// -// @ExceptionHandler(ArrayIndexOutOfBoundsException.class) -// private ResponseEntity handleArrayIndexOutOfBound( -// ArrayIndexOutOfBoundsException notFoundException -// ) { -// -// return new ResponseEntity( -// new ExceptionDto(HttpStatus.NOT_FOUND, notFoundException.getMessage()), -// HttpStatus.NOT_FOUND -// ); -// } -} diff --git a/src/main/java/dev/naman/productservice/exceptions/NotFoundException.java b/src/main/java/dev/naman/productservice/exceptions/NotFoundException.java deleted file mode 100644 index 0986b0e..0000000 --- a/src/main/java/dev/naman/productservice/exceptions/NotFoundException.java +++ /dev/null @@ -1,12 +0,0 @@ -package dev.naman.productservice.exceptions; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -@ResponseStatus(value = HttpStatus.NOT_FOUND) -public class NotFoundException extends Exception { - - public NotFoundException(String message) { - super(message); - } -} diff --git a/src/main/java/dev/naman/productservice/inheritancedemo/joinedtable/Mentor.java b/src/main/java/dev/naman/productservice/inheritancedemo/joinedtable/Mentor.java deleted file mode 100644 index 2e06842..0000000 --- a/src/main/java/dev/naman/productservice/inheritancedemo/joinedtable/Mentor.java +++ /dev/null @@ -1,14 +0,0 @@ -package dev.naman.productservice.inheritancedemo.joinedtable; - -import jakarta.persistence.Entity; -import jakarta.persistence.PrimaryKeyJoinColumn; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@Entity(name = "jt_mentor") -@PrimaryKeyJoinColumn(name = "user_id") -public class Mentor extends User { - private double averageRating; -} diff --git a/src/main/java/dev/naman/productservice/inheritancedemo/joinedtable/MentorRepository.java b/src/main/java/dev/naman/productservice/inheritancedemo/joinedtable/MentorRepository.java deleted file mode 100644 index 567c201..0000000 --- a/src/main/java/dev/naman/productservice/inheritancedemo/joinedtable/MentorRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package dev.naman.productservice.inheritancedemo.joinedtable; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository("jt_mr") -public interface MentorRepository -extends JpaRepository { - @Override - S save(S entity); -} diff --git a/src/main/java/dev/naman/productservice/inheritancedemo/joinedtable/Student.java b/src/main/java/dev/naman/productservice/inheritancedemo/joinedtable/Student.java deleted file mode 100644 index d327d8f..0000000 --- a/src/main/java/dev/naman/productservice/inheritancedemo/joinedtable/Student.java +++ /dev/null @@ -1,15 +0,0 @@ -package dev.naman.productservice.inheritancedemo.joinedtable; - -import jakarta.persistence.Entity; -import jakarta.persistence.PrimaryKeyJoinColumn; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@Entity(name = "jt_student") -@PrimaryKeyJoinColumn(name = "user_id") -public class Student extends User { - private double psp; - private double attendance; -} diff --git a/src/main/java/dev/naman/productservice/inheritancedemo/joinedtable/TA.java b/src/main/java/dev/naman/productservice/inheritancedemo/joinedtable/TA.java deleted file mode 100644 index 7e34534..0000000 --- a/src/main/java/dev/naman/productservice/inheritancedemo/joinedtable/TA.java +++ /dev/null @@ -1,14 +0,0 @@ -package dev.naman.productservice.inheritancedemo.joinedtable; - -import jakarta.persistence.Entity; -import jakarta.persistence.PrimaryKeyJoinColumn; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@Entity(name = "jt_ta") -@PrimaryKeyJoinColumn(name = "user_id") -public class TA extends User { - private double averageRating; -} diff --git a/src/main/java/dev/naman/productservice/inheritancedemo/joinedtable/User.java b/src/main/java/dev/naman/productservice/inheritancedemo/joinedtable/User.java deleted file mode 100644 index 5c1e921..0000000 --- a/src/main/java/dev/naman/productservice/inheritancedemo/joinedtable/User.java +++ /dev/null @@ -1,19 +0,0 @@ -package dev.naman.productservice.inheritancedemo.joinedtable; - -import jakarta.persistence.*; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -@Getter -@Setter -@ToString -@Entity(name = "jt_user") -@Inheritance(strategy = InheritanceType.JOINED) -public class User { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - private String name; - private String email; -} diff --git a/src/main/java/dev/naman/productservice/inheritancedemo/joinedtable/UserRepository.java b/src/main/java/dev/naman/productservice/inheritancedemo/joinedtable/UserRepository.java deleted file mode 100644 index 581462b..0000000 --- a/src/main/java/dev/naman/productservice/inheritancedemo/joinedtable/UserRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -package dev.naman.productservice.inheritancedemo.joinedtable; - -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository("jt_ur") -public interface UserRepository -extends JpaRepository { - - @Override - S save(S entity); -} diff --git a/src/main/java/dev/naman/productservice/inheritancedemo/mappedsuperclass/Mentor.java b/src/main/java/dev/naman/productservice/inheritancedemo/mappedsuperclass/Mentor.java deleted file mode 100644 index 0a08459..0000000 --- a/src/main/java/dev/naman/productservice/inheritancedemo/mappedsuperclass/Mentor.java +++ /dev/null @@ -1,12 +0,0 @@ -package dev.naman.productservice.inheritancedemo.mappedsuperclass; - -import jakarta.persistence.Entity; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@Entity(name = "ms_mentor") -public class Mentor extends User { - private double averageRating; -} diff --git a/src/main/java/dev/naman/productservice/inheritancedemo/mappedsuperclass/Student.java b/src/main/java/dev/naman/productservice/inheritancedemo/mappedsuperclass/Student.java deleted file mode 100644 index a7b2989..0000000 --- a/src/main/java/dev/naman/productservice/inheritancedemo/mappedsuperclass/Student.java +++ /dev/null @@ -1,13 +0,0 @@ -package dev.naman.productservice.inheritancedemo.mappedsuperclass; - -import jakarta.persistence.Entity; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@Entity(name = "ms_student") -public class Student extends User { - private double psp; - private double attendance; -} diff --git a/src/main/java/dev/naman/productservice/inheritancedemo/mappedsuperclass/TA.java b/src/main/java/dev/naman/productservice/inheritancedemo/mappedsuperclass/TA.java deleted file mode 100644 index 735d058..0000000 --- a/src/main/java/dev/naman/productservice/inheritancedemo/mappedsuperclass/TA.java +++ /dev/null @@ -1,12 +0,0 @@ -package dev.naman.productservice.inheritancedemo.mappedsuperclass; - -import jakarta.persistence.Entity; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@Entity(name = "ms_ta") -public class TA extends User { - private double averageRating; -} diff --git a/src/main/java/dev/naman/productservice/inheritancedemo/mappedsuperclass/User.java b/src/main/java/dev/naman/productservice/inheritancedemo/mappedsuperclass/User.java deleted file mode 100644 index bd1bdfb..0000000 --- a/src/main/java/dev/naman/productservice/inheritancedemo/mappedsuperclass/User.java +++ /dev/null @@ -1,19 +0,0 @@ -package dev.naman.productservice.inheritancedemo.mappedsuperclass; - -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; -import jakarta.persistence.MappedSuperclass; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@MappedSuperclass -public class User { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - private String name; - private String email; -} diff --git a/src/main/java/dev/naman/productservice/inheritancedemo/singletable/Mentor.java b/src/main/java/dev/naman/productservice/inheritancedemo/singletable/Mentor.java deleted file mode 100644 index 20424a3..0000000 --- a/src/main/java/dev/naman/productservice/inheritancedemo/singletable/Mentor.java +++ /dev/null @@ -1,14 +0,0 @@ -package dev.naman.productservice.inheritancedemo.singletable; - -import jakarta.persistence.DiscriminatorValue; -import jakarta.persistence.Entity; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@Entity(name = "st_mentor") -@DiscriminatorValue(value = "3") -public class Mentor extends User { - private double averageRating; -} diff --git a/src/main/java/dev/naman/productservice/inheritancedemo/singletable/MentorRepository.java b/src/main/java/dev/naman/productservice/inheritancedemo/singletable/MentorRepository.java deleted file mode 100644 index 1402125..0000000 --- a/src/main/java/dev/naman/productservice/inheritancedemo/singletable/MentorRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -package dev.naman.productservice.inheritancedemo.singletable; - -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository("st_mr") -public interface MentorRepository -extends JpaRepository { - @Override - S save(S entity); -} diff --git a/src/main/java/dev/naman/productservice/inheritancedemo/singletable/Student.java b/src/main/java/dev/naman/productservice/inheritancedemo/singletable/Student.java deleted file mode 100644 index f711c1b..0000000 --- a/src/main/java/dev/naman/productservice/inheritancedemo/singletable/Student.java +++ /dev/null @@ -1,15 +0,0 @@ -package dev.naman.productservice.inheritancedemo.singletable; - -import jakarta.persistence.DiscriminatorValue; -import jakarta.persistence.Entity; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@Entity(name = "st_student") -@DiscriminatorValue(value = "1") -public class Student extends User { - private double psp; - private double attendance; -} diff --git a/src/main/java/dev/naman/productservice/inheritancedemo/singletable/TA.java b/src/main/java/dev/naman/productservice/inheritancedemo/singletable/TA.java deleted file mode 100644 index 6950eaa..0000000 --- a/src/main/java/dev/naman/productservice/inheritancedemo/singletable/TA.java +++ /dev/null @@ -1,14 +0,0 @@ -package dev.naman.productservice.inheritancedemo.singletable; - -import jakarta.persistence.DiscriminatorValue; -import jakarta.persistence.Entity; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@Entity(name = "st_ta") -@DiscriminatorValue(value = "2") -public class TA extends User { - private double averageRating; -} diff --git a/src/main/java/dev/naman/productservice/inheritancedemo/singletable/User.java b/src/main/java/dev/naman/productservice/inheritancedemo/singletable/User.java deleted file mode 100644 index d596463..0000000 --- a/src/main/java/dev/naman/productservice/inheritancedemo/singletable/User.java +++ /dev/null @@ -1,22 +0,0 @@ -package dev.naman.productservice.inheritancedemo.singletable; - -import jakarta.persistence.*; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@Entity(name = "st_user") -@Inheritance(strategy = InheritanceType.SINGLE_TABLE) -@DiscriminatorColumn( - name = "userType", - discriminatorType = DiscriminatorType.INTEGER -) -@DiscriminatorValue(value = "0") -public class User { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - private String name; - private String email; -} diff --git a/src/main/java/dev/naman/productservice/inheritancedemo/singletable/UserRepository.java b/src/main/java/dev/naman/productservice/inheritancedemo/singletable/UserRepository.java deleted file mode 100644 index cd4604e..0000000 --- a/src/main/java/dev/naman/productservice/inheritancedemo/singletable/UserRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -package dev.naman.productservice.inheritancedemo.singletable; - -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository("st_ur") -public interface UserRepository -extends JpaRepository { - - @Override - S save(S entity); -} diff --git a/src/main/java/dev/naman/productservice/inheritancedemo/tableperclass/Mentor.java b/src/main/java/dev/naman/productservice/inheritancedemo/tableperclass/Mentor.java deleted file mode 100644 index df47423..0000000 --- a/src/main/java/dev/naman/productservice/inheritancedemo/tableperclass/Mentor.java +++ /dev/null @@ -1,13 +0,0 @@ -package dev.naman.productservice.inheritancedemo.tableperclass; - -import jakarta.persistence.DiscriminatorValue; -import jakarta.persistence.Entity; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@Entity(name = "tpc_mentor") -public class Mentor extends User { - private double averageRating; -} diff --git a/src/main/java/dev/naman/productservice/inheritancedemo/tableperclass/MentorRepository.java b/src/main/java/dev/naman/productservice/inheritancedemo/tableperclass/MentorRepository.java deleted file mode 100644 index 9c7dbe3..0000000 --- a/src/main/java/dev/naman/productservice/inheritancedemo/tableperclass/MentorRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -package dev.naman.productservice.inheritancedemo.tableperclass; - -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository("tpc_mr") -public interface MentorRepository -extends JpaRepository { - @Override - S save(S entity); -} diff --git a/src/main/java/dev/naman/productservice/inheritancedemo/tableperclass/Student.java b/src/main/java/dev/naman/productservice/inheritancedemo/tableperclass/Student.java deleted file mode 100644 index ce25676..0000000 --- a/src/main/java/dev/naman/productservice/inheritancedemo/tableperclass/Student.java +++ /dev/null @@ -1,14 +0,0 @@ -package dev.naman.productservice.inheritancedemo.tableperclass; - -import jakarta.persistence.DiscriminatorValue; -import jakarta.persistence.Entity; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@Entity(name = "tpc_student") -public class Student extends User { - private double psp; - private double attendance; -} diff --git a/src/main/java/dev/naman/productservice/inheritancedemo/tableperclass/TA.java b/src/main/java/dev/naman/productservice/inheritancedemo/tableperclass/TA.java deleted file mode 100644 index da42ce9..0000000 --- a/src/main/java/dev/naman/productservice/inheritancedemo/tableperclass/TA.java +++ /dev/null @@ -1,13 +0,0 @@ -package dev.naman.productservice.inheritancedemo.tableperclass; - -import jakarta.persistence.DiscriminatorValue; -import jakarta.persistence.Entity; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -@Entity(name = "tpc_ta") -public class TA extends User { - private double averageRating; -} diff --git a/src/main/java/dev/naman/productservice/inheritancedemo/tableperclass/User.java b/src/main/java/dev/naman/productservice/inheritancedemo/tableperclass/User.java deleted file mode 100644 index 3d9b3d4..0000000 --- a/src/main/java/dev/naman/productservice/inheritancedemo/tableperclass/User.java +++ /dev/null @@ -1,21 +0,0 @@ -package dev.naman.productservice.inheritancedemo.tableperclass; - -import jakarta.persistence.*; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; - -import java.util.UUID; - -@Getter -@Setter -@ToString -@Entity(name = "tpc_user") -@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) -public class User { - @Id -// @GeneratedValue(strategy = GenerationType.TABLE, generator="course") - private UUID id; - private String name; - private String email; -} diff --git a/src/main/java/dev/naman/productservice/inheritancedemo/tableperclass/UserRepository.java b/src/main/java/dev/naman/productservice/inheritancedemo/tableperclass/UserRepository.java deleted file mode 100644 index 397d9ca..0000000 --- a/src/main/java/dev/naman/productservice/inheritancedemo/tableperclass/UserRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -package dev.naman.productservice.inheritancedemo.tableperclass; - -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.stereotype.Repository; - -@Repository("tpc_ur") -public interface UserRepository -extends JpaRepository { - - @Override - S save(S entity); -} diff --git a/src/main/java/dev/naman/productservice/models/BaseModel.java b/src/main/java/dev/naman/productservice/models/BaseModel.java deleted file mode 100644 index c8ada58..0000000 --- a/src/main/java/dev/naman/productservice/models/BaseModel.java +++ /dev/null @@ -1,16 +0,0 @@ -package dev.naman.productservice.models; - -import jakarta.persistence.*; -import org.hibernate.annotations.GenericGenerator; -import org.hibernate.id.factory.spi.GenerationTypeStrategy; - -import java.util.UUID; - -@MappedSuperclass -public class BaseModel { - @Id - @GeneratedValue(generator = "naman") - @GenericGenerator(name = "naman", strategy = "uuid2") - @Column(name = "id", columnDefinition = "binary(16)", nullable = false, updatable = false) - private UUID uuid; -} diff --git a/src/main/java/dev/naman/productservice/models/Category.java b/src/main/java/dev/naman/productservice/models/Category.java deleted file mode 100644 index 4fd8f7f..0000000 --- a/src/main/java/dev/naman/productservice/models/Category.java +++ /dev/null @@ -1,36 +0,0 @@ -package dev.naman.productservice.models; - -import jakarta.persistence.*; -import lombok.*; -import org.hibernate.annotations.Fetch; -import org.hibernate.annotations.FetchMode; - -import java.util.ArrayList; -import java.util.List; - -@Entity -@Getter -@Setter -@AllArgsConstructor -@NoArgsConstructor -public class Category extends BaseModel { - @Column - private String name; - - @OneToMany(mappedBy = "category") - @Fetch(FetchMode.SELECT) - private List products = new ArrayList<>(); - - // this is the same relation being mapped by category attribute in the other (Product) class -} -// class Group { -// m:m -// List members; -// m:m -// List admins; -// -// 1----> 1 -// m<---- 1 -// m : 1 -// User creator; -// } \ No newline at end of file diff --git a/src/main/java/dev/naman/productservice/models/Order.java b/src/main/java/dev/naman/productservice/models/Order.java deleted file mode 100644 index 9ec7d46..0000000 --- a/src/main/java/dev/naman/productservice/models/Order.java +++ /dev/null @@ -1,21 +0,0 @@ -package dev.naman.productservice.models; - -import jakarta.persistence.*; -import lombok.Getter; -import lombok.Setter; - -import java.util.List; - -@Entity(name = "orders") -@Getter -@Setter -public class Order extends BaseModel { - - @ManyToMany() - @JoinTable( - name = "product_orders", - joinColumns = @JoinColumn(name = "order_id"), - inverseJoinColumns = @JoinColumn(name = "product_id") - ) - private List product; -} diff --git a/src/main/java/dev/naman/productservice/models/Price.java b/src/main/java/dev/naman/productservice/models/Price.java deleted file mode 100644 index 2b0d1a3..0000000 --- a/src/main/java/dev/naman/productservice/models/Price.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.naman.productservice.models; - -import jakarta.persistence.Entity; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Entity -@Getter -@Setter -@AllArgsConstructor -@NoArgsConstructor -public class Price extends BaseModel { - String currency; - double price; -} diff --git a/src/main/java/dev/naman/productservice/models/Product.java b/src/main/java/dev/naman/productservice/models/Product.java deleted file mode 100644 index ad6621b..0000000 --- a/src/main/java/dev/naman/productservice/models/Product.java +++ /dev/null @@ -1,34 +0,0 @@ -package dev.naman.productservice.models; - -import jakarta.annotation.Nullable; -import jakarta.persistence.*; -import lombok.*; -import org.hibernate.annotations.Fetch; -import org.hibernate.annotations.FetchMode; - -@Entity -@Getter -@Setter -@NoArgsConstructor -@AllArgsConstructor -public class Product extends BaseModel { - - private String title; - - private String description; - - private String image; - // P : C - // => L to R: 1 : 1 - // => R to L: m : 1 - // => Ans: m : 1 - @ManyToOne(cascade = {CascadeType.PERSIST}) - @JoinColumn(name = "category") - private Category category; - - @OneToOne(cascade = {CascadeType.PERSIST, CascadeType.REMOVE}, fetch = FetchType.LAZY) -// @Fetch(FetchMode.JOIN) - private Price price; - private int inventoryCount; -// private double price; -} diff --git a/src/main/java/dev/naman/productservice/repositories/CategoryRepository.java b/src/main/java/dev/naman/productservice/repositories/CategoryRepository.java deleted file mode 100644 index 6521d4a..0000000 --- a/src/main/java/dev/naman/productservice/repositories/CategoryRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -package dev.naman.productservice.repositories; - -import dev.naman.productservice.models.Category; -import org.springframework.context.annotation.Lazy; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.List; -import java.util.Optional; -import java.util.UUID; - -@Lazy -public interface CategoryRepository -extends JpaRepository { - - Optional findById(UUID uuid); - - @Override - List findAllById(Iterable uuids); -} diff --git a/src/main/java/dev/naman/productservice/repositories/CustomQueries.java b/src/main/java/dev/naman/productservice/repositories/CustomQueries.java deleted file mode 100644 index 161151e..0000000 --- a/src/main/java/dev/naman/productservice/repositories/CustomQueries.java +++ /dev/null @@ -1,6 +0,0 @@ -package dev.naman.productservice.repositories; - -public interface CustomQueries { - String FIND_ALL_BY_TITLE = "select * from product join product_orders " + - "on product.id = product_orders.product_id where title = :naman"; -} diff --git a/src/main/java/dev/naman/productservice/repositories/PriceRepository.java b/src/main/java/dev/naman/productservice/repositories/PriceRepository.java deleted file mode 100644 index bd06799..0000000 --- a/src/main/java/dev/naman/productservice/repositories/PriceRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package dev.naman.productservice.repositories; - -import dev.naman.productservice.models.Price; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface PriceRepository -extends JpaRepository { -} diff --git a/src/main/java/dev/naman/productservice/repositories/ProductRepository.java b/src/main/java/dev/naman/productservice/repositories/ProductRepository.java deleted file mode 100644 index c2bd45c..0000000 --- a/src/main/java/dev/naman/productservice/repositories/ProductRepository.java +++ /dev/null @@ -1,47 +0,0 @@ -package dev.naman.productservice.repositories; - -import dev.naman.productservice.models.Category; -import dev.naman.productservice.models.Product; -import org.springframework.data.domain.Example; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.FluentQuery; -import org.springframework.stereotype.Repository; - -import java.util.List; -import java.util.UUID; -import java.util.function.Function; - -@Repository -public interface ProductRepository -extends JpaRepository { - - Product findByTitleEquals(String title); - - Product findByTitleEqualsAndPrice_PriceOrderByPrice_price(String title, double price); - - List findAllByPrice_Currency(String currency); - - @Override - void delete(Product entity); - - long countAllByPrice_Currency(String currency); - - - List findAllByTitleLike(String titleRegex); - - List readAllByTitleLike(String titleRegex); - - - List findAllByCategoryIn(List categories); - - // @Query("select Product from Product where Product .category.uuid in :uuids") -// List findAllByCategoryIn(List uuids); - - - @Query(value = CustomQueries.FIND_ALL_BY_TITLE, nativeQuery = true) - List findAllByTitle(String naman); - -// @Query("select Product from Product where Product.price.currency = :currency and Product.title = :naman") -// List doSomething(String naman, String currency); -} diff --git a/src/main/java/dev/naman/productservice/services/CategoryService.java b/src/main/java/dev/naman/productservice/services/CategoryService.java deleted file mode 100644 index 91d2912..0000000 --- a/src/main/java/dev/naman/productservice/services/CategoryService.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.naman.productservice.services; - -import dev.naman.productservice.models.Category; - -import java.util.List; - -public interface CategoryService { - Category getCategory(String uuid); - List getProductTitles(List categoryUUIDs); -} diff --git a/src/main/java/dev/naman/productservice/services/CategoryServiceImpl.java b/src/main/java/dev/naman/productservice/services/CategoryServiceImpl.java deleted file mode 100644 index b167a55..0000000 --- a/src/main/java/dev/naman/productservice/services/CategoryServiceImpl.java +++ /dev/null @@ -1,79 +0,0 @@ -package dev.naman.productservice.services; - -import dev.naman.productservice.models.Category; -import dev.naman.productservice.models.Product; -import dev.naman.productservice.repositories.CategoryRepository; -import dev.naman.productservice.repositories.ProductRepository; -import org.springframework.stereotype.Service; -import org.springframework.web.bind.annotation.RequestBody; - -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.UUID; - -@Service -public class CategoryServiceImpl implements CategoryService { - private CategoryRepository categoryRepository; - private final ProductRepository productRepository; - - public CategoryServiceImpl(CategoryRepository categoryRepository, - ProductRepository productRepository) { - this.categoryRepository = categoryRepository; - this.productRepository = productRepository; - } - - @Override - public Category getCategory(String uuid) { - Optional categoryOptional = categoryRepository.findById(UUID.fromString(uuid)); - - if (categoryOptional.isEmpty()) { - return null; - } - - Category category = categoryOptional.get(); - - List products = category.getProducts(); - - - return category; - } - - public List getProductTitles(List categoryUUIDs) { - List uuids = new ArrayList<>(); - - for (String uuid: categoryUUIDs) { - uuids.add(UUID.fromString(uuid)); - } -// -// List categories = categoryRepository.findAllById(uuids); -// -// -// List titles = new ArrayList<>(); -// -// categories.forEach( -// category -> { -// category.getProducts().forEach( -// product -> { -// titles.add(product.getTitle()); -// } -// ); -// } -// ); -// -// -// return titles; - - List categories = categoryRepository.findAllById(uuids); - - List products = productRepository.findAllByCategoryIn(categories); - - List titles = new ArrayList<>(); - - for (Product p: products) { - titles.add(p.getTitle()); - } - - return titles; - } -} diff --git a/src/main/java/dev/naman/productservice/services/FakeStoreProductService.java b/src/main/java/dev/naman/productservice/services/FakeStoreProductService.java deleted file mode 100644 index ceb58af..0000000 --- a/src/main/java/dev/naman/productservice/services/FakeStoreProductService.java +++ /dev/null @@ -1,63 +0,0 @@ -package dev.naman.productservice.services; - -import dev.naman.productservice.dtos.GenericProductDto; -import dev.naman.productservice.exceptions.NotFoundException; -import dev.naman.productservice.thirdpartyclients.productsservice.fakestore.FakeStoreProductDto; -import dev.naman.productservice.thirdpartyclients.productsservice.fakestore.FakeStoryProductServiceClient; -import org.springframework.context.annotation.Primary; -import org.springframework.stereotype.Component; -import org.springframework.stereotype.Repository; -import org.springframework.stereotype.Service; - -import java.util.ArrayList; -import java.util.List; - - -@Repository("fakeStoreProductService") -public class FakeStoreProductService implements ProductService { - - private FakeStoryProductServiceClient fakeStoryProductServiceClient; - - private GenericProductDto convertFakeStoreProductIntoGenericProduct(FakeStoreProductDto fakeStoreProductDto) { - - GenericProductDto product = new GenericProductDto(); - product.setId(fakeStoreProductDto.getId()); - product.setImage(fakeStoreProductDto.getImage()); - product.setDescription(fakeStoreProductDto.getDescription()); - product.setTitle(fakeStoreProductDto.getTitle()); - product.setPrice(fakeStoreProductDto.getPrice()); - product.setCategory(fakeStoreProductDto.getCategory()); - - return product; - } - - public FakeStoreProductService(FakeStoryProductServiceClient fakeStoryProductServiceClient) { - this.fakeStoryProductServiceClient = fakeStoryProductServiceClient; - } - - - @Override - public GenericProductDto createProduct(GenericProductDto product) { - return convertFakeStoreProductIntoGenericProduct(fakeStoryProductServiceClient.createProduct(product)); - } - - @Override - public GenericProductDto getProductById(Long id) throws NotFoundException { - return convertFakeStoreProductIntoGenericProduct(fakeStoryProductServiceClient.getProductById(id)); - } - - @Override - public List getAllProducts() { - List genericProductDtos = new ArrayList<>(); - - for (FakeStoreProductDto fakeStoreProductDto: fakeStoryProductServiceClient.getAllProducts()) { - genericProductDtos.add(convertFakeStoreProductIntoGenericProduct(fakeStoreProductDto)); - } - return genericProductDtos; - } - - @Override - public GenericProductDto deleteProduct(Long id) { - return convertFakeStoreProductIntoGenericProduct(fakeStoryProductServiceClient.deleteProduct(id)); - } -} diff --git a/src/main/java/dev/naman/productservice/services/ProductService.java b/src/main/java/dev/naman/productservice/services/ProductService.java deleted file mode 100644 index bc5eb10..0000000 --- a/src/main/java/dev/naman/productservice/services/ProductService.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.naman.productservice.services; - -import dev.naman.productservice.dtos.GenericProductDto; -import dev.naman.productservice.exceptions.NotFoundException; - -import java.util.List; - -public interface ProductService { - - GenericProductDto createProduct(GenericProductDto product); - - GenericProductDto getProductById(Long id) throws NotFoundException; - - List getAllProducts(); - - GenericProductDto deleteProduct(Long id); -} diff --git a/src/main/java/dev/naman/productservice/services/SelfProductServiceImpl.java b/src/main/java/dev/naman/productservice/services/SelfProductServiceImpl.java deleted file mode 100644 index a50d666..0000000 --- a/src/main/java/dev/naman/productservice/services/SelfProductServiceImpl.java +++ /dev/null @@ -1,42 +0,0 @@ -package dev.naman.productservice.services; - -import dev.naman.productservice.dtos.GenericProductDto; -import dev.naman.productservice.models.Product; -import dev.naman.productservice.repositories.ProductRepository; -import org.springframework.context.annotation.Primary; -import org.springframework.stereotype.Service; - -import java.util.List; - - -@Primary -@Service("selfProductServiceImpl") -public class SelfProductServiceImpl implements ProductService { - private ProductRepository productRepository; - - public SelfProductServiceImpl(ProductRepository productRepository) { - this.productRepository = productRepository; - } - - @Override - public GenericProductDto getProductById(Long id) { - - - return new GenericProductDto(); - } - - @Override - public GenericProductDto createProduct(GenericProductDto product) { - return null; - } - - @Override - public List getAllProducts() { - return null; - } - - @Override - public GenericProductDto deleteProduct(Long id) { - return null; - } -} diff --git a/src/main/java/dev/naman/productservice/thirdpartyclients/productsservice/fakestore/FakeStoreProductDto.java b/src/main/java/dev/naman/productservice/thirdpartyclients/productsservice/fakestore/FakeStoreProductDto.java deleted file mode 100644 index 67846c9..0000000 --- a/src/main/java/dev/naman/productservice/thirdpartyclients/productsservice/fakestore/FakeStoreProductDto.java +++ /dev/null @@ -1,18 +0,0 @@ -package dev.naman.productservice.thirdpartyclients.productsservice.fakestore; - -import dev.naman.productservice.models.Category; -import lombok.Getter; -import lombok.Setter; - -@Setter -@Getter -public class FakeStoreProductDto { - private Long id; - private String title; - private double price; - private String category; - private String description; - private String image; -} - -// Break till 10:35 \ No newline at end of file diff --git a/src/main/java/dev/naman/productservice/thirdpartyclients/productsservice/fakestore/FakeStoryProductServiceClient.java b/src/main/java/dev/naman/productservice/thirdpartyclients/productsservice/fakestore/FakeStoryProductServiceClient.java deleted file mode 100644 index 6af4a08..0000000 --- a/src/main/java/dev/naman/productservice/thirdpartyclients/productsservice/fakestore/FakeStoryProductServiceClient.java +++ /dev/null @@ -1,97 +0,0 @@ -package dev.naman.productservice.thirdpartyclients.productsservice.fakestore; - -import dev.naman.productservice.dtos.GenericProductDto; -import dev.naman.productservice.exceptions.NotFoundException; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.http.HttpMethod; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Service; -import org.springframework.web.client.RequestCallback; -import org.springframework.web.client.ResponseExtractor; -import org.springframework.web.client.RestTemplate; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/*** - * Wrapper over FakeStore API - */ -@Service -public class FakeStoryProductServiceClient { - private RestTemplateBuilder restTemplateBuilder; - - - @Value("${fakestore.api.url}") - private String fakeStoreApiUrl; - - @Value("${fakestore.api.paths.product}") - private String fakeStoreProductsApiPath; - - private String specificProductRequestUrl ; - private String productRequestsBaseUrl ; - - public FakeStoryProductServiceClient(RestTemplateBuilder restTemplateBuilder, - @Value("${fakestore.api.url}") String fakeStoreApiUrl, - @Value("${fakestore.api.paths.product}") String fakeStoreProductsApiPath) { - this.restTemplateBuilder = restTemplateBuilder; - this.productRequestsBaseUrl = fakeStoreApiUrl + fakeStoreProductsApiPath; - this.specificProductRequestUrl = fakeStoreApiUrl + fakeStoreProductsApiPath + "/{id}"; - } - - - public FakeStoreProductDto createProduct(GenericProductDto product) { - RestTemplate restTemplate = restTemplateBuilder.build(); - ResponseEntity response = restTemplate.postForEntity( - productRequestsBaseUrl, product, FakeStoreProductDto.class - ); - - return response.getBody(); - } - - public FakeStoreProductDto getProductById(Long id) throws NotFoundException { -// FakeStoreProductService fakeStoreProductService = new FakeStoreProductService(); - RestTemplate restTemplate = restTemplateBuilder.build(); - ResponseEntity response = - restTemplate.getForEntity(specificProductRequestUrl, FakeStoreProductDto.class, id); - - FakeStoreProductDto fakeStoreProductDto = response.getBody(); - - if (fakeStoreProductDto == null) { - throw new NotFoundException("Product with id: " + id + " doesn't exist."); -// return null; - } - -// null == null - -// response.getStatusCode() - - return fakeStoreProductDto; -// return null; - } - - public List getAllProducts() { - RestTemplate restTemplate = restTemplateBuilder.build(); - - ResponseEntity response = - restTemplate.getForEntity(productRequestsBaseUrl, FakeStoreProductDto[].class); - - List answer = new ArrayList<>(); - - return Arrays.stream(response.getBody()).toList(); - } - - public FakeStoreProductDto deleteProduct(Long id) { - RestTemplate restTemplate = restTemplateBuilder.build(); - - - RequestCallback requestCallback = restTemplate.acceptHeaderRequestCallback(FakeStoreProductDto.class); - ResponseExtractor> responseExtractor = - restTemplate.responseEntityExtractor(FakeStoreProductDto.class); - ResponseEntity response = restTemplate.execute(specificProductRequestUrl, HttpMethod.DELETE, - requestCallback, responseExtractor, id); - - return response.getBody(); - } -} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index d032b9b..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,20 +0,0 @@ -productservice.type=fakeStoreProductService -ayush.goyal=fakeStoreProductService -naman.bhalla=abc -server.port=3000 -# hashmap key:value - - -# Fakestore Config Values -fakestore.api.url=https://fakestoreapi.com -fakestore.api.paths.product=/products - -server.error.include-stacktrace=never - -spring.jpa.hibernate.ddl-auto=validate -spring.datasource.url=jdbc:mysql://localhost:3306/sep23productservice -spring.datasource.username=sep23productservice -spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -spring.jpa.show-sql=true -#logging.level.org.hibernate.SQL=DEBUG -#logging.level.org.hibernate.type=TRACE diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..ef475c1 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,27 @@ +use: + custom: + repository: false + +app: + fakestore: + url: https://fakestoreapi.com + service: +# type: FAKE_STORE_SERVICE + type: SELF_STORE_SERVICE +spring: + jpa: + hibernate: + ddl-auto: update + show-sql: true + properties: + hibernate: + format_sql: true + dialect: org.hibernate.dialect.MySQL8Dialect + datasource: + url: jdbc:mysql://localhost:3306/scaler + username: root + password: secret + driver-class-name: com.mysql.cj.jdbc.Driver +logging: + level: + org.hibernate.sql: DEBUG diff --git a/src/main/resources/db/migration/V1__init_db.sql b/src/main/resources/db/migration/V1__init_db.sql deleted file mode 100644 index 4056c0f..0000000 --- a/src/main/resources/db/migration/V1__init_db.sql +++ /dev/null @@ -1,164 +0,0 @@ -CREATE TABLE category -( - id BINARY(16) NOT NULL, - name VARCHAR(255) NULL, - CONSTRAINT pk_category PRIMARY KEY (id) -); - -CREATE TABLE jt_mentor -( - user_id BIGINT NOT NULL, - average_rating DOUBLE NOT NULL, - CONSTRAINT pk_jt_mentor PRIMARY KEY (user_id) -); - -CREATE TABLE jt_student -( - user_id BIGINT NOT NULL, - psp DOUBLE NOT NULL, - attendance DOUBLE NOT NULL, - CONSTRAINT pk_jt_student PRIMARY KEY (user_id) -); - -CREATE TABLE jt_ta -( - user_id BIGINT NOT NULL, - average_rating DOUBLE NOT NULL, - CONSTRAINT pk_jt_ta PRIMARY KEY (user_id) -); - -CREATE TABLE jt_user -( - id BIGINT AUTO_INCREMENT NOT NULL, - name VARCHAR(255) NULL, - email VARCHAR(255) NULL, - CONSTRAINT pk_jt_user PRIMARY KEY (id) -); - -CREATE TABLE ms_mentor -( - id BIGINT AUTO_INCREMENT NOT NULL, - name VARCHAR(255) NULL, - email VARCHAR(255) NULL, - average_rating DOUBLE NOT NULL, - CONSTRAINT pk_ms_mentor PRIMARY KEY (id) -); - -CREATE TABLE ms_student -( - id BIGINT AUTO_INCREMENT NOT NULL, - name VARCHAR(255) NULL, - email VARCHAR(255) NULL, - psp DOUBLE NOT NULL, - attendance DOUBLE NOT NULL, - CONSTRAINT pk_ms_student PRIMARY KEY (id) -); - -CREATE TABLE ms_ta -( - id BIGINT AUTO_INCREMENT NOT NULL, - name VARCHAR(255) NULL, - email VARCHAR(255) NULL, - average_rating DOUBLE NOT NULL, - CONSTRAINT pk_ms_ta PRIMARY KEY (id) -); - -CREATE TABLE orders -( - id BINARY(16) NOT NULL, - CONSTRAINT pk_orders PRIMARY KEY (id) -); - -CREATE TABLE price -( - id BINARY(16) NOT NULL, - currency VARCHAR(255) NULL, - price DOUBLE NOT NULL, - CONSTRAINT pk_price PRIMARY KEY (id) -); - -CREATE TABLE product -( - id BINARY(16) NOT NULL, - title VARCHAR(255) NULL, - `description` VARCHAR(255) NULL, - image VARCHAR(255) NULL, - category BINARY(16) NULL, - price_id BINARY(16) NULL, - CONSTRAINT pk_product PRIMARY KEY (id) -); - -CREATE TABLE product_orders -( - order_id BINARY(16) NOT NULL, - product_id BINARY(16) NOT NULL -); - -CREATE TABLE st_user -( - id BIGINT AUTO_INCREMENT NOT NULL, - user_type INT NULL, - name VARCHAR(255) NULL, - email VARCHAR(255) NULL, - average_rating DOUBLE NOT NULL, - psp DOUBLE NOT NULL, - attendance DOUBLE NOT NULL, - CONSTRAINT pk_st_user PRIMARY KEY (id) -); - -CREATE TABLE tpc_mentor -( - id BINARY(16) NOT NULL, - name VARCHAR(255) NULL, - email VARCHAR(255) NULL, - average_rating DOUBLE NOT NULL, - CONSTRAINT pk_tpc_mentor PRIMARY KEY (id) -); - -CREATE TABLE tpc_student -( - id BINARY(16) NOT NULL, - name VARCHAR(255) NULL, - email VARCHAR(255) NULL, - psp DOUBLE NOT NULL, - attendance DOUBLE NOT NULL, - CONSTRAINT pk_tpc_student PRIMARY KEY (id) -); - -CREATE TABLE tpc_ta -( - id BINARY(16) NOT NULL, - name VARCHAR(255) NULL, - email VARCHAR(255) NULL, - average_rating DOUBLE NOT NULL, - CONSTRAINT pk_tpc_ta PRIMARY KEY (id) -); - -CREATE TABLE tpc_user -( - id BINARY(16) NOT NULL, - name VARCHAR(255) NULL, - email VARCHAR(255) NULL, - CONSTRAINT pk_tpc_user PRIMARY KEY (id) -); - -ALTER TABLE jt_mentor - ADD CONSTRAINT FK_JT_MENTOR_ON_USER FOREIGN KEY (user_id) REFERENCES jt_user (id); - -ALTER TABLE jt_student - ADD CONSTRAINT FK_JT_STUDENT_ON_USER FOREIGN KEY (user_id) REFERENCES jt_user (id); - -ALTER TABLE jt_ta - ADD CONSTRAINT FK_JT_TA_ON_USER FOREIGN KEY (user_id) REFERENCES jt_user (id); - -ALTER TABLE product - ADD CONSTRAINT FK_PRODUCT_ON_CATEGORY FOREIGN KEY (category) REFERENCES category (id); - -ALTER TABLE product - ADD CONSTRAINT FK_PRODUCT_ON_PRICE FOREIGN KEY (price_id) REFERENCES price (id); - -ALTER TABLE product_orders - ADD CONSTRAINT fk_proord_on_order FOREIGN KEY (order_id) REFERENCES orders (id); - -ALTER TABLE product_orders - ADD CONSTRAINT fk_proord_on_product FOREIGN KEY (product_id) REFERENCES product (id); \ No newline at end of file diff --git a/src/main/resources/db/migration/V2__add_something_add_column_inventory_count.sql b/src/main/resources/db/migration/V2__add_something_add_column_inventory_count.sql deleted file mode 100644 index 4f4fe1a..0000000 --- a/src/main/resources/db/migration/V2__add_something_add_column_inventory_count.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE TABLE something -( - id BINARY(16) NOT NULL, - CONSTRAINT pk_something PRIMARY KEY (id) -); - -ALTER TABLE product - ADD inventory_count INT NULL; - -ALTER TABLE product - MODIFY inventory_count INT NOT NULL; \ No newline at end of file diff --git a/src/test/java/dev/biswajit/ecomm/productservice/SelfManagedProductServiceApplicationTests.java b/src/test/java/dev/biswajit/ecomm/productservice/SelfManagedProductServiceApplicationTests.java new file mode 100644 index 0000000..a0b5a73 --- /dev/null +++ b/src/test/java/dev/biswajit/ecomm/productservice/SelfManagedProductServiceApplicationTests.java @@ -0,0 +1,13 @@ +package dev.biswajit.ecomm.productservice; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class SelfManagedProductServiceApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/src/test/java/dev/biswajit/ecomm/productservice/productcontroller/ProductControllerIntegrationTest.java b/src/test/java/dev/biswajit/ecomm/productservice/productcontroller/ProductControllerIntegrationTest.java new file mode 100644 index 0000000..d8cb0b7 --- /dev/null +++ b/src/test/java/dev/biswajit/ecomm/productservice/productcontroller/ProductControllerIntegrationTest.java @@ -0,0 +1,44 @@ +package dev.biswajit.ecomm.productservice.productcontroller; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ActiveProfiles("test") +@SpringBootTest +@ExtendWith(SpringExtension.class) +public class ProductControllerIntegrationTest { + @Test + @Disabled + void shouldReturnProductWhenSearchedById() { + + } + + @Test + @Disabled + void shouldThrowExceptionWhenProductIsNotFound() { + + } + + @Test + @Disabled + void shouldReturnAllProducts() { + + } + + @Test + @Disabled + void shouldCreateProduct() { + + } + + @Test + @Disabled + void shouldUpdateTheProductAttributes() { + + } + +} diff --git a/src/test/java/dev/naman/productservice/ProductserviceApplicationTests.java b/src/test/java/dev/naman/productservice/ProductserviceApplicationTests.java deleted file mode 100644 index a149efa..0000000 --- a/src/test/java/dev/naman/productservice/ProductserviceApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package dev.naman.productservice; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class ProductserviceApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/src/test/java/dev/naman/productservice/RandomTest.java b/src/test/java/dev/naman/productservice/RandomTest.java deleted file mode 100644 index eb71d20..0000000 --- a/src/test/java/dev/naman/productservice/RandomTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.naman.productservice; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -import java.util.Random; - -@SpringBootTest -public class RandomTest { -// @Test -// void testLessThan3() { -// Random random = new Random(); -// int number = random.nextInt(); -// -// assert(number < 10000000); -// } -} diff --git a/src/test/java/dev/naman/productservice/controllers/ProductControllerTest.java b/src/test/java/dev/naman/productservice/controllers/ProductControllerTest.java deleted file mode 100644 index 800e736..0000000 --- a/src/test/java/dev/naman/productservice/controllers/ProductControllerTest.java +++ /dev/null @@ -1,70 +0,0 @@ -package dev.naman.productservice.controllers; - -import dev.naman.productservice.exceptions.NotFoundException; -import dev.naman.productservice.thirdpartyclients.productsservice.fakestore.FakeStoryProductServiceClient; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -import java.util.Random; - -import static org.junit.jupiter.api.Assertions.*; - -@SpringBootTest -public class ProductControllerTest { - - @Autowired - private FakeStoryProductServiceClient fakeStoryProductServiceClient; - - - @Test - @DisplayName("1 + 1 equals 2") - void onePlusOneEqualsTrue() throws NotFoundException { -// System.out.println("It is true"); -// assertEquals(11, 1 + 1, "one plus is not coming to be 11"); - -// assert - -// assertNull(fakeStoryProductServiceClient.getProductById(101L)); - -// Exception e; -// -// try { -// fakeStoryProductServiceClient.getProductById(101L); -// } catch (Exception ex) { -// e = ex; -// } -// -// assertNotNull(e); -// assertEquals(NotFoundException.class, e.getClass()); - -// assertEquals(null, fakeStoryProductServiceClient.getProductById(101L)); -// assertThrows(NotFoundException.class, () -> fakeStoryProductServiceClient.getProductById(101L)); -// -// assertEquals(true, 1 + 1 == 2); - assertTrue(returnSomething()); - } - - boolean returnSomething() { - Random random = new Random(); - return random.nextInt() % 2 == 0; - } - - @Test - void additionShouldBeCorrect() { - assertTrue(-1 + -1 == -2, "adding 2 negatives is not correct"); - - assertTrue(-1 + 0 == -1, "adding a negative and a zero is giving wrong answer"); - - assertTrue(-1 + 1 == 0); - - assert 1 + 0 == 1; - - assert 1 + 1 == 2; - } -} - -// Assertion Framework -// -> allows you to make assertions -// -> allows you to make checks \ No newline at end of file diff --git a/src/test/java/dev/naman/productservice/thirdpartyclients/productsservice/fakestore/FakeStoryProductServiceClientTest.java b/src/test/java/dev/naman/productservice/thirdpartyclients/productsservice/fakestore/FakeStoryProductServiceClientTest.java deleted file mode 100644 index d79b07f..0000000 --- a/src/test/java/dev/naman/productservice/thirdpartyclients/productsservice/fakestore/FakeStoryProductServiceClientTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package dev.naman.productservice.thirdpartyclients.productsservice.fakestore; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.http.ResponseEntity; -import org.springframework.web.client.RestTemplate; - -import static org.junit.jupiter.api.Assertions.*; - -@SpringBootTest -class FakeStoryProductServiceClientTest { - @Autowired - private RestTemplateBuilder restTemplateBuilder; - - @Test - void testNonExistingProductReturnsNull() { -// RestTemplate restTemplate = restTemplateBuilder.build(); -// ResponseEntity response = -// restTemplate.getForEntity(specificProductRequestUrl, FakeStoreProductDto.class, id); -// -// FakeStoreProductDto fakeStoreProductDto = response.getBody(); -// -// assertNull(fakeStoreProductDto); - } -} \ No newline at end of file