diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 00000000..13566b81
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 00000000..755d7ed5
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 00000000..b7843190
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/homework-java-ironlibrary.iml b/.idea/homework-java-ironlibrary.iml
new file mode 100644
index 00000000..d6ebd480
--- /dev/null
+++ b/.idea/homework-java-ironlibrary.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 00000000..712ab9d9
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 00000000..8d72d9d5
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 00000000..821fdf28
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 00000000..83067447
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/homework/.gitattributes b/homework/.gitattributes
new file mode 100644
index 00000000..3b41682a
--- /dev/null
+++ b/homework/.gitattributes
@@ -0,0 +1,2 @@
+/mvnw text eol=lf
+*.cmd text eol=crlf
diff --git a/homework/.gitignore b/homework/.gitignore
new file mode 100644
index 00000000..667aaef0
--- /dev/null
+++ b/homework/.gitignore
@@ -0,0 +1,33 @@
+HELP.md
+target/
+.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
diff --git a/homework/.mvn/wrapper/maven-wrapper.properties b/homework/.mvn/wrapper/maven-wrapper.properties
new file mode 100644
index 00000000..c595b009
--- /dev/null
+++ b/homework/.mvn/wrapper/maven-wrapper.properties
@@ -0,0 +1,3 @@
+wrapperVersion=3.3.4
+distributionType=only-script
+distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.14/apache-maven-3.9.14-bin.zip
diff --git a/homework/mvnw b/homework/mvnw
new file mode 100755
index 00000000..bd8896bf
--- /dev/null
+++ b/homework/mvnw
@@ -0,0 +1,295 @@
+#!/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.4
+#
+# 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:]'
+}
+
+scriptDir="$(dirname "$0")"
+scriptName="$(basename "$0")"
+
+# 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 <"$scriptDir/.mvn/wrapper/maven-wrapper.properties"
+[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.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${scriptName#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
+
+# Find the actual extracted directory name (handles snapshots where filename != directory name)
+actualDistributionDir=""
+
+# First try the expected directory name (for regular distributions)
+if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then
+ if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then
+ actualDistributionDir="$distributionUrlNameMain"
+ fi
+fi
+
+# If not found, search for any directory with the Maven executable (for snapshots)
+if [ -z "$actualDistributionDir" ]; then
+ # enable globbing to iterate over items
+ set +f
+ for dir in "$TMP_DOWNLOAD_DIR"/*; do
+ if [ -d "$dir" ]; then
+ if [ -f "$dir/bin/$MVN_CMD" ]; then
+ actualDistributionDir="$(basename "$dir")"
+ break
+ fi
+ fi
+ done
+ set -f
+fi
+
+if [ -z "$actualDistributionDir" ]; then
+ verbose "Contents of $TMP_DOWNLOAD_DIR:"
+ verbose "$(ls -la "$TMP_DOWNLOAD_DIR")"
+ die "Could not find Maven distribution directory in extracted archive"
+fi
+
+verbose "Found extracted Maven distribution directory: $actualDistributionDir"
+printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url"
+mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
+
+clean || :
+exec_maven "$@"
diff --git a/homework/mvnw.cmd b/homework/mvnw.cmd
new file mode 100644
index 00000000..92450f93
--- /dev/null
+++ b/homework/mvnw.cmd
@@ -0,0 +1,189 @@
+<# : 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.4
+@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 -eq $False) { "/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_M2_PATH = "$HOME/.m2"
+if ($env:MAVEN_USER_HOME) {
+ $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME"
+}
+
+if (-not (Test-Path -Path $MAVEN_M2_PATH)) {
+ New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null
+}
+
+$MAVEN_WRAPPER_DISTS = $null
+if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) {
+ $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists"
+} else {
+ $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists"
+}
+
+$MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain"
+$MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::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
+
+# Find the actual extracted directory name (handles snapshots where filename != directory name)
+$actualDistributionDir = ""
+
+# First try the expected directory name (for regular distributions)
+$expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain"
+$expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD"
+if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) {
+ $actualDistributionDir = $distributionUrlNameMain
+}
+
+# If not found, search for any directory with the Maven executable (for snapshots)
+if (!$actualDistributionDir) {
+ Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object {
+ $testPath = Join-Path $_.FullName "bin/$MVN_CMD"
+ if (Test-Path -Path $testPath -PathType Leaf) {
+ $actualDistributionDir = $_.Name
+ }
+ }
+}
+
+if (!$actualDistributionDir) {
+ Write-Error "Could not find Maven distribution directory in extracted archive"
+}
+
+Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir"
+Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -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/homework/pom.xml b/homework/pom.xml
new file mode 100644
index 00000000..660f2c2e
--- /dev/null
+++ b/homework/pom.xml
@@ -0,0 +1,118 @@
+
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 4.0.5
+
+
+ org.example
+ homework
+ 0.0.1-SNAPSHOT
+ homework
+ homework
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 21
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-jpa
+
+
+ org.springframework.boot
+ spring-boot-starter-webmvc
+
+
+
+ org.projectlombok
+ lombok
+ true
+
+
+ org.springframework.boot
+ spring-boot-starter-data-jpa-test
+ test
+
+
+ org.springframework.boot
+ spring-boot-starter-webmvc-test
+ test
+
+
+ jakarta.validation
+ jakarta.validation-api
+ 3.1.1
+ compile
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ default-compile
+ compile
+
+ compile
+
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+
+
+ default-testCompile
+ test-compile
+
+ testCompile
+
+
+
+
+ org.projectlombok
+ lombok
+
+
+
+
+
+
+
+
+
+
diff --git a/homework/src/main/java/org/example/homework/DTO/request/AddBookRequest.java b/homework/src/main/java/org/example/homework/DTO/request/AddBookRequest.java
new file mode 100644
index 00000000..b3b0ab28
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/DTO/request/AddBookRequest.java
@@ -0,0 +1,16 @@
+package org.example.homework.DTO.request;
+
+import jakarta.validation.constraints.Email;
+import jakarta.validation.constraints.Min;
+import jakarta.validation.constraints.NotBlank;
+import jakarta.validation.constraints.NotNull;
+
+public record AddBookRequest(
+ @NotBlank String isbn,
+ @NotBlank String title,
+ @NotBlank String category,
+ @NotNull @Min(1) Integer quantity,
+ @NotBlank String authorName,
+ @NotBlank @Email String authorEmail
+) {
+}
diff --git a/homework/src/main/java/org/example/homework/DTO/request/IssueBookRequest.java b/homework/src/main/java/org/example/homework/DTO/request/IssueBookRequest.java
new file mode 100644
index 00000000..dd10301a
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/DTO/request/IssueBookRequest.java
@@ -0,0 +1,10 @@
+package org.example.homework.DTO.request;
+
+import jakarta.validation.constraints.NotBlank;
+
+public record IssueBookRequest(
+ @NotBlank String usn,
+ @NotBlank String studentName,
+ @NotBlank String bookIsbn
+) {
+}
\ No newline at end of file
diff --git a/homework/src/main/java/org/example/homework/DTO/response/BookResponse.java b/homework/src/main/java/org/example/homework/DTO/response/BookResponse.java
new file mode 100644
index 00000000..1b21bb8a
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/DTO/response/BookResponse.java
@@ -0,0 +1,11 @@
+package org.example.homework.DTO.response;
+
+public record BookResponse(
+ String isbn,
+ String title,
+ String category,
+ Integer quantity,
+ String authorName,
+ String authorEmail
+) {
+}
diff --git a/homework/src/main/java/org/example/homework/DTO/response/IssueResponse.java b/homework/src/main/java/org/example/homework/DTO/response/IssueResponse.java
new file mode 100644
index 00000000..f7965675
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/DTO/response/IssueResponse.java
@@ -0,0 +1,15 @@
+package org.example.homework.DTO.response;
+
+
+import java.time.LocalDate;
+
+public record IssueResponse(
+ Integer issueId,
+ String studentUsn,
+ String studentName,
+ String bookIsbn,
+ String bookTitle,
+ LocalDate issueDate,
+ LocalDate returnDate
+) {
+}
\ No newline at end of file
diff --git a/homework/src/main/java/org/example/homework/DTO/response/IssuedBookResponse.java b/homework/src/main/java/org/example/homework/DTO/response/IssuedBookResponse.java
new file mode 100644
index 00000000..33bf8868
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/DTO/response/IssuedBookResponse.java
@@ -0,0 +1,11 @@
+package org.example.homework.DTO.response;
+
+
+import java.time.LocalDate;
+
+public record IssuedBookResponse(
+ String bookTitle,
+ String studentName,
+ LocalDate returnDate
+) {
+}
diff --git a/homework/src/main/java/org/example/homework/HomeworkApplication.java b/homework/src/main/java/org/example/homework/HomeworkApplication.java
new file mode 100644
index 00000000..d783523d
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/HomeworkApplication.java
@@ -0,0 +1,13 @@
+package org.example.homework;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class HomeworkApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(HomeworkApplication.class, args);
+ }
+
+}
diff --git a/homework/src/main/java/org/example/homework/controller/BookController.java b/homework/src/main/java/org/example/homework/controller/BookController.java
new file mode 100644
index 00000000..199c10b7
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/controller/BookController.java
@@ -0,0 +1,51 @@
+package org.example.homework.controller;
+
+
+import jakarta.validation.Valid;
+import lombok.RequiredArgsConstructor;
+import org.example.homework.DTO.request.AddBookRequest;
+import org.example.homework.DTO.response.BookResponse;
+import org.example.homework.service.BookService;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/api/books")
+@RequiredArgsConstructor
+public class BookController {
+
+ private final BookService bookService;
+
+ @PostMapping
+ public ResponseEntity addBook(@RequestBody @Valid AddBookRequest request) {
+ BookResponse response = bookService.addBook(request);
+ return ResponseEntity.status(HttpStatus.CREATED).body(response);
+ }
+
+ @GetMapping("/search/title")
+ public ResponseEntity> searchByTitle(@RequestParam String title) {
+ List response = bookService.searchByTitle(title);
+ return ResponseEntity.ok(response);
+ }
+
+ @GetMapping("/search/category")
+ public ResponseEntity> searchByCategory(@RequestParam String category) {
+ List response = bookService.searchByCategory(category);
+ return ResponseEntity.ok(response);
+ }
+
+ @GetMapping("/search/author")
+ public ResponseEntity> searchByAuthor(@RequestParam String name) {
+ List response = bookService.searchByAuthor(name);
+ return ResponseEntity.ok(response);
+ }
+
+ @GetMapping
+ public ResponseEntity> getAllBooksWithAuthors() {
+ List response = bookService.getAllBooksWithAuthors();
+ return ResponseEntity.ok(response);
+ }
+}
\ No newline at end of file
diff --git a/homework/src/main/java/org/example/homework/controller/IssueController.java b/homework/src/main/java/org/example/homework/controller/IssueController.java
new file mode 100644
index 00000000..62a58819
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/controller/IssueController.java
@@ -0,0 +1,33 @@
+package org.example.homework.controller;
+
+import jakarta.validation.Valid;
+import lombok.RequiredArgsConstructor;
+import org.example.homework.DTO.request.IssueBookRequest;
+import org.example.homework.DTO.response.IssueResponse;
+import org.example.homework.DTO.response.IssuedBookResponse;
+import org.example.homework.service.IssueService;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/api/issues")
+@RequiredArgsConstructor
+public class IssueController {
+
+ private final IssueService issueService;
+
+ @PostMapping
+ public ResponseEntity issueBook(@RequestBody @Valid IssueBookRequest request) {
+ IssueResponse response = issueService.issueBook(request);
+ return ResponseEntity.status(HttpStatus.CREATED).body(response);
+ }
+
+ @GetMapping("/student/{usn}")
+ public ResponseEntity> getBooksByUsn(@PathVariable String usn) {
+ List response = issueService.getBooksByUsn(usn);
+ return ResponseEntity.ok(response);
+ }
+}
diff --git a/homework/src/main/java/org/example/homework/entity/Author.java b/homework/src/main/java/org/example/homework/entity/Author.java
new file mode 100644
index 00000000..daca4f2c
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/entity/Author.java
@@ -0,0 +1,34 @@
+package org.example.homework.entity;
+
+import jakarta.persistence.*;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Entity
+@Table(name = "authors")
+@AllArgsConstructor
+@NoArgsConstructor
+@Data
+public class Author {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Integer authorId;
+
+ @Column(nullable = false)
+ private String name;
+
+ @Column(nullable = false)
+ private String email;
+
+ @OneToOne
+ @JoinColumn(name = "book_isbn", referencedColumnName = "isbn", unique = true)
+ private Book authorBook;
+
+ public Author(String name, String email, Book authorBook) {
+ this.name = name;
+ this.email = email;
+ this.authorBook = authorBook;
+ }
+}
diff --git a/homework/src/main/java/org/example/homework/entity/Book.java b/homework/src/main/java/org/example/homework/entity/Book.java
new file mode 100644
index 00000000..d1da5817
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/entity/Book.java
@@ -0,0 +1,27 @@
+package org.example.homework.entity;
+
+import jakarta.persistence.*;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Entity
+@Table(name = "books")
+@AllArgsConstructor
+@NoArgsConstructor
+@Data
+public class Book {
+
+ @Id
+ private String isbn;
+
+ @Column(nullable = false)
+ private String title;
+
+ @Column(nullable = false)
+ private String category;
+
+ @Column(nullable = false)
+ private Integer quantity;
+
+}
diff --git a/homework/src/main/java/org/example/homework/entity/Issue.java b/homework/src/main/java/org/example/homework/entity/Issue.java
new file mode 100644
index 00000000..c1d566a1
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/entity/Issue.java
@@ -0,0 +1,34 @@
+package org.example.homework.entity;
+
+import jakarta.persistence.*;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.time.LocalDate;
+
+@Entity
+@Table(name = "issues")
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class Issue {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Integer issueId;
+
+ @Column(nullable = false)
+ private LocalDate issueDate;
+
+ @Column(nullable = false)
+ private LocalDate returnDate;
+
+ @ManyToOne(optional = false)
+ @JoinColumn(name = "student_usn", referencedColumnName = "usn")
+ private Student issueStudent;
+
+ @ManyToOne(optional = false)
+ @JoinColumn(name = "book_isbn", referencedColumnName = "isbn")
+ private Book issueBook;
+}
diff --git a/homework/src/main/java/org/example/homework/entity/Student.java b/homework/src/main/java/org/example/homework/entity/Student.java
new file mode 100644
index 00000000..3f93fc1d
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/entity/Student.java
@@ -0,0 +1,25 @@
+package org.example.homework.entity;
+
+import jakarta.persistence.Column;
+import jakarta.persistence.Entity;
+import jakarta.persistence.Id;
+import jakarta.persistence.Table;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Entity
+@Table(name = "students")
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+public class Student {
+
+ @Id
+ private String usn;
+
+ @Column(nullable = false)
+ private String name;
+}
diff --git a/homework/src/main/java/org/example/homework/exceptions/GlobalExceptionHandler.java b/homework/src/main/java/org/example/homework/exceptions/GlobalExceptionHandler.java
new file mode 100644
index 00000000..243f5610
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/exceptions/GlobalExceptionHandler.java
@@ -0,0 +1,46 @@
+package org.example.homework.exceptions;
+
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ProblemDetail;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+@RestControllerAdvice
+public class GlobalExceptionHandler {
+
+ @ExceptionHandler(ResourceNotFoundException.class)
+ public ProblemDetail handleNotFound(ResourceNotFoundException ex) {
+ ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail(HttpStatus.NOT_FOUND, ex.getMessage());
+ problemDetail.setTitle("Resource Not Found");
+ return problemDetail;
+ }
+
+ @ExceptionHandler(ResourceAlreadyExistsException.class)
+ public ProblemDetail handleAlreadyExists(ResourceAlreadyExistsException ex) {
+ ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail(HttpStatus.CONFLICT, ex.getMessage());
+ problemDetail.setTitle("Resource Already Exists");
+ return problemDetail;
+ }
+
+ @ExceptionHandler(InsufficientQuantityException.class)
+ public ProblemDetail handleInsufficientQuantity(InsufficientQuantityException ex) {
+ ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail(HttpStatus.BAD_REQUEST, ex.getMessage());
+ problemDetail.setTitle("Insufficient Quantity");
+ return problemDetail;
+ }
+
+ @ExceptionHandler(MethodArgumentNotValidException.class)
+ public ProblemDetail handleValidation(MethodArgumentNotValidException ex) {
+ String message = ex.getBindingResult()
+ .getFieldErrors()
+ .stream()
+ .findFirst()
+ .map(error -> error.getField() + " " + error.getDefaultMessage())
+ .orElse("Validation error");
+
+ ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail(HttpStatus.BAD_REQUEST, message);
+ problemDetail.setTitle("Validation Error");
+ return problemDetail;
+ }
+}
diff --git a/homework/src/main/java/org/example/homework/exceptions/InsufficientQuantityException.java b/homework/src/main/java/org/example/homework/exceptions/InsufficientQuantityException.java
new file mode 100644
index 00000000..8c3b5f43
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/exceptions/InsufficientQuantityException.java
@@ -0,0 +1,7 @@
+package org.example.homework.exceptions;
+
+public class InsufficientQuantityException extends RuntimeException {
+ public InsufficientQuantityException(String message) {
+ super(message);
+ }
+}
diff --git a/homework/src/main/java/org/example/homework/exceptions/ResourceAlreadyExistsException.java b/homework/src/main/java/org/example/homework/exceptions/ResourceAlreadyExistsException.java
new file mode 100644
index 00000000..8cb1588d
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/exceptions/ResourceAlreadyExistsException.java
@@ -0,0 +1,7 @@
+package org.example.homework.exceptions;
+
+public class ResourceAlreadyExistsException extends RuntimeException {
+ public ResourceAlreadyExistsException(String message) {
+ super(message);
+ }
+}
diff --git a/homework/src/main/java/org/example/homework/exceptions/ResourceNotFoundException.java b/homework/src/main/java/org/example/homework/exceptions/ResourceNotFoundException.java
new file mode 100644
index 00000000..a32790d4
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/exceptions/ResourceNotFoundException.java
@@ -0,0 +1,7 @@
+package org.example.homework.exceptions;
+
+public class ResourceNotFoundException extends RuntimeException {
+ public ResourceNotFoundException(String message) {
+ super(message);
+ }
+}
diff --git a/homework/src/main/java/org/example/homework/repository/AuthorRepository.java b/homework/src/main/java/org/example/homework/repository/AuthorRepository.java
new file mode 100644
index 00000000..75c9fcff
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/repository/AuthorRepository.java
@@ -0,0 +1,14 @@
+package org.example.homework.repository;
+
+import org.example.homework.entity.Author;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+import java.util.Optional;
+
+@Repository
+public interface AuthorRepository extends JpaRepository {
+ List findByNameContainingIgnoreCase(String name);
+ Optional findByAuthorBookIsbn(String isbn);
+}
diff --git a/homework/src/main/java/org/example/homework/repository/BookRepository.java b/homework/src/main/java/org/example/homework/repository/BookRepository.java
new file mode 100644
index 00000000..f5236c1b
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/repository/BookRepository.java
@@ -0,0 +1,13 @@
+package org.example.homework.repository;
+
+import org.example.homework.entity.Book;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface BookRepository extends JpaRepository {
+ List findByTitleContainingIgnoreCase(String title);
+ List findByCategoryContainingIgnoreCase(String category);
+}
\ No newline at end of file
diff --git a/homework/src/main/java/org/example/homework/repository/IssueRepository.java b/homework/src/main/java/org/example/homework/repository/IssueRepository.java
new file mode 100644
index 00000000..27771695
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/repository/IssueRepository.java
@@ -0,0 +1,12 @@
+package org.example.homework.repository;
+import org.example.homework.entity.Issue;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+import java.awt.print.Book;
+import java.util.List;
+
+@Repository
+public interface IssueRepository extends JpaRepository {
+ List findByIssueStudentUsn(String usn);
+}
\ No newline at end of file
diff --git a/homework/src/main/java/org/example/homework/repository/StudentRepository.java b/homework/src/main/java/org/example/homework/repository/StudentRepository.java
new file mode 100644
index 00000000..6d6504ac
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/repository/StudentRepository.java
@@ -0,0 +1,9 @@
+package org.example.homework.repository;
+
+import org.example.homework.entity.Student;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface StudentRepository extends JpaRepository {
+}
diff --git a/homework/src/main/java/org/example/homework/service/BookService.java b/homework/src/main/java/org/example/homework/service/BookService.java
new file mode 100644
index 00000000..813191bb
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/service/BookService.java
@@ -0,0 +1,20 @@
+package org.example.homework.service;
+
+
+import org.example.homework.DTO.request.AddBookRequest;
+import org.example.homework.DTO.response.BookResponse;
+
+import java.util.List;
+
+public interface BookService {
+
+ BookResponse addBook(AddBookRequest request);
+
+ List searchByTitle(String title);
+
+ List searchByCategory(String category);
+
+ List searchByAuthor(String authorName);
+
+ List getAllBooksWithAuthors();
+}
diff --git a/homework/src/main/java/org/example/homework/service/IssueService.java b/homework/src/main/java/org/example/homework/service/IssueService.java
new file mode 100644
index 00000000..4ce1e630
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/service/IssueService.java
@@ -0,0 +1,14 @@
+package org.example.homework.service;
+
+import org.example.homework.DTO.request.IssueBookRequest;
+import org.example.homework.DTO.response.IssueResponse;
+import org.example.homework.DTO.response.IssuedBookResponse;
+
+import java.util.List;
+
+public interface IssueService {
+
+ IssueResponse issueBook(IssueBookRequest request);
+
+ List getBooksByUsn(String usn);
+}
diff --git a/homework/src/main/java/org/example/homework/service/impl/BookServiceImpl.java b/homework/src/main/java/org/example/homework/service/impl/BookServiceImpl.java
new file mode 100644
index 00000000..3163fdc4
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/service/impl/BookServiceImpl.java
@@ -0,0 +1,103 @@
+package org.example.homework.service.impl;
+
+import lombok.RequiredArgsConstructor;
+import org.example.homework.DTO.request.AddBookRequest;
+import org.example.homework.DTO.response.BookResponse;
+import org.example.homework.entity.Author;
+import org.example.homework.entity.Book;
+import org.example.homework.exceptions.ResourceAlreadyExistsException;
+import org.example.homework.repository.AuthorRepository;
+import org.example.homework.repository.BookRepository;
+import org.example.homework.service.BookService;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+@Service
+@RequiredArgsConstructor
+@Transactional
+public class BookServiceImpl implements BookService {
+
+ private final BookRepository bookRepository;
+ private final AuthorRepository authorRepository;
+
+ @Override
+ public BookResponse addBook(AddBookRequest request) {
+ if (bookRepository.existsById(request.isbn())) {
+ throw new ResourceAlreadyExistsException(
+ "Book already exists with isbn: " + request.isbn()
+ );
+ }
+
+ Book book = new Book();
+ book.setIsbn(request.isbn());
+ book.setTitle(request.title());
+ book.setCategory(request.category());
+ book.setQuantity(request.quantity());
+
+ Book savedBook = bookRepository.save(book);
+
+ Author author = new Author();
+ author.setName(request.authorName());
+ author.setEmail(request.authorEmail());
+ author.setAuthorBook(savedBook);
+
+ Author savedAuthor = authorRepository.save(author);
+
+ return mapToBookResponse(savedBook, savedAuthor);
+ }
+
+
+ @Override
+ @Transactional(readOnly = true)
+ public List searchByTitle(String title) {
+ return bookRepository.findByTitleContainingIgnoreCase(title)
+ .stream()
+ .map(this::mapBookToResponseUsingAuthorLookup)
+ .toList();
+ }
+
+ @Override
+ @Transactional(readOnly = true)
+ public List searchByCategory(String category) {
+ return bookRepository.findByCategoryContainingIgnoreCase(category)
+ .stream()
+ .map(this::mapBookToResponseUsingAuthorLookup)
+ .toList();
+ }
+
+ @Override
+ @Transactional(readOnly = true)
+ public List searchByAuthor(String authorName) {
+ return authorRepository.findByNameContainingIgnoreCase(authorName)
+ .stream()
+ .map(author -> mapToBookResponse(author.getAuthorBook(), author))
+ .toList();
+ }
+
+ @Override
+ @Transactional(readOnly = true)
+ public List getAllBooksWithAuthors() {
+ return authorRepository.findAll()
+ .stream()
+ .map(author -> mapToBookResponse(author.getAuthorBook(), author))
+ .toList();
+ }
+
+ private BookResponse mapBookToResponseUsingAuthorLookup(Book book) {
+ Author author = authorRepository.findByAuthorBookIsbn(book.getIsbn()).orElse(null);
+ return mapToBookResponse(book, author);
+ }
+
+ private BookResponse mapToBookResponse(Book book, Author author) {
+ return new BookResponse(
+ book.getIsbn(),
+ book.getTitle(),
+ book.getCategory(),
+ book.getQuantity(),
+ author != null ? author.getName() : null,
+ author != null ? author.getEmail() : null
+ );
+ }
+}
diff --git a/homework/src/main/java/org/example/homework/service/impl/IssueServiceImpl.java b/homework/src/main/java/org/example/homework/service/impl/IssueServiceImpl.java
new file mode 100644
index 00000000..9d4fe1c0
--- /dev/null
+++ b/homework/src/main/java/org/example/homework/service/impl/IssueServiceImpl.java
@@ -0,0 +1,93 @@
+package org.example.homework.service.impl;
+
+import lombok.RequiredArgsConstructor;
+import org.example.homework.DTO.request.IssueBookRequest;
+import org.example.homework.DTO.response.IssueResponse;
+import org.example.homework.DTO.response.IssuedBookResponse;
+import org.example.homework.entity.Book;
+import org.example.homework.entity.Issue;
+import org.example.homework.entity.Student;
+import org.example.homework.exceptions.InsufficientQuantityException;
+import org.example.homework.exceptions.ResourceNotFoundException;
+import org.example.homework.repository.BookRepository;
+import org.example.homework.repository.IssueRepository;
+import org.example.homework.repository.StudentRepository;
+import org.example.homework.service.IssueService;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.time.LocalDate;
+import java.util.List;
+
+@Service
+@RequiredArgsConstructor
+@Transactional
+public class IssueServiceImpl implements IssueService {
+
+ private final IssueRepository issueRepository;
+ private final StudentRepository studentRepository;
+ private final BookRepository bookRepository;
+
+ @Override
+ public IssueResponse issueBook(IssueBookRequest request) {
+ Book book = bookRepository.findById(request.bookIsbn())
+ .orElseThrow(() -> new ResourceNotFoundException(
+ "Book not found with isbn: " + request.bookIsbn()
+ ));
+
+ if (book.getQuantity() == null || book.getQuantity() <= 0) {
+ throw new InsufficientQuantityException(
+ "Book is out of stock for isbn: " + request.bookIsbn()
+ );
+ }
+
+ Student student = studentRepository.findById(request.usn())
+ .orElseGet(() -> {
+ Student newStudent = new Student();
+ newStudent.setUsn(request.usn());
+ newStudent.setName(request.studentName());
+ return studentRepository.save(newStudent);
+ });
+
+ LocalDate issueDate = LocalDate.now();
+ LocalDate returnDate = issueDate.plusDays(7);
+
+ Issue issue = new Issue();
+ issue.setIssueDate(issueDate);
+ issue.setReturnDate(returnDate);
+ issue.setIssueStudent(student);
+ issue.setIssueBook(book);
+
+ Issue savedIssue = issueRepository.save(issue);
+
+ book.setQuantity(book.getQuantity() - 1);
+ bookRepository.save(book);
+
+ return new IssueResponse(
+ savedIssue.getIssueId(),
+ student.getUsn(),
+ student.getName(),
+ book.getIsbn(),
+ book.getTitle(),
+ savedIssue.getIssueDate(),
+ savedIssue.getReturnDate()
+ );
+ }
+
+ @Override
+ @Transactional(readOnly = true)
+ public List getBooksByUsn(String usn) {
+ if (!studentRepository.existsById(usn)) {
+ throw new ResourceNotFoundException("Student not found with usn: " + usn);
+ }
+
+ return issueRepository.findByIssueStudentUsn(usn)
+ .stream()
+ .map(issue -> new IssuedBookResponse(
+ issue.getIssueBook().getTitle(),
+ issue.getIssueStudent().getName(),
+ issue.getReturnDate()
+ ))
+ .toList();
+ }
+}
diff --git a/homework/src/main/resources/application.properties b/homework/src/main/resources/application.properties
new file mode 100644
index 00000000..cfb278f8
--- /dev/null
+++ b/homework/src/main/resources/application.properties
@@ -0,0 +1 @@
+spring.application.name=homework
diff --git a/homework/src/test/java/org/example/homework/BookServiceImplTest.java b/homework/src/test/java/org/example/homework/BookServiceImplTest.java
new file mode 100644
index 00000000..e0e130be
--- /dev/null
+++ b/homework/src/test/java/org/example/homework/BookServiceImplTest.java
@@ -0,0 +1,136 @@
+package org.example.homework;
+
+import org.example.homework.DTO.request.AddBookRequest;
+import org.example.homework.DTO.response.BookResponse;
+import org.example.homework.entity.Author;
+import org.example.homework.entity.Book;
+import org.example.homework.exceptions.ResourceAlreadyExistsException;
+import org.example.homework.repository.AuthorRepository;
+import org.example.homework.repository.BookRepository;
+import org.example.homework.service.impl.BookServiceImpl;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.List;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.BDDMockito.*;
+
+@ExtendWith(MockitoExtension.class)
+class BookServiceImplTest {
+
+ @Mock
+ private BookRepository bookRepository;
+
+ @Mock
+ private AuthorRepository authorRepository;
+
+ @InjectMocks
+ private BookServiceImpl bookService;
+
+ private Book sampleBook;
+ private Author sampleAuthor;
+ private AddBookRequest sampleRequest;
+
+ @BeforeEach
+ void setUp() {
+ sampleBook = new Book();
+ sampleBook.setIsbn("978-3-16-148410-0");
+ sampleBook.setTitle("The Notebook");
+ sampleBook.setCategory("Romance");
+ sampleBook.setQuantity(4);
+
+ sampleAuthor = new Author();
+ sampleAuthor.setAuthorId(1);
+ sampleAuthor.setName("Nicholas Sparks");
+ sampleAuthor.setEmail("nicholassparks@gmail.com");
+ sampleAuthor.setAuthorBook(sampleBook);
+
+ sampleRequest = new AddBookRequest(
+ "978-3-16-148410-0",
+ "The Notebook",
+ "Romance",
+ 4,
+ "Nicholas Sparks",
+ "nicholassparks@gmail.com"
+ );
+ }
+
+ @Test
+ @DisplayName("Should successfully save book and author")
+ void addBook_Success() {
+ given(bookRepository.existsById(sampleRequest.isbn())).willReturn(false);
+ given(bookRepository.save(any(Book.class))).willReturn(sampleBook);
+ given(authorRepository.save(any(Author.class))).willReturn(sampleAuthor);
+
+ BookResponse response = bookService.addBook(sampleRequest);
+
+ assertAll("Book Response Validation",
+ () -> assertNotNull(response),
+ () -> assertEquals(sampleRequest.isbn(), response.isbn()),
+ () -> assertEquals(sampleRequest.authorName(), response.authorName())
+ );
+
+ verify(bookRepository).existsById(sampleRequest.isbn());
+ verify(bookRepository).save(any(Book.class));
+ verify(authorRepository).save(any(Author.class));
+ }
+
+ @Test
+ @DisplayName("Should throw ResourceAlreadyExistsException when ISBN exists")
+ void addBook_AlreadyExists_ThrowsException() {
+ given(bookRepository.existsById(sampleRequest.isbn())).willReturn(true);
+
+ assertThrows(ResourceAlreadyExistsException.class, () -> bookService.addBook(sampleRequest));
+
+ verify(bookRepository).existsById(sampleRequest.isbn());
+ verify(bookRepository, never()).save(any());
+ verify(authorRepository, never()).save(any());
+ }
+
+ @Test
+ @DisplayName("Should return books when searching by title")
+ void searchByTitle_ReturnsList() {
+ String title = "Notebook";
+ given(bookRepository.findByTitleContainingIgnoreCase(title)).willReturn(List.of(sampleBook));
+ given(authorRepository.findByAuthorBookIsbn(sampleBook.getIsbn())).willReturn(Optional.of(sampleAuthor));
+ List response = bookService.searchByTitle(title);
+
+ assertFalse(response.isEmpty());
+ assertEquals(sampleAuthor.getName(), response.get(0).authorName());
+
+ verify(bookRepository).findByTitleContainingIgnoreCase(title);
+ }
+
+ @Test
+ @DisplayName("Should return all books with their authors")
+ void getAllBooksWithAuthors_ReturnsAll() {
+
+ given(authorRepository.findAll()).willReturn(List.of(sampleAuthor));
+
+ List response = bookService.getAllBooksWithAuthors();
+
+ assertEquals(1, response.size());
+ assertEquals(sampleBook.getTitle(), response.get(0).title());
+ verify(authorRepository).findAll();
+ }
+
+ @Test
+ @DisplayName("Should handle case where author is missing for a book")
+ void searchByTitle_AuthorNotFound_ReturnsNullAuthorFields() {
+
+ given(bookRepository.findByTitleContainingIgnoreCase("Notebook")).willReturn(List.of(sampleBook));
+ given(authorRepository.findByAuthorBookIsbn(sampleBook.getIsbn())).willReturn(Optional.empty());
+
+ List response = bookService.searchByTitle("Notebook");
+
+ assertNull(response.get(0).authorName());
+ assertNull(response.get(0).authorEmail());
+ }
+}
\ No newline at end of file
diff --git a/homework/src/test/java/org/example/homework/HomeworkApplicationTests.java b/homework/src/test/java/org/example/homework/HomeworkApplicationTests.java
new file mode 100644
index 00000000..3a93f35f
--- /dev/null
+++ b/homework/src/test/java/org/example/homework/HomeworkApplicationTests.java
@@ -0,0 +1,13 @@
+package org.example.homework;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+class HomeworkApplicationTests {
+
+ @Test
+ void contextLoads() {
+ }
+
+}
diff --git a/homework/src/test/java/org/example/homework/IssueServiceImplTest.java b/homework/src/test/java/org/example/homework/IssueServiceImplTest.java
new file mode 100644
index 00000000..04e3b73c
--- /dev/null
+++ b/homework/src/test/java/org/example/homework/IssueServiceImplTest.java
@@ -0,0 +1,134 @@
+package org.example.homework;
+
+import org.example.homework.DTO.request.IssueBookRequest;
+import org.example.homework.DTO.response.IssueResponse;
+import org.example.homework.DTO.response.IssuedBookResponse;
+import org.example.homework.entity.Book;
+import org.example.homework.entity.Issue;
+import org.example.homework.entity.Student;
+import org.example.homework.exceptions.InsufficientQuantityException;
+import org.example.homework.exceptions.ResourceNotFoundException;
+import org.example.homework.repository.BookRepository;
+import org.example.homework.repository.IssueRepository;
+import org.example.homework.repository.StudentRepository;
+import org.example.homework.service.impl.IssueServiceImpl;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.time.LocalDate;
+import java.util.List;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.BDDMockito.*;
+
+@ExtendWith(MockitoExtension.class)
+class IssueServiceImplTest {
+
+ @Mock
+ private IssueRepository issueRepository;
+ @Mock
+ private StudentRepository studentRepository;
+ @Mock
+ private BookRepository bookRepository;
+
+ @InjectMocks
+ private IssueServiceImpl issueService;
+
+ private Book sharedBook;
+ private Student sharedStudent;
+ private Issue sharedIssue;
+ private IssueBookRequest sharedRequest;
+
+ @BeforeEach
+ void setUp() {
+ sharedBook = new Book();
+ sharedBook.setIsbn("978-0132350884");
+ sharedBook.setTitle("Clean Code");
+ sharedBook.setQuantity(10);
+
+ sharedStudent = new Student();
+ sharedStudent.setUsn("2024MS01");
+ sharedStudent.setName("Ali Aliyev");
+
+ sharedRequest = new IssueBookRequest("2024MS01", "Ali Aliyev", "978-0132350884");
+
+ sharedIssue = new Issue();
+ sharedIssue.setIssueId(1);
+ sharedIssue.setIssueDate(LocalDate.now());
+ sharedIssue.setReturnDate(LocalDate.now().plusDays(7));
+ sharedIssue.setIssueBook(sharedBook);
+ sharedIssue.setIssueStudent(sharedStudent);
+ }
+
+ @Test
+ @DisplayName("GIVEN valid request WHEN issueBook THEN return success response and decrement quantity")
+ void issueBook_ShouldReturnSuccessResponse() {
+ given(bookRepository.findById(sharedRequest.bookIsbn())).willReturn(Optional.of(sharedBook));
+ given(studentRepository.findById(sharedRequest.usn())).willReturn(Optional.of(sharedStudent));
+ given(issueRepository.save(any(Issue.class))).willReturn(sharedIssue);
+
+ IssueResponse response = issueService.issueBook(sharedRequest);
+
+ assertNotNull(response);
+ assertEquals(9, sharedBook.getQuantity());
+ assertEquals(sharedIssue.getIssueId(), response.issueId());
+ assertEquals(sharedStudent.getUsn(), response.studentUsn());
+
+ verify(bookRepository).save(sharedBook);
+ verify(issueRepository).save(any(Issue.class));
+ }
+
+ @Test
+ @DisplayName("GIVEN book out of stock WHEN issueBook THEN throw InsufficientQuantityException")
+ void issueBook_WhenOutOfStock_ShouldThrowException() {
+ sharedBook.setQuantity(0);
+ given(bookRepository.findById(sharedRequest.bookIsbn())).willReturn(Optional.of(sharedBook));
+
+ assertThrows(InsufficientQuantityException.class, () -> issueService.issueBook(sharedRequest));
+
+ verify(issueRepository, never()).save(any());
+ verify(bookRepository, never()).save(sharedBook);
+ }
+
+ @Test
+ @DisplayName("GIVEN student not exists WHEN issueBook THEN create new student and issue")
+ void issueBook_WhenStudentNotFound_ShouldCreateNewStudent() {
+ given(bookRepository.findById(sharedRequest.bookIsbn())).willReturn(Optional.of(sharedBook));
+ given(studentRepository.findById(sharedRequest.usn())).willReturn(Optional.empty());
+ given(studentRepository.save(any(Student.class))).willReturn(sharedStudent);
+ given(issueRepository.save(any(Issue.class))).willReturn(sharedIssue);
+
+ issueService.issueBook(sharedRequest);
+
+ verify(studentRepository).save(any(Student.class));
+ verify(issueRepository).save(any(Issue.class));
+ }
+
+ @Test
+ @DisplayName("GİVEN existing USN WHEN getBooksByUsn THEN return list of issued books")
+ void getBooksByUsn_ShouldReturnList() {
+ given(studentRepository.existsById("2024MS01")).willReturn(true);
+ given(issueRepository.findByIssueStudentUsn("2024MS01")).willReturn(List.of(sharedIssue));
+
+ List results = issueService.getBooksByUsn("2024MS01");
+
+ assertFalse(results.isEmpty());
+ assertEquals(sharedBook.getTitle(), results.get(0).bookTitle());
+ assertEquals(sharedStudent.getName(), results.get(0).studentName());
+ }
+
+ @Test
+ @DisplayName("GİVEN invalid USN WHEN getBooksByUsn THEN throw ResourceNotFoundException")
+ void getBooksByUsn_WhenStudentNotFound_ShouldThrowException() {
+ given(studentRepository.existsById("invalid-usn")).willReturn(false);
+
+ assertThrows(ResourceNotFoundException.class, () -> issueService.getBooksByUsn("invalid-usn"));
+ verify(issueRepository, never()).findByIssueStudentUsn(anyString());
+ }
+}
\ No newline at end of file