From 7bd73f9f14b09bb63c87f1d7ecc1f271197443f8 Mon Sep 17 00:00:00 2001 From: bedroomghost Date: Sat, 12 Apr 2025 17:29:29 +0200 Subject: [PATCH 01/10] feat!: Set up project --- .gitattributes | 2 + .gitignore | 51 ++-- .mvn/wrapper/maven-wrapper.properties | 19 ++ mvnw | 259 ++++++++++++++++++ mvnw.cmd | 149 ++++++++++ pom.xml | 84 ++++++ .../techivw/webprice/WebpriceApplication.java | 13 + src/main/resources/application.properties | 1 + .../webprice/WebpriceApplicationTests.java | 13 + 9 files changed, 569 insertions(+), 22 deletions(-) create mode 100644 .gitattributes create mode 100644 .mvn/wrapper/maven-wrapper.properties create mode 100644 mvnw create mode 100644 mvnw.cmd create mode 100644 pom.xml create mode 100644 src/main/java/com/techivw/webprice/WebpriceApplication.java create mode 100644 src/main/resources/application.properties create mode 100644 src/test/java/com/techivw/webprice/WebpriceApplicationTests.java diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..3b41682 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +/mvnw text eol=lf +*.cmd text eol=crlf diff --git a/.gitignore b/.gitignore index 9154f4c..549e00a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,26 +1,33 @@ -# ---> Java -# Compiled class file -*.class +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ -# Log file -*.log +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache -# BlueJ files -*.ctxt +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.nar -*.ear -*.zip -*.tar.gz -*.rar - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* -replay_pid* +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ +### VS Code ### +.vscode/ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..d58dfb7 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,19 @@ +# 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 +# +# http://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. +wrapperVersion=3.3.2 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip diff --git a/mvnw b/mvnw new file mode 100644 index 0000000..19529dd --- /dev/null +++ b/mvnw @@ -0,0 +1,259 @@ +#!/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 +# +# http://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.3.2 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + 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" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..249bdf3 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,149 @@ +<# : batch portion +@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 http://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.3.2 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' +$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" +if ($env:MAVEN_USER_HOME) { + $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" +} +$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..1a81bef --- /dev/null +++ b/pom.xml @@ -0,0 +1,84 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.4.4 + + + com.techivw + webprice + 0.0.1-SNAPSHOT + webprice + Demo project for Spring Boot + + + + + + + + + + + + + + + 21 + + + + org.springframework.boot + spring-boot-starter + + + + com.h2database + h2 + runtime + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.projectlombok + lombok + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/src/main/java/com/techivw/webprice/WebpriceApplication.java b/src/main/java/com/techivw/webprice/WebpriceApplication.java new file mode 100644 index 0000000..4812da4 --- /dev/null +++ b/src/main/java/com/techivw/webprice/WebpriceApplication.java @@ -0,0 +1,13 @@ +package com.techivw.webprice; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class WebpriceApplication { + + public static void main(String[] args) { + SpringApplication.run(WebpriceApplication.class, args); + } + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..1981c62 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=webprice diff --git a/src/test/java/com/techivw/webprice/WebpriceApplicationTests.java b/src/test/java/com/techivw/webprice/WebpriceApplicationTests.java new file mode 100644 index 0000000..206151e --- /dev/null +++ b/src/test/java/com/techivw/webprice/WebpriceApplicationTests.java @@ -0,0 +1,13 @@ +package com.techivw.webprice; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class WebpriceApplicationTests { + + @Test + void contextLoads() { + } + +} -- 2.47.2 From bf5e51b4258dc281232e50b35477fee7bfe030fc Mon Sep 17 00:00:00 2001 From: bedroomghost Date: Sun, 13 Apr 2025 11:43:56 +0200 Subject: [PATCH 02/10] chore!: Clean up project and scaffolding --- .gitattributes | 2 - .gitignore | 1 - application/pom.xml | 24 ++ boot/pom.xml | 70 +++++ .../com/techivw/webprice/Application.java | 4 +- .../main/resources/application.properties | 0 domain/pom.xml | 17 ++ infrastructure/in/rest-api/pom.xml | 28 ++ infrastructure/out/sql-repository/pom.xml | 28 ++ mvnw | 259 ------------------ mvnw.cmd | 149 ---------- pom.xml | 114 +++----- .../webprice/WebpriceApplicationTests.java | 13 - 13 files changed, 212 insertions(+), 497 deletions(-) delete mode 100644 .gitattributes create mode 100644 application/pom.xml create mode 100644 boot/pom.xml rename src/main/java/com/techivw/webprice/WebpriceApplication.java => boot/src/main/java/com/techivw/webprice/Application.java (70%) rename {src => boot/src}/main/resources/application.properties (100%) create mode 100644 domain/pom.xml create mode 100644 infrastructure/in/rest-api/pom.xml create mode 100644 infrastructure/out/sql-repository/pom.xml delete mode 100644 mvnw delete mode 100644 mvnw.cmd delete mode 100644 src/test/java/com/techivw/webprice/WebpriceApplicationTests.java diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 3b41682..0000000 --- a/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -/mvnw text eol=lf -*.cmd text eol=crlf diff --git a/.gitignore b/.gitignore index 549e00a..7ed0d6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -HELP.md target/ !.mvn/wrapper/maven-wrapper.jar !**/src/main/**/target/ diff --git a/application/pom.xml b/application/pom.xml new file mode 100644 index 0000000..f32927a --- /dev/null +++ b/application/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + application + jar + application + + + com.techivw + webprice + 0.0.1-SNAPSHOT + + + + + com.techivw + domain + + + + \ No newline at end of file diff --git a/boot/pom.xml b/boot/pom.xml new file mode 100644 index 0000000..c77ee7e --- /dev/null +++ b/boot/pom.xml @@ -0,0 +1,70 @@ + + + 4.0.0 + + boot + jar + boot + + + com.techivw + webprice + 0.0.1-SNAPSHOT + + + + + com.techivw + domain + + + com.techivw + application + + + com.techivw + rest-api + + + com.techivw + sql-repository + + + + org.springframework.boot + spring-boot-starter + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.projectlombok + lombok + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/techivw/webprice/WebpriceApplication.java b/boot/src/main/java/com/techivw/webprice/Application.java similarity index 70% rename from src/main/java/com/techivw/webprice/WebpriceApplication.java rename to boot/src/main/java/com/techivw/webprice/Application.java index 4812da4..f8e7b60 100644 --- a/src/main/java/com/techivw/webprice/WebpriceApplication.java +++ b/boot/src/main/java/com/techivw/webprice/Application.java @@ -4,10 +4,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -public class WebpriceApplication { +public class Application { public static void main(String[] args) { - SpringApplication.run(WebpriceApplication.class, args); + SpringApplication.run(Application.class, args); } } diff --git a/src/main/resources/application.properties b/boot/src/main/resources/application.properties similarity index 100% rename from src/main/resources/application.properties rename to boot/src/main/resources/application.properties diff --git a/domain/pom.xml b/domain/pom.xml new file mode 100644 index 0000000..59613af --- /dev/null +++ b/domain/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + domain + jar + domain + + + com.techivw + webprice + 0.0.1-SNAPSHOT + + + diff --git a/infrastructure/in/rest-api/pom.xml b/infrastructure/in/rest-api/pom.xml new file mode 100644 index 0000000..00326b8 --- /dev/null +++ b/infrastructure/in/rest-api/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + + rest-api + jar + rest-api + + + com.techivw + webprice + 0.0.1-SNAPSHOT + + + + + com.techivw + domain + + + com.techivw + application + + + + diff --git a/infrastructure/out/sql-repository/pom.xml b/infrastructure/out/sql-repository/pom.xml new file mode 100644 index 0000000..6cd3125 --- /dev/null +++ b/infrastructure/out/sql-repository/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + + sql-repository + jar + sql-repository + + + com.techivw + webprice + 0.0.1-SNAPSHOT + + + + + com.techivw + domain + + + com.techivw + application + + + + \ No newline at end of file diff --git a/mvnw b/mvnw deleted file mode 100644 index 19529dd..0000000 --- a/mvnw +++ /dev/null @@ -1,259 +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 -# -# http://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.3.2 -# -# Optional ENV vars -# ----------------- -# JAVA_HOME - location of a JDK home dir, required when download maven via java source -# MVNW_REPOURL - repo url base for downloading maven distribution -# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven -# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output -# ---------------------------------------------------------------------------- - -set -euf -[ "${MVNW_VERBOSE-}" != debug ] || set -x - -# OS specific support. -native_path() { printf %s\\n "$1"; } -case "$(uname)" in -CYGWIN* | MINGW*) - [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" - native_path() { cygpath --path --windows "$1"; } - ;; -esac - -# set JAVACMD and JAVACCMD -set_java_home() { - # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched - 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" - JAVACCMD="$JAVA_HOME/jre/sh/javac" - else - JAVACMD="$JAVA_HOME/bin/java" - JAVACCMD="$JAVA_HOME/bin/javac" - - if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then - echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 - echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 - return 1 - fi - fi - else - JAVACMD="$( - 'set' +e - 'unset' -f command 2>/dev/null - 'command' -v java - )" || : - JAVACCMD="$( - 'set' +e - 'unset' -f command 2>/dev/null - 'command' -v javac - )" || : - - if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then - echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 - return 1 - fi - fi -} - -# hash string like Java String::hashCode -hash_string() { - str="${1:-}" h=0 - while [ -n "$str" ]; do - char="${str%"${str#?}"}" - h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) - str="${str#?}" - done - printf %x\\n $h -} - -verbose() { :; } -[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } - -die() { - printf %s\\n "$1" >&2 - exit 1 -} - -trim() { - # MWRAPPER-139: - # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. - # Needed for removing poorly interpreted newline sequences when running in more - # exotic environments such as mingw bash on Windows. - printf "%s" "${1}" | tr -d '[:space:]' -} - -# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties -while IFS="=" read -r key value; do - case "${key-}" in - distributionUrl) distributionUrl=$(trim "${value-}") ;; - distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; - esac -done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" -[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" - -case "${distributionUrl##*/}" in -maven-mvnd-*bin.*) - MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ - case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in - *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; - :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; - :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; - :Linux*x86_64*) distributionPlatform=linux-amd64 ;; - *) - echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 - distributionPlatform=linux-amd64 - ;; - esac - distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" - ;; -maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; -*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; -esac - -# apply MVNW_REPOURL and calculate MAVEN_HOME -# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ -[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" -distributionUrlName="${distributionUrl##*/}" -distributionUrlNameMain="${distributionUrlName%.*}" -distributionUrlNameMain="${distributionUrlNameMain%-bin}" -MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" -MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" - -exec_maven() { - unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : - exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" -} - -if [ -d "$MAVEN_HOME" ]; then - verbose "found existing MAVEN_HOME at $MAVEN_HOME" - exec_maven "$@" -fi - -case "${distributionUrl-}" in -*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; -*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; -esac - -# prepare tmp dir -if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then - clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } - trap clean HUP INT TERM EXIT -else - die "cannot create temp dir" -fi - -mkdir -p -- "${MAVEN_HOME%/*}" - -# Download and Install Apache Maven -verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." -verbose "Downloading from: $distributionUrl" -verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" - -# select .zip or .tar.gz -if ! command -v unzip >/dev/null; then - distributionUrl="${distributionUrl%.zip}.tar.gz" - distributionUrlName="${distributionUrl##*/}" -fi - -# verbose opt -__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' -[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v - -# normalize http auth -case "${MVNW_PASSWORD:+has-password}" in -'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; -has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; -esac - -if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then - verbose "Found wget ... using wget" - wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" -elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then - verbose "Found curl ... using curl" - curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" -elif set_java_home; then - verbose "Falling back to use Java to download" - javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" - targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" - cat >"$javaSource" <<-END - public class Downloader extends java.net.Authenticator - { - protected java.net.PasswordAuthentication getPasswordAuthentication() - { - return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); - } - public static void main( String[] args ) throws Exception - { - setDefault( new Downloader() ); - java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); - } - } - END - # For Cygwin/MinGW, switch paths to Windows format before running javac and java - verbose " - Compiling Downloader.java ..." - "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" - verbose " - Running Downloader.java ..." - "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" -fi - -# If specified, validate the SHA-256 sum of the Maven distribution zip file -if [ -n "${distributionSha256Sum-}" ]; then - distributionSha256Result=false - if [ "$MVN_CMD" = mvnd.sh ]; then - echo "Checksum validation is not supported for maven-mvnd." >&2 - echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 - exit 1 - elif command -v sha256sum >/dev/null; then - if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then - distributionSha256Result=true - fi - elif command -v shasum >/dev/null; then - if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then - distributionSha256Result=true - fi - else - echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 - echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 - exit 1 - fi - if [ $distributionSha256Result = false ]; then - echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 - echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 - exit 1 - fi -fi - -# unzip and move -if command -v unzip >/dev/null; then - unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" -else - tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" -fi -printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" -mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" - -clean || : -exec_maven "$@" diff --git a/mvnw.cmd b/mvnw.cmd deleted file mode 100644 index 249bdf3..0000000 --- a/mvnw.cmd +++ /dev/null @@ -1,149 +0,0 @@ -<# : batch portion -@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 http://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.3.2 -@REM -@REM Optional ENV vars -@REM MVNW_REPOURL - repo url base for downloading maven distribution -@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven -@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output -@REM ---------------------------------------------------------------------------- - -@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) -@SET __MVNW_CMD__= -@SET __MVNW_ERROR__= -@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% -@SET PSModulePath= -@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( - IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) -) -@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% -@SET __MVNW_PSMODULEP_SAVE= -@SET __MVNW_ARG0_NAME__= -@SET MVNW_USERNAME= -@SET MVNW_PASSWORD= -@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) -@echo Cannot start maven from wrapper >&2 && exit /b 1 -@GOTO :EOF -: end batch / begin powershell #> - -$ErrorActionPreference = "Stop" -if ($env:MVNW_VERBOSE -eq "true") { - $VerbosePreference = "Continue" -} - -# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties -$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl -if (!$distributionUrl) { - Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" -} - -switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { - "maven-mvnd-*" { - $USE_MVND = $true - $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" - $MVN_CMD = "mvnd.cmd" - break - } - default { - $USE_MVND = $false - $MVN_CMD = $script -replace '^mvnw','mvn' - break - } -} - -# apply MVNW_REPOURL and calculate MAVEN_HOME -# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ -if ($env:MVNW_REPOURL) { - $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } - $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" -} -$distributionUrlName = $distributionUrl -replace '^.*/','' -$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' -$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" -if ($env:MAVEN_USER_HOME) { - $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" -} -$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' -$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" - -if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { - Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" - Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" - exit $? -} - -if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { - Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" -} - -# prepare tmp dir -$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile -$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" -$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null -trap { - if ($TMP_DOWNLOAD_DIR.Exists) { - try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } - catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } - } -} - -New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null - -# Download and Install Apache Maven -Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." -Write-Verbose "Downloading from: $distributionUrl" -Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" - -$webclient = New-Object System.Net.WebClient -if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { - $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) -} -[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null - -# If specified, validate the SHA-256 sum of the Maven distribution zip file -$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum -if ($distributionSha256Sum) { - if ($USE_MVND) { - Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." - } - Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash - if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { - Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." - } -} - -# unzip and move -Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null -Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null -try { - Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null -} catch { - if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { - Write-Error "fail to move MAVEN_HOME" - } -} finally { - try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } - catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } -} - -Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/pom.xml b/pom.xml index 1a81bef..9d71b30 100644 --- a/pom.xml +++ b/pom.xml @@ -2,83 +2,55 @@ 4.0.0 + + com.techivw + webprice + 0.0.1-SNAPSHOT + pom + web-price + org.springframework.boot spring-boot-starter-parent 3.4.4 - com.techivw - webprice - 0.0.1-SNAPSHOT - webprice - Demo project for Spring Boot - - - - - - - - - - - - - - - 21 - - - - org.springframework.boot - spring-boot-starter - - - com.h2database - h2 - runtime - - - org.projectlombok - lombok - true - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - org.projectlombok - lombok - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - - - - + + + + com.techivw + domain + ${project.version} + + + com.techivw + application + ${project.version} + + + com.techivw + rest-api + ${project.version} + + + com.techivw + sql-repository + ${project.version} + + + com.techivw + boot + ${project.version} + + + + + domain + application + infrastructure/in/rest-api + infrastructure/out/sql-repository + boot + diff --git a/src/test/java/com/techivw/webprice/WebpriceApplicationTests.java b/src/test/java/com/techivw/webprice/WebpriceApplicationTests.java deleted file mode 100644 index 206151e..0000000 --- a/src/test/java/com/techivw/webprice/WebpriceApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.techivw.webprice; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class WebpriceApplicationTests { - - @Test - void contextLoads() { - } - -} -- 2.47.2 From 0021f7698e0e557602457cdfd672841582723c40 Mon Sep 17 00:00:00 2001 From: bedroomghost Date: Mon, 14 Apr 2025 18:17:15 +0200 Subject: [PATCH 03/10] chore: Clean up project and scaffolding --- .mvn/wrapper/maven-wrapper.properties | 19 ------ application/pom.xml | 4 +- boot/pom.xml | 46 ++++--------- domain/pom.xml | 3 +- infrastructure/in/rest-api/pom.xml | 15 +++-- infrastructure/out/sql-repository/pom.xml | 5 +- pom.xml | 80 +++++++++++------------ 7 files changed, 67 insertions(+), 105 deletions(-) delete mode 100644 .mvn/wrapper/maven-wrapper.properties diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties deleted file mode 100644 index d58dfb7..0000000 --- a/.mvn/wrapper/maven-wrapper.properties +++ /dev/null @@ -1,19 +0,0 @@ -# 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 -# -# http://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. -wrapperVersion=3.3.2 -distributionType=only-script -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip diff --git a/application/pom.xml b/application/pom.xml index f32927a..ff5fe0d 100644 --- a/application/pom.xml +++ b/application/pom.xml @@ -10,14 +10,16 @@ com.techivw - webprice + web-price 0.0.1-SNAPSHOT + com.techivw domain + 0.0.1-SNAPSHOT diff --git a/boot/pom.xml b/boot/pom.xml index c77ee7e..0f47e93 100644 --- a/boot/pom.xml +++ b/boot/pom.xml @@ -4,67 +4,47 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + + com.techivw + web-price + 0.0.1-SNAPSHOT + + + boot jar boot - - com.techivw - webprice - 0.0.1-SNAPSHOT - - + com.techivw domain + 0.0.1-SNAPSHOT com.techivw application + 0.0.1-SNAPSHOT com.techivw rest-api + 0.0.1-SNAPSHOT com.techivw sql-repository - - - - org.springframework.boot - spring-boot-starter + 0.0.1-SNAPSHOT - - org.apache.maven.plugins - maven-compiler-plugin - - - - org.projectlombok - lombok - - - - org.springframework.boot spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - - - \ No newline at end of file + diff --git a/domain/pom.xml b/domain/pom.xml index 59613af..95acb5d 100644 --- a/domain/pom.xml +++ b/domain/pom.xml @@ -10,8 +10,7 @@ com.techivw - webprice + web-price 0.0.1-SNAPSHOT - diff --git a/infrastructure/in/rest-api/pom.xml b/infrastructure/in/rest-api/pom.xml index 00326b8..de49e08 100644 --- a/infrastructure/in/rest-api/pom.xml +++ b/infrastructure/in/rest-api/pom.xml @@ -4,24 +4,27 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + + com.techivw + web-price + 0.0.1-SNAPSHOT + ../../../pom.xml + + rest-api jar rest-api - - com.techivw - webprice - 0.0.1-SNAPSHOT - - com.techivw domain + 0.0.1-SNAPSHOT com.techivw application + 0.0.1-SNAPSHOT diff --git a/infrastructure/out/sql-repository/pom.xml b/infrastructure/out/sql-repository/pom.xml index 6cd3125..a15cfe6 100644 --- a/infrastructure/out/sql-repository/pom.xml +++ b/infrastructure/out/sql-repository/pom.xml @@ -10,18 +10,21 @@ com.techivw - webprice + web-price 0.0.1-SNAPSHOT + ../../../pom.xml com.techivw domain + 0.0.1-SNAPSHOT com.techivw application + 0.0.1-SNAPSHOT diff --git a/pom.xml b/pom.xml index 9d71b30..4a35e15 100644 --- a/pom.xml +++ b/pom.xml @@ -3,49 +3,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.techivw - webprice - 0.0.1-SNAPSHOT - pom - web-price - - - org.springframework.boot - spring-boot-starter-parent - 3.4.4 - - - - - - - com.techivw - domain - ${project.version} - - - com.techivw - application - ${project.version} - - - com.techivw - rest-api - ${project.version} - - - com.techivw - sql-repository - ${project.version} - - - com.techivw - boot - ${project.version} - - - - domain application @@ -53,4 +10,41 @@ infrastructure/out/sql-repository boot + + + org.springframework.boot + spring-boot-starter-parent + 3.4.4 + + + + com.techivw + web-price + 0.0.1-SNAPSHOT + pom + web-price + + + 21 + + + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-web + + + org.projectlombok + lombok + + + org.springframework.boot + spring-boot-starter-data-jpa + + -- 2.47.2 From ba13f2110254698f93e25b1722b9a597e16f3ca7 Mon Sep 17 00:00:00 2001 From: bedroomghost Date: Mon, 14 Apr 2025 20:19:27 +0200 Subject: [PATCH 04/10] feat: get product price by brand and date range --- .../ports/in/PriceServicePort.java | 11 ++++ .../ports/out/PriceRepositoryPort.java | 12 ++++ .../application/services/PriceService.java | 21 +++++++ .../src/main/resources/application.properties | 11 ++++ .../com/techivw/webprice/domain/Price.java | 23 ++++++++ .../adapters/PriceControllerAdapter.java | 59 +++++++++++++++++++ .../in/controllers/model/PriceResponse.java | 17 ++++++ .../PriceEntityJPARepository.java | 20 +++++++ .../adapters/PriceRepositoryAdapter.java | 28 +++++++++ .../mappers/PriceEntityMapper.java | 28 +++++++++ .../repositories/model/PriceEntity.java | 47 +++++++++++++++ pom.xml | 13 +++- 12 files changed, 288 insertions(+), 2 deletions(-) create mode 100644 application/src/main/java/com/techivw/webprice/application/ports/in/PriceServicePort.java create mode 100644 application/src/main/java/com/techivw/webprice/application/ports/out/PriceRepositoryPort.java create mode 100644 application/src/main/java/com/techivw/webprice/application/services/PriceService.java create mode 100644 domain/src/main/java/com/techivw/webprice/domain/Price.java create mode 100644 infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/adapters/PriceControllerAdapter.java create mode 100644 infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/model/PriceResponse.java create mode 100644 infrastructure/out/sql-repository/src/main/java/com/techivw/webprice/infrastructure/repositories/PriceEntityJPARepository.java create mode 100644 infrastructure/out/sql-repository/src/main/java/com/techivw/webprice/infrastructure/repositories/adapters/PriceRepositoryAdapter.java create mode 100644 infrastructure/out/sql-repository/src/main/java/com/techivw/webprice/infrastructure/repositories/mappers/PriceEntityMapper.java create mode 100644 infrastructure/out/sql-repository/src/main/java/com/techivw/webprice/infrastructure/repositories/model/PriceEntity.java diff --git a/application/src/main/java/com/techivw/webprice/application/ports/in/PriceServicePort.java b/application/src/main/java/com/techivw/webprice/application/ports/in/PriceServicePort.java new file mode 100644 index 0000000..1a37997 --- /dev/null +++ b/application/src/main/java/com/techivw/webprice/application/ports/in/PriceServicePort.java @@ -0,0 +1,11 @@ +package com.techivw.webprice.application.ports.in; + +import com.techivw.webprice.domain.Price; + +import java.time.LocalDateTime; + +public interface PriceServicePort { + + Price getPriceWithHighestPriorityByDateTimeAndProductIdAndBrandId(LocalDateTime dateTime, Long productId, Long brandId); + +} diff --git a/application/src/main/java/com/techivw/webprice/application/ports/out/PriceRepositoryPort.java b/application/src/main/java/com/techivw/webprice/application/ports/out/PriceRepositoryPort.java new file mode 100644 index 0000000..b785a12 --- /dev/null +++ b/application/src/main/java/com/techivw/webprice/application/ports/out/PriceRepositoryPort.java @@ -0,0 +1,12 @@ +package com.techivw.webprice.application.ports.out; + +import com.techivw.webprice.domain.Price; + +import java.time.LocalDateTime; +import java.util.Optional; + +public interface PriceRepositoryPort { + + Optional findHighestPriorityPriceByDateTimeAndProductIdAndBrandId(LocalDateTime dateTime, Long productId, Long brandId); + +} diff --git a/application/src/main/java/com/techivw/webprice/application/services/PriceService.java b/application/src/main/java/com/techivw/webprice/application/services/PriceService.java new file mode 100644 index 0000000..247c416 --- /dev/null +++ b/application/src/main/java/com/techivw/webprice/application/services/PriceService.java @@ -0,0 +1,21 @@ +package com.techivw.webprice.application.services; + +import com.techivw.webprice.application.ports.in.PriceServicePort; +import com.techivw.webprice.application.ports.out.PriceRepositoryPort; +import com.techivw.webprice.domain.Price; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; + +import java.time.LocalDateTime; + +@Service +@AllArgsConstructor +public class PriceService implements PriceServicePort { + + PriceRepositoryPort priceRepositoryPort; + + @Override + public Price getPriceWithHighestPriorityByDateTimeAndProductIdAndBrandId(LocalDateTime dateTime, Long productId, Long brandId) { + return priceRepositoryPort.findHighestPriorityPriceByDateTimeAndProductIdAndBrandId(dateTime, productId, brandId).orElse(null); + } +} diff --git a/boot/src/main/resources/application.properties b/boot/src/main/resources/application.properties index 1981c62..c02d384 100644 --- a/boot/src/main/resources/application.properties +++ b/boot/src/main/resources/application.properties @@ -1 +1,12 @@ spring.application.name=webprice + +# Database Configuration +spring.datasource.url=jdbc:h2:mem:webprice +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=admin +spring.datasource.password=admin +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect + +# H2 console +spring.h2.console.enabled=true +spring.h2.console.path=/h2-console diff --git a/domain/src/main/java/com/techivw/webprice/domain/Price.java b/domain/src/main/java/com/techivw/webprice/domain/Price.java new file mode 100644 index 0000000..fc8ba9a --- /dev/null +++ b/domain/src/main/java/com/techivw/webprice/domain/Price.java @@ -0,0 +1,23 @@ +package com.techivw.webprice.domain; + +import lombok.Builder; +import lombok.Data; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +@Data +@Builder +public class Price { + + private Long id; + private Long brandId; + private LocalDateTime startDate; + private LocalDateTime endDate; + private Long priceList; + private Long productId; + private Integer priority; + private BigDecimal price; + private String currency; + +} diff --git a/infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/adapters/PriceControllerAdapter.java b/infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/adapters/PriceControllerAdapter.java new file mode 100644 index 0000000..cdb1c0f --- /dev/null +++ b/infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/adapters/PriceControllerAdapter.java @@ -0,0 +1,59 @@ +package com.techivw.webprice.infrastructure.in.controllers.adapters; + +import com.techivw.webprice.application.ports.in.PriceServicePort; +import com.techivw.webprice.domain.Price; +import com.techivw.webprice.infrastructure.in.controllers.model.PriceResponse; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import lombok.AllArgsConstructor; +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.time.LocalDateTime; + +@RestController +@AllArgsConstructor +@RequestMapping("/price") +public class PriceControllerAdapter { + + private PriceServicePort priceServicePort; + + @GetMapping + @Operation( + summary = "Get product price", + description = "Returns the current price for a specific product from a particular brand at a given date and time" + ) + @ApiResponse( + responseCode = "200", + description = "Price information found", + content = @Content(mediaType = "application/json", schema = @Schema(implementation = PriceResponse.class)) + ) + @ApiResponse(responseCode = "404", description = "Price information not found for the given parameters") + @ApiResponse(responseCode = "400", description = "Invalid request parameters") + public ResponseEntity getPrice( + @Parameter(description = "Date and time for price lookup (ISO format)", example = "2025-04-30T12:00:00") + @RequestParam(name = "dateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateTime, + @Parameter(description = "Product ID", example = "35455") + @RequestParam(name = "productId") Long productId, + @Parameter(description = "Brand ID", example = "1") + @RequestParam(name = "brandId") Long brandId) { + + Price price = priceServicePort.getPriceWithHighestPriorityByDateTimeAndProductIdAndBrandId(dateTime, productId, brandId); + PriceResponse priceResponse = PriceResponse.builder() + .productId(price.getProductId()) + .brandId(price.getBrandId()) + .priceList(price.getPriceList()) + .startDate(price.getStartDate()) + .endDate(price.getEndDate()) + .price(price.getPrice()) + .build(); + return ResponseEntity.ok(priceResponse); + } +} diff --git a/infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/model/PriceResponse.java b/infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/model/PriceResponse.java new file mode 100644 index 0000000..4c32826 --- /dev/null +++ b/infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/model/PriceResponse.java @@ -0,0 +1,17 @@ +package com.techivw.webprice.infrastructure.in.controllers.model; + +import lombok.Builder; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +@Builder +public class PriceResponse { + + private Long productId; + private Long brandId; + private Long priceList; + private LocalDateTime startDate; + private LocalDateTime endDate; + private BigDecimal price; +} diff --git a/infrastructure/out/sql-repository/src/main/java/com/techivw/webprice/infrastructure/repositories/PriceEntityJPARepository.java b/infrastructure/out/sql-repository/src/main/java/com/techivw/webprice/infrastructure/repositories/PriceEntityJPARepository.java new file mode 100644 index 0000000..f265993 --- /dev/null +++ b/infrastructure/out/sql-repository/src/main/java/com/techivw/webprice/infrastructure/repositories/PriceEntityJPARepository.java @@ -0,0 +1,20 @@ +package com.techivw.webprice.infrastructure.repositories; + +import com.techivw.webprice.infrastructure.repositories.model.PriceEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.stereotype.Repository; + +import java.time.LocalDateTime; +import java.util.Optional; + +@Repository +public interface PriceEntityJPARepository extends JpaRepository { + + @Query("SELECT p FROM PriceEntity p WHERE " + + "p.productId = :productId " + + "AND p.brandId = :brandId " + + "AND :dateTime BETWEEN p.startDate AND p.endDate " + + "ORDER BY p.priority DESC LIMIT 1") + Optional findPriceByDateTimeAndProductIdAndBrandId(LocalDateTime dateTime, Long productId, Long brandId); +} diff --git a/infrastructure/out/sql-repository/src/main/java/com/techivw/webprice/infrastructure/repositories/adapters/PriceRepositoryAdapter.java b/infrastructure/out/sql-repository/src/main/java/com/techivw/webprice/infrastructure/repositories/adapters/PriceRepositoryAdapter.java new file mode 100644 index 0000000..a30b161 --- /dev/null +++ b/infrastructure/out/sql-repository/src/main/java/com/techivw/webprice/infrastructure/repositories/adapters/PriceRepositoryAdapter.java @@ -0,0 +1,28 @@ +package com.techivw.webprice.infrastructure.repositories.adapters; + +import com.techivw.webprice.application.ports.out.PriceRepositoryPort; +import com.techivw.webprice.domain.Price; +import com.techivw.webprice.infrastructure.repositories.PriceEntityJPARepository; +import com.techivw.webprice.infrastructure.repositories.mappers.PriceEntityMapper; +import com.techivw.webprice.infrastructure.repositories.model.PriceEntity; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; + +import java.time.LocalDateTime; +import java.util.Optional; + +@Service +@AllArgsConstructor +public class PriceRepositoryAdapter implements PriceRepositoryPort { + + private final PriceEntityJPARepository repository; + + @Override + public Optional findHighestPriorityPriceByDateTimeAndProductIdAndBrandId(LocalDateTime dateTime, Long productId, Long brandId) { + + Optional priceEntity = + repository.findPriceByDateTimeAndProductIdAndBrandId(dateTime, productId, brandId); + + return PriceEntityMapper.toOptionalPrice(priceEntity); + } +} diff --git a/infrastructure/out/sql-repository/src/main/java/com/techivw/webprice/infrastructure/repositories/mappers/PriceEntityMapper.java b/infrastructure/out/sql-repository/src/main/java/com/techivw/webprice/infrastructure/repositories/mappers/PriceEntityMapper.java new file mode 100644 index 0000000..7445cd9 --- /dev/null +++ b/infrastructure/out/sql-repository/src/main/java/com/techivw/webprice/infrastructure/repositories/mappers/PriceEntityMapper.java @@ -0,0 +1,28 @@ +package com.techivw.webprice.infrastructure.repositories.mappers; + +import com.techivw.webprice.domain.Price; +import com.techivw.webprice.infrastructure.repositories.model.PriceEntity; + +import java.util.Optional; + +public class PriceEntityMapper { + + public static Price toPrice(PriceEntity priceEntity) { + return Price.builder() + .id(priceEntity.getId()) + .brandId(priceEntity.getBrandId()) + .startDate(priceEntity.getStartDate()) + .endDate(priceEntity.getEndDate()) + .priceList(priceEntity.getPriceList()) + .productId(priceEntity.getProductId()) + .priority(priceEntity.getPriority()) + .price(priceEntity.getPrice()) + .currency(priceEntity.getCurrency()) + .build(); + } + + public static Optional toOptionalPrice(Optional priceEntity) { + return priceEntity.map(PriceEntityMapper::toPrice); + } + +} diff --git a/infrastructure/out/sql-repository/src/main/java/com/techivw/webprice/infrastructure/repositories/model/PriceEntity.java b/infrastructure/out/sql-repository/src/main/java/com/techivw/webprice/infrastructure/repositories/model/PriceEntity.java new file mode 100644 index 0000000..cba0dc6 --- /dev/null +++ b/infrastructure/out/sql-repository/src/main/java/com/techivw/webprice/infrastructure/repositories/model/PriceEntity.java @@ -0,0 +1,47 @@ +package com.techivw.webprice.infrastructure.repositories.model; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; + +import java.math.BigDecimal; +import java.time.LocalDateTime; + +@Entity +@Getter +@Setter +@Table(name = "prices") +public class PriceEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private Long id; + + @Column(name = "brand_id") + private Long brandId; + + @Column(name = "start_date") + @Temporal(TemporalType.TIMESTAMP) + private LocalDateTime startDate; + + @Column(name = "end_date") + @Temporal(TemporalType.TIMESTAMP) + private LocalDateTime endDate; + + @Column(name = "price_list") + private Long priceList; + + @Column(name = "product_id") + private Long productId; + + @Column(name = "priority") + private Integer priority; + + @Column(name = "price") + private BigDecimal price; + + @Column(name = "currency") + private String currency; + +} diff --git a/pom.xml b/pom.xml index 4a35e15..a8adf7a 100644 --- a/pom.xml +++ b/pom.xml @@ -38,13 +38,22 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-data-jpa + + + com.h2database + h2 + org.projectlombok lombok - org.springframework.boot - spring-boot-starter-data-jpa + org.springdoc + springdoc-openapi-starter-webmvc-ui + 2.8.6 -- 2.47.2 From 8dc84d21108bb08bc158b1dfbd42da203b8926c9 Mon Sep 17 00:00:00 2001 From: bedroomghost Date: Tue, 15 Apr 2025 20:31:32 +0200 Subject: [PATCH 05/10] fix: PriceResponse not properly parsed to json --- .../infrastructure/in/controllers/model/PriceResponse.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/model/PriceResponse.java b/infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/model/PriceResponse.java index 4c32826..563a46d 100644 --- a/infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/model/PriceResponse.java +++ b/infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/model/PriceResponse.java @@ -1,10 +1,12 @@ package com.techivw.webprice.infrastructure.in.controllers.model; import lombok.Builder; +import lombok.Data; import java.math.BigDecimal; import java.time.LocalDateTime; +@Data @Builder public class PriceResponse { -- 2.47.2 From f0fcbb588d18e864a7cc5eb867ea86c0db7c7034 Mon Sep 17 00:00:00 2001 From: bedroomghost Date: Tue, 15 Apr 2025 20:54:44 +0200 Subject: [PATCH 06/10] feat: Added exception handling for rest-api --- .../exceptions/NotFoundException.java | 8 ++++++ .../application/services/PriceService.java | 6 ++++- .../adapters/PriceControllerAdapter.java | 13 +++------ .../handlers/AdapterExceptionHandler.java | 27 +++++++++++++++++++ .../model/mappers/PriceResponseMapper.java | 18 +++++++++++++ 5 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 application/src/main/java/com/techivw/webprice/application/exceptions/NotFoundException.java create mode 100644 infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/handlers/AdapterExceptionHandler.java create mode 100644 infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/model/mappers/PriceResponseMapper.java diff --git a/application/src/main/java/com/techivw/webprice/application/exceptions/NotFoundException.java b/application/src/main/java/com/techivw/webprice/application/exceptions/NotFoundException.java new file mode 100644 index 0000000..d3b2145 --- /dev/null +++ b/application/src/main/java/com/techivw/webprice/application/exceptions/NotFoundException.java @@ -0,0 +1,8 @@ +package com.techivw.webprice.application.exceptions; + +public class NotFoundException extends RuntimeException { + + public NotFoundException(String message) { + super(message); + } +} diff --git a/application/src/main/java/com/techivw/webprice/application/services/PriceService.java b/application/src/main/java/com/techivw/webprice/application/services/PriceService.java index 247c416..eee1d41 100644 --- a/application/src/main/java/com/techivw/webprice/application/services/PriceService.java +++ b/application/src/main/java/com/techivw/webprice/application/services/PriceService.java @@ -1,5 +1,6 @@ package com.techivw.webprice.application.services; +import com.techivw.webprice.application.exceptions.NotFoundException; import com.techivw.webprice.application.ports.in.PriceServicePort; import com.techivw.webprice.application.ports.out.PriceRepositoryPort; import com.techivw.webprice.domain.Price; @@ -16,6 +17,9 @@ public class PriceService implements PriceServicePort { @Override public Price getPriceWithHighestPriorityByDateTimeAndProductIdAndBrandId(LocalDateTime dateTime, Long productId, Long brandId) { - return priceRepositoryPort.findHighestPriorityPriceByDateTimeAndProductIdAndBrandId(dateTime, productId, brandId).orElse(null); + return priceRepositoryPort.findHighestPriorityPriceByDateTimeAndProductIdAndBrandId(dateTime, productId, brandId) + .orElseThrow(() -> + new NotFoundException(String.format( + "Price for product %d of brand %d not found for date %s", productId, brandId, dateTime))); } } diff --git a/infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/adapters/PriceControllerAdapter.java b/infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/adapters/PriceControllerAdapter.java index cdb1c0f..f790640 100644 --- a/infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/adapters/PriceControllerAdapter.java +++ b/infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/adapters/PriceControllerAdapter.java @@ -3,6 +3,7 @@ package com.techivw.webprice.infrastructure.in.controllers.adapters; import com.techivw.webprice.application.ports.in.PriceServicePort; import com.techivw.webprice.domain.Price; import com.techivw.webprice.infrastructure.in.controllers.model.PriceResponse; +import com.techivw.webprice.infrastructure.in.controllers.model.mappers.PriceResponseMapper; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Content; @@ -35,8 +36,8 @@ public class PriceControllerAdapter { description = "Price information found", content = @Content(mediaType = "application/json", schema = @Schema(implementation = PriceResponse.class)) ) - @ApiResponse(responseCode = "404", description = "Price information not found for the given parameters") @ApiResponse(responseCode = "400", description = "Invalid request parameters") + @ApiResponse(responseCode = "404", description = "Price information not found for the given parameters") public ResponseEntity getPrice( @Parameter(description = "Date and time for price lookup (ISO format)", example = "2025-04-30T12:00:00") @RequestParam(name = "dateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime dateTime, @@ -46,14 +47,6 @@ public class PriceControllerAdapter { @RequestParam(name = "brandId") Long brandId) { Price price = priceServicePort.getPriceWithHighestPriorityByDateTimeAndProductIdAndBrandId(dateTime, productId, brandId); - PriceResponse priceResponse = PriceResponse.builder() - .productId(price.getProductId()) - .brandId(price.getBrandId()) - .priceList(price.getPriceList()) - .startDate(price.getStartDate()) - .endDate(price.getEndDate()) - .price(price.getPrice()) - .build(); - return ResponseEntity.ok(priceResponse); + return ResponseEntity.ok(PriceResponseMapper.fromPrice(price)); } } diff --git a/infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/handlers/AdapterExceptionHandler.java b/infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/handlers/AdapterExceptionHandler.java new file mode 100644 index 0000000..50b1daa --- /dev/null +++ b/infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/handlers/AdapterExceptionHandler.java @@ -0,0 +1,27 @@ +package com.techivw.webprice.infrastructure.in.controllers.handlers; + +import com.techivw.webprice.application.exceptions.NotFoundException; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +import static org.springframework.http.HttpStatus.NOT_FOUND; + +@RestControllerAdvice +public class AdapterExceptionHandler { + + @ExceptionHandler(NotFoundException.class) + public ResponseEntity> handleNotFoundException(NotFoundException ex) { + Map body = new HashMap<>(); + body.put("timestamp", new Date()); + body.put("status", NOT_FOUND.value()); + body.put("error", "Not Found"); + body.put("message", ex.getMessage()); + + return new ResponseEntity<>(body, NOT_FOUND); + } +} diff --git a/infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/model/mappers/PriceResponseMapper.java b/infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/model/mappers/PriceResponseMapper.java new file mode 100644 index 0000000..e938b07 --- /dev/null +++ b/infrastructure/in/rest-api/src/main/java/com/techivw/webprice/infrastructure/in/controllers/model/mappers/PriceResponseMapper.java @@ -0,0 +1,18 @@ +package com.techivw.webprice.infrastructure.in.controllers.model.mappers; + +import com.techivw.webprice.domain.Price; +import com.techivw.webprice.infrastructure.in.controllers.model.PriceResponse; + +public class PriceResponseMapper { + + public static PriceResponse fromPrice(Price price) { + return PriceResponse.builder() + .productId(price.getProductId()) + .brandId(price.getBrandId()) + .priceList(price.getPriceList()) + .startDate(price.getStartDate()) + .endDate(price.getEndDate()) + .price(price.getPrice()) + .build(); + } +} -- 2.47.2 From 7cd3b063bcd3210859af58462a7e510124d9197d Mon Sep 17 00:00:00 2001 From: bedroomghost Date: Tue, 15 Apr 2025 20:59:43 +0200 Subject: [PATCH 07/10] feat!: Added database migration support --- boot/src/main/resources/application.properties | 5 +++++ infrastructure/out/sql-repository/pom.xml | 9 +++++++++ .../sql/migration/V1__create_prices_table.sql | 11 +++++++++++ .../sql/migration/V2__insert_prices_data.sql | 6 ++++++ pom.xml | 4 ---- 5 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 infrastructure/out/sql-repository/sql/migration/V1__create_prices_table.sql create mode 100644 infrastructure/out/sql-repository/sql/migration/V2__insert_prices_data.sql diff --git a/boot/src/main/resources/application.properties b/boot/src/main/resources/application.properties index c02d384..1da086d 100644 --- a/boot/src/main/resources/application.properties +++ b/boot/src/main/resources/application.properties @@ -10,3 +10,8 @@ spring.jpa.database-platform=org.hibernate.dialect.H2Dialect # H2 console spring.h2.console.enabled=true spring.h2.console.path=/h2-console + +# Flyway +spring.flyway.enabled=true +spring.flyway.locations=filesystem:infrastructure/out/sql-repository/sql/migration +spring.flyway.baseline-on-migrate=true \ No newline at end of file diff --git a/infrastructure/out/sql-repository/pom.xml b/infrastructure/out/sql-repository/pom.xml index a15cfe6..334c736 100644 --- a/infrastructure/out/sql-repository/pom.xml +++ b/infrastructure/out/sql-repository/pom.xml @@ -26,6 +26,15 @@ application 0.0.1-SNAPSHOT + + org.flywaydb + flyway-maven-plugin + 11.7.1 + + + com.h2database + h2 + \ No newline at end of file diff --git a/infrastructure/out/sql-repository/sql/migration/V1__create_prices_table.sql b/infrastructure/out/sql-repository/sql/migration/V1__create_prices_table.sql new file mode 100644 index 0000000..301a730 --- /dev/null +++ b/infrastructure/out/sql-repository/sql/migration/V1__create_prices_table.sql @@ -0,0 +1,11 @@ +CREATE TABLE prices ( + id BIGINT AUTO_INCREMENT PRIMARY KEY, + brand_id BIGINT NOT NULL, + start_date TIMESTAMP NOT NULL, + end_date TIMESTAMP NOT NULL, + price_list BIGINT NOT NULL, + product_id BIGINT NOT NULL, + priority BIGINT NOT NULL, + price DECIMAL(10, 2) NOT NULL, + currency VARCHAR(3) +); \ No newline at end of file diff --git a/infrastructure/out/sql-repository/sql/migration/V2__insert_prices_data.sql b/infrastructure/out/sql-repository/sql/migration/V2__insert_prices_data.sql new file mode 100644 index 0000000..5ad9204 --- /dev/null +++ b/infrastructure/out/sql-repository/sql/migration/V2__insert_prices_data.sql @@ -0,0 +1,6 @@ +INSERT INTO prices (brand_id, start_date, end_date, price_list, product_id, priority, price, currency) +VALUES + (1, '2020-06-14 00:00:00', '2020-12-31 23:59:59', 1, 35455, 0, 35.50, 'EUR'), + (1, '2020-06-14 15:00:00', '2020-06-14 18:30:00', 2, 35455, 1, 25.45, 'EUR'), + (1, '2020-06-15 00:00:00', '2020-06-15 11:00:00', 3, 35455, 1, 30.50, 'EUR'), + (1, '2020-06-15 16:00:00', '2020-12-31 23:59:59', 4, 35455, 1, 38.95, 'EUR'); \ No newline at end of file diff --git a/pom.xml b/pom.xml index a8adf7a..60e4ead 100644 --- a/pom.xml +++ b/pom.xml @@ -42,10 +42,6 @@ org.springframework.boot spring-boot-starter-data-jpa - - com.h2database - h2 - org.projectlombok lombok -- 2.47.2 From 92871f081955ef0c67d9483084d312d307760783 Mon Sep 17 00:00:00 2001 From: bedroomghost Date: Sun, 20 Apr 2025 11:14:14 +0200 Subject: [PATCH 08/10] feat: Added defined endpoint test cases --- infrastructure/in/rest-api/pom.xml | 18 +++++ .../adapters/PriceControllerAdapterTest.java | 77 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 infrastructure/in/rest-api/src/test/java/com/techivw/webprice/infrastructure/in/controllers/adapters/PriceControllerAdapterTest.java diff --git a/infrastructure/in/rest-api/pom.xml b/infrastructure/in/rest-api/pom.xml index de49e08..9ad6546 100644 --- a/infrastructure/in/rest-api/pom.xml +++ b/infrastructure/in/rest-api/pom.xml @@ -16,6 +16,12 @@ rest-api + + org.springframework.boot + spring-boot-starter-test + test + + com.techivw domain @@ -28,4 +34,16 @@ + + + + org.apache.maven.plugins + maven-surefire-plugin + + -javaagent:${settings.localRepository}/net/bytebuddy/byte-buddy-agent/1.15.11/byte-buddy-agent-1.15.11.jar + + + + + diff --git a/infrastructure/in/rest-api/src/test/java/com/techivw/webprice/infrastructure/in/controllers/adapters/PriceControllerAdapterTest.java b/infrastructure/in/rest-api/src/test/java/com/techivw/webprice/infrastructure/in/controllers/adapters/PriceControllerAdapterTest.java new file mode 100644 index 0000000..d2b6079 --- /dev/null +++ b/infrastructure/in/rest-api/src/test/java/com/techivw/webprice/infrastructure/in/controllers/adapters/PriceControllerAdapterTest.java @@ -0,0 +1,77 @@ +package com.techivw.webprice.infrastructure.in.controllers.adapters; + +import com.techivw.webprice.application.ports.in.PriceServicePort; +import com.techivw.webprice.domain.Price; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.bean.override.mockito.MockitoBean; +import org.springframework.test.web.servlet.MockMvc; + +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.stream.Stream; + +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@WebMvcTest +@ContextConfiguration(classes = PriceControllerAdapter.class) +@ActiveProfiles("test") +public class PriceControllerAdapterTest { + + @Autowired + private MockMvc mockMvc; + + @MockitoBean + private PriceServicePort priceServicePort; + + private static final Long PRODUCT_ID = 35455L; + private static final Long BRAND_ID = 1L; + + @ParameterizedTest + @MethodSource("testCases") + void testGetPrice(String testName, String dateTime, double expectedPrice) throws Exception { + LocalDateTime date = LocalDateTime.parse(dateTime); + + Price mockPrice = createPrice(date.minusHours(1), date.plusHours(1), 1, expectedPrice, 1); + when(priceServicePort.getPriceWithHighestPriorityByDateTimeAndProductIdAndBrandId(date, PRODUCT_ID, BRAND_ID)) + .thenReturn(mockPrice); + + mockMvc.perform(get("/price") + .param("dateTime", dateTime) + .param("productId", String.valueOf(PRODUCT_ID)) + .param("brandId", String.valueOf(BRAND_ID))) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.price").value(expectedPrice)); + } + + private static Stream testCases() { + return Stream.of( + Arguments.of("Test 1", "2020-06-14T10:00:00", 35.50), + Arguments.of("Test 2", "2020-06-14T16:00:00", 25.45), + Arguments.of("Test 3", "2020-06-14T21:00:00", 35.50), + Arguments.of("Test 4", "2020-06-15T10:00:00", 30.50), + Arguments.of("Test 5", "2020-06-16T21:00:00", 38.95) + ); + } + + private Price createPrice(LocalDateTime startDate, LocalDateTime endDate, long priceList, double price, int priority) { + return Price.builder() + .brandId(BRAND_ID) + .productId(PRODUCT_ID) + .startDate(startDate) + .endDate(endDate) + .priceList(priceList) + .price(BigDecimal.valueOf(price)) + .priority(priority) + .currency("EUR") + .build(); + } +} \ No newline at end of file -- 2.47.2 From 18866635ab8e8748bcb9e4bafb341265539ab53d Mon Sep 17 00:00:00 2001 From: bedroomghost Date: Sun, 20 Apr 2025 18:02:22 +0200 Subject: [PATCH 09/10] test: Add unit tests for PriceService and PriceRepositoryAdapter --- README.md | 33 +++++++- .../services/PriceServiceTest.java | 77 ++++++++++++++++++ infrastructure/in/rest-api/pom.xml | 18 ----- .../adapters/PriceRepositoryAdapterTest.java | 78 +++++++++++++++++++ pom.xml | 18 +++++ 5 files changed, 205 insertions(+), 19 deletions(-) create mode 100644 application/src/test/java/com/techivw/webprice/application/services/PriceServiceTest.java create mode 100644 infrastructure/out/sql-repository/src/test/java/com/techivw/webprice/infrastructure/repositories/adapters/PriceRepositoryAdapterTest.java diff --git a/README.md b/README.md index 91bc1cd..cb70863 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,33 @@ -# web-price +Prices web service (web-price) +=================================== +Web service for obtaining the price of a product given a date, the product id and the brand id. + +## Requirements + +- Java 21 +- Maven + +## Development + +1. Local installation of the project + ``` + mvn clean install + ``` +2. Run the app from the project root with: + ``` + mvn clean spring-boot:run -pl boot -Dspring-boot.run.profiles=local + ``` + or navigating to the `boot` directory of the project: + ``` + mvn clean spring-boot:run -Dspring-boot.run.profiles=local + ``` +3. Service should be ready to receive requests at http://localhost:8080/price with OpenAPI docs available at http://localhost:8080/swagger-ui/index.html + +## Running Tests + +To run all tests in the project: + +```bash +mvn test +``` diff --git a/application/src/test/java/com/techivw/webprice/application/services/PriceServiceTest.java b/application/src/test/java/com/techivw/webprice/application/services/PriceServiceTest.java new file mode 100644 index 0000000..2a61a80 --- /dev/null +++ b/application/src/test/java/com/techivw/webprice/application/services/PriceServiceTest.java @@ -0,0 +1,77 @@ +package com.techivw.webprice.application.services; + +import com.techivw.webprice.application.exceptions.NotFoundException; +import com.techivw.webprice.application.ports.in.PriceServicePort; +import com.techivw.webprice.application.ports.out.PriceRepositoryPort; +import com.techivw.webprice.domain.Price; + +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.Optional; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.when; + +@ExtendWith(SpringExtension.class) +class PriceServiceTest { + + @Mock + private PriceRepositoryPort priceRepositoryPort; + + private PriceServicePort priceService; + + private final LocalDateTime TEST_DATE = LocalDateTime.parse("2023-01-01T12:00:00"); + private final Long TEST_PRODUCT_ID = 35455L; + private final Long TEST_BRAND_ID = 1L; + + @BeforeEach + void setUp() { + priceService = new PriceService(priceRepositoryPort); + } + + @Test + void shouldReturnPriceWhenPriceExists() { + Price expectedPrice = createPrice(); + when(priceRepositoryPort.findHighestPriorityPriceByDateTimeAndProductIdAndBrandId( + eq(TEST_DATE), eq(TEST_PRODUCT_ID), eq(TEST_BRAND_ID))) + .thenReturn(Optional.of(expectedPrice)); + + Price result = priceService.getPriceWithHighestPriorityByDateTimeAndProductIdAndBrandId( + TEST_DATE, TEST_PRODUCT_ID, TEST_BRAND_ID); + + assertNotNull(result); + assertEquals(expectedPrice.getProductId(), result.getProductId()); + assertEquals(expectedPrice.getPrice(), result.getPrice()); + } + + @Test + void shouldThrowNotFoundExceptionWhenPriceDoesNotExist() { + when(priceRepositoryPort.findHighestPriorityPriceByDateTimeAndProductIdAndBrandId( + any(LocalDateTime.class), anyLong(), anyLong())) + .thenReturn(Optional.empty()); + + assertThrows(NotFoundException.class, () -> + priceService.getPriceWithHighestPriorityByDateTimeAndProductIdAndBrandId( + TEST_DATE, TEST_PRODUCT_ID, TEST_BRAND_ID)); + } + + private Price createPrice() { + return Price.builder() + .brandId(TEST_BRAND_ID) + .productId(TEST_PRODUCT_ID) + .startDate(TEST_DATE.minusDays(1)) + .endDate(TEST_DATE.plusDays(1)) + .priceList(1L) + .price(BigDecimal.valueOf(35.50)) + .priority(1) + .currency("EUR") + .build(); + } +} \ No newline at end of file diff --git a/infrastructure/in/rest-api/pom.xml b/infrastructure/in/rest-api/pom.xml index 9ad6546..de49e08 100644 --- a/infrastructure/in/rest-api/pom.xml +++ b/infrastructure/in/rest-api/pom.xml @@ -16,12 +16,6 @@ rest-api - - org.springframework.boot - spring-boot-starter-test - test - - com.techivw domain @@ -34,16 +28,4 @@ - - - - org.apache.maven.plugins - maven-surefire-plugin - - -javaagent:${settings.localRepository}/net/bytebuddy/byte-buddy-agent/1.15.11/byte-buddy-agent-1.15.11.jar - - - - - diff --git a/infrastructure/out/sql-repository/src/test/java/com/techivw/webprice/infrastructure/repositories/adapters/PriceRepositoryAdapterTest.java b/infrastructure/out/sql-repository/src/test/java/com/techivw/webprice/infrastructure/repositories/adapters/PriceRepositoryAdapterTest.java new file mode 100644 index 0000000..a260ca5 --- /dev/null +++ b/infrastructure/out/sql-repository/src/test/java/com/techivw/webprice/infrastructure/repositories/adapters/PriceRepositoryAdapterTest.java @@ -0,0 +1,78 @@ +package com.techivw.webprice.infrastructure.repositories.adapters; + +import com.techivw.webprice.domain.Price; +import com.techivw.webprice.infrastructure.repositories.PriceEntityJPARepository; +import com.techivw.webprice.infrastructure.repositories.model.PriceEntity; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +class PriceRepositoryAdapterTest { + + @Mock + private PriceEntityJPARepository repository; + + private PriceRepositoryAdapter adapter; + + private final LocalDateTime TEST_DATE = LocalDateTime.parse("2023-01-01T12:00:00"); + private final Long TEST_PRODUCT_ID = 35455L; + private final Long TEST_BRAND_ID = 1L; + + @BeforeEach + void setUp() { + adapter = new PriceRepositoryAdapter(repository); + } + + @Test + void shouldReturnPriceWhenPriceEntityExists() { + PriceEntity priceEntity = createSamplePriceEntity(); + when(repository.findPriceByDateTimeAndProductIdAndBrandId( + eq(TEST_DATE), eq(TEST_PRODUCT_ID), eq(TEST_BRAND_ID))) + .thenReturn(Optional.of(priceEntity)); + + Optional result = adapter.findHighestPriorityPriceByDateTimeAndProductIdAndBrandId( + TEST_DATE, TEST_PRODUCT_ID, TEST_BRAND_ID); + + assertTrue(result.isPresent()); + Price price = result.get(); + assertEquals(TEST_PRODUCT_ID, price.getProductId()); + assertEquals(TEST_BRAND_ID, price.getBrandId()); + assertEquals(BigDecimal.valueOf(35.50), price.getPrice()); + } + + @Test + void shouldReturnEmptyOptionalWhenPriceEntityDoesNotExist() { + when(repository.findPriceByDateTimeAndProductIdAndBrandId( + any(LocalDateTime.class), anyLong(), anyLong())) + .thenReturn(Optional.empty()); + + Optional result = adapter.findHighestPriorityPriceByDateTimeAndProductIdAndBrandId( + TEST_DATE, TEST_PRODUCT_ID, TEST_BRAND_ID); + + assertFalse(result.isPresent()); + } + + private PriceEntity createSamplePriceEntity() { + PriceEntity entity = new PriceEntity(); + entity.setBrandId(TEST_BRAND_ID); + entity.setProductId(TEST_PRODUCT_ID); + entity.setStartDate(TEST_DATE.minusDays(1)); + entity.setEndDate(TEST_DATE.plusDays(1)); + entity.setPriceList(1L); + entity.setPrice(BigDecimal.valueOf(35.50)); + entity.setPriority(1); + entity.setCurrency("EUR"); + return entity; + } +} diff --git a/pom.xml b/pom.xml index 60e4ead..13ffae0 100644 --- a/pom.xml +++ b/pom.xml @@ -51,5 +51,23 @@ springdoc-openapi-starter-webmvc-ui 2.8.6 + + org.springframework.boot + spring-boot-starter-test + test + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + -javaagent:${settings.localRepository}/net/bytebuddy/byte-buddy-agent/1.15.11/byte-buddy-agent-1.15.11.jar + + + + + -- 2.47.2 From 13826758605b23fdff291184a062f82ce660f1fc Mon Sep 17 00:00:00 2001 From: bedroomghost Date: Sun, 20 Apr 2025 18:05:56 +0200 Subject: [PATCH 10/10] chore(release): v1.0 --- application/pom.xml | 4 ++-- boot/pom.xml | 10 +++++----- domain/pom.xml | 2 +- infrastructure/in/rest-api/pom.xml | 6 +++--- infrastructure/out/sql-repository/pom.xml | 6 +++--- pom.xml | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/application/pom.xml b/application/pom.xml index ff5fe0d..6487922 100644 --- a/application/pom.xml +++ b/application/pom.xml @@ -11,7 +11,7 @@ com.techivw web-price - 0.0.1-SNAPSHOT + 1.0-RELEASE @@ -19,7 +19,7 @@ com.techivw domain - 0.0.1-SNAPSHOT + 1.0-RELEASE diff --git a/boot/pom.xml b/boot/pom.xml index 0f47e93..a27a6b9 100644 --- a/boot/pom.xml +++ b/boot/pom.xml @@ -7,7 +7,7 @@ com.techivw web-price - 0.0.1-SNAPSHOT + 1.0-RELEASE @@ -20,22 +20,22 @@ com.techivw domain - 0.0.1-SNAPSHOT + 1.0-RELEASE com.techivw application - 0.0.1-SNAPSHOT + 1.0-RELEASE com.techivw rest-api - 0.0.1-SNAPSHOT + 1.0-RELEASE com.techivw sql-repository - 0.0.1-SNAPSHOT + 1.0-RELEASE diff --git a/domain/pom.xml b/domain/pom.xml index 95acb5d..ab35c2d 100644 --- a/domain/pom.xml +++ b/domain/pom.xml @@ -11,6 +11,6 @@ com.techivw web-price - 0.0.1-SNAPSHOT + 1.0-RELEASE diff --git a/infrastructure/in/rest-api/pom.xml b/infrastructure/in/rest-api/pom.xml index de49e08..5826199 100644 --- a/infrastructure/in/rest-api/pom.xml +++ b/infrastructure/in/rest-api/pom.xml @@ -7,7 +7,7 @@ com.techivw web-price - 0.0.1-SNAPSHOT + 1.0-RELEASE ../../../pom.xml @@ -19,12 +19,12 @@ com.techivw domain - 0.0.1-SNAPSHOT + 1.0-RELEASE com.techivw application - 0.0.1-SNAPSHOT + 1.0-RELEASE diff --git a/infrastructure/out/sql-repository/pom.xml b/infrastructure/out/sql-repository/pom.xml index 334c736..9b9a268 100644 --- a/infrastructure/out/sql-repository/pom.xml +++ b/infrastructure/out/sql-repository/pom.xml @@ -11,7 +11,7 @@ com.techivw web-price - 0.0.1-SNAPSHOT + 1.0-RELEASE ../../../pom.xml @@ -19,12 +19,12 @@ com.techivw domain - 0.0.1-SNAPSHOT + 1.0-RELEASE com.techivw application - 0.0.1-SNAPSHOT + 1.0-RELEASE org.flywaydb diff --git a/pom.xml b/pom.xml index 13ffae0..dd1734c 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ com.techivw web-price - 0.0.1-SNAPSHOT + 1.0-RELEASE pom web-price -- 2.47.2