diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..ab1f4164 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 00000000..fcf95396 --- /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..1b7e9cc4 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/homework-java-ironschool.iml b/.idea/homework-java-ironschool.iml new file mode 100644 index 00000000..6ca28ba7 --- /dev/null +++ b/.idea/homework-java-ironschool.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ 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..e7233282 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..7d988043 --- /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/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..c5f3f6b9 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "interactive" +} \ No newline at end of file diff --git a/ironschool/.gitattributes b/ironschool/.gitattributes new file mode 100644 index 00000000..3b41682a --- /dev/null +++ b/ironschool/.gitattributes @@ -0,0 +1,2 @@ +/mvnw text eol=lf +*.cmd text eol=crlf diff --git a/ironschool/.gitignore b/ironschool/.gitignore new file mode 100644 index 00000000..667aaef0 --- /dev/null +++ b/ironschool/.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/ironschool/.mvn/wrapper/maven-wrapper.properties b/ironschool/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 00000000..8dea6c22 --- /dev/null +++ b/ironschool/.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.12/apache-maven-3.9.12-bin.zip diff --git a/ironschool/log.txt b/ironschool/log.txt new file mode 100644 index 00000000..ca37cb07 --- /dev/null +++ b/ironschool/log.txt @@ -0,0 +1,26 @@ +2026-03-10T00:59:26.539028 ---> new student registered +2026-03-10T00:59:26.546917400 ---> list of students showed +2026-03-10T01:00:44.494041300 ---> new student registered +2026-03-10T01:00:44.497051200 ---> list of students showed +2026-03-10T01:04:16.889230900 ---> new student registered +2026-03-10T01:04:16.891273 ---> list of students showed +2026-03-10T01:06:38.246073300 ---> Student named Leyla enrolled to az.ironschool.ironschool.entities.Course@31edaa7d course +2026-03-10T01:06:38.248271700 ---> student named Leyla looked up +2026-03-10T01:06:42.887239700 ---> Student named Ali enrolled to az.ironschool.ironschool.entities.Course@31edaa7d course +2026-03-10T01:06:48.804679200 ---> list of students showed +2026-03-10T01:06:52.727763100 ---> list of students showed +2026-03-10T01:06:57.450444800 ---> student named Ali looked up +2026-03-10T01:07:02.108471 ---> student named Leyla looked up +2026-03-10T01:07:06.689399600 ---> returned list of students who have Java course +2026-03-10T01:09:07.287565800 ---> list of teachers returned +2026-03-10T01:09:11.200922900 ---> list of teachers returned +2026-03-10T01:09:15.600185 ---> teacher named T1 looked up +2026-03-10T01:12:53.555568100 ---> teacher named John looked up +2026-03-10T01:12:57.205865700 ---> teacher named John looked up +2026-03-10T01:13:01.143146900 ---> teacher named John looked up +2026-03-10T01:27:55.724181800 ---> course Spring deleted +2026-03-10T01:27:55.765465 ---> course name Spring looked up +2026-03-10T01:27:55.779967100 ---> school's profit is: -3300.0 +2026-03-10T01:27:55.786517900 ---> Teacher John assingned to 1fcf23c4-d7a8-40b9-a745-bfec4c80be06 course +2026-03-10T01:27:55.791514 ---> courses showed +2026-03-10T01:27:55.803713 ---> course Java's profit is: 200.0 diff --git a/ironschool/mvnw b/ironschool/mvnw new file mode 100644 index 00000000..bd8896bf --- /dev/null +++ b/ironschool/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/ironschool/mvnw.cmd b/ironschool/mvnw.cmd new file mode 100644 index 00000000..92450f93 --- /dev/null +++ b/ironschool/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/ironschool/pom.xml b/ironschool/pom.xml new file mode 100644 index 00000000..dfe62a8d --- /dev/null +++ b/ironschool/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 4.0.3 + + + az.ironschool + ironschool + 0.0.1-SNAPSHOT + ironschool + Demo project for Spring Boot + + + + + + + + + + + + + + + 17 + + + + + org.springframework.boot + spring-boot-starter-webmvc + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + + org.junit.jupiter + junit-jupiter + 5.10.2 + test + + + + org.springframework.boot + spring-boot-starter-webmvc-test + test + + + org.springframework.boot + spring-boot-starter-validation + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/ironschool/src/main/java/az/ironschool/ironschool/IronschoolApplication.java b/ironschool/src/main/java/az/ironschool/ironschool/IronschoolApplication.java new file mode 100644 index 00000000..de689381 --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/IronschoolApplication.java @@ -0,0 +1,14 @@ +package az.ironschool.ironschool; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class IronschoolApplication { + + public static void main(String[] args) { + SpringApplication.run(IronschoolApplication.class, args); + + } + +} diff --git a/ironschool/src/main/java/az/ironschool/ironschool/controllers/CourseController.java b/ironschool/src/main/java/az/ironschool/ironschool/controllers/CourseController.java new file mode 100644 index 00000000..121118aa --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/controllers/CourseController.java @@ -0,0 +1,63 @@ +package az.ironschool.ironschool.controllers; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import az.ironschool.ironschool.entities.Course; +import az.ironschool.ironschool.entities.Teacher; +import az.ironschool.ironschool.services.CourseService; +import az.ironschool.ironschool.utils.Logging; + +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + + +@RestController +@RequestMapping("/courses") +public class CourseController { + + private static CourseService courseService; + + @PutMapping("/assign") + public void assign(@RequestParam String teacherId, @RequestParam String courseId){ + courseService.assign(teacherId, courseId); + + } + + + @GetMapping("/get-all") + public List showCourses(){ + return courseService.showCourses(); + } + + + + @GetMapping("/lookup/{id}") + public Course lookupCourse(@PathVariable String courseId){ + return courseService.lookupCourse(courseId); + } + + @GetMapping("/show-total-profit") + public double showSchoolProfit(){ + return courseService.showSchoolProfit(); + } + + @GetMapping("/profit") + public double courseProfit(@RequestParam String courseId) { + return courseService.courseProfit(courseId); + } + + @DeleteMapping("/delete-course") + public void deleteCourse(@RequestParam String id){ + courseService.deleteCourse(id); + } + + +} diff --git a/ironschool/src/main/java/az/ironschool/ironschool/controllers/CreateSchool.java b/ironschool/src/main/java/az/ironschool/ironschool/controllers/CreateSchool.java new file mode 100644 index 00000000..6dce7e8b --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/controllers/CreateSchool.java @@ -0,0 +1,62 @@ +package az.ironschool.ironschool.controllers; + +import az.ironschool.ironschool.services.TeacherService; +import az.ironschool.ironschool.entities.Teacher; +import java.util.Scanner; + +public class CreateSchool { + private static Scanner sc = new Scanner(System.in); + private static TeacherService teacherService; + + public CreateSchool(TeacherService teacherService) { + this.teacherService = teacherService; + } + + public static void createSchool() { + try { + System.out.println("Please enter a name for your school: "); + String schoolName = sc.nextLine(); + + } catch (RuntimeException e) { + System.out.println("Error: "); + } + + try { + System.out.println("Enter how many teachers you want to have in your school: "); + int teacherCount = sc.nextInt(); + sc.nextLine(); + + for (int i = 1; i < teacherCount + 1; i++) { + Teacher teacher = new Teacher(); + System.out.println("Enter the name of the teacher number " + i + " : "); + String teacherName = sc.nextLine(); + teacher.setName(teacherName); + + while (true) { + try { + System.out.println("Enter the teacher " + teacherName + "'s salary: "); + double teacherSalary = sc.nextDouble(); + teacher.setSalary(teacherSalary); + sc.nextLine(); + break; + } catch (RuntimeException e) { + System.err.println("Error: wrong input type.Please enter a number that is valid"); + sc.nextLine(); + } + } + if (teacherService != null) { + teacherService.getTeachers().put(teacher.getTeacherId(), teacher); + } + + System.out.println("Enter the subject teacher ' " + teacherName + "' teachs: "); + String teacherSubject = sc.nextLine(); + //sc.nextLine(); + teacher.setSubject(teacherSubject); + } + System.out.println(" HashMap has created for teachers "); + }catch (RuntimeException e){ + System.err.println("Error: Please enter a number."); + sc.nextLine(); + } + } +} diff --git a/ironschool/src/main/java/az/ironschool/ironschool/controllers/StudentController.java b/ironschool/src/main/java/az/ironschool/ironschool/controllers/StudentController.java new file mode 100644 index 00000000..cda53d0a --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/controllers/StudentController.java @@ -0,0 +1,60 @@ +package az.ironschool.ironschool.controllers; + +import java.util.List; + +import org.springframework.web.bind.annotation.RestController; + +import az.ironschool.ironschool.dtos.NewStudentDTO; +import az.ironschool.ironschool.entities.Student; +import az.ironschool.ironschool.services.StudentService; +import jakarta.validation.Valid; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + + +@RestController +@RequestMapping("/students") +public class StudentController { + + private static StudentService studentService; + + @PostMapping("/register-new") + public void newStudent(@Valid @RequestBody NewStudentDTO newStudent){ + + studentService.registerNewStudent(newStudent); + + } + + + @PutMapping("/enroll") + public void enroll(@RequestParam String studentId, @RequestParam String courseId) { + studentService.enroll(studentId, courseId); + + + } + + + @GetMapping("/show-all") + public List showAll(){ + return studentService.showStudents(); + } + + @GetMapping("/lookup-student/{id}") + public Student lookupStudent(@PathVariable String studentId){ + return studentService.lookupStudent(studentId); + } + + + @GetMapping("/get-by-course") + public List getByCourse(@RequestParam String courseId){ + return studentService.getByCourse(courseId); + } + + +} diff --git a/ironschool/src/main/java/az/ironschool/ironschool/controllers/TeacherController.java b/ironschool/src/main/java/az/ironschool/ironschool/controllers/TeacherController.java new file mode 100644 index 00000000..c0265f20 --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/controllers/TeacherController.java @@ -0,0 +1,42 @@ +package az.ironschool.ironschool.controllers; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import az.ironschool.ironschool.entities.Teacher; +import az.ironschool.ironschool.services.TeacherService; + +@RestController +@RequestMapping("/teachers") +public class TeacherController { + private static TeacherService service; + + + + @GetMapping("/all-teachers") + public List showTeachers(){ + return service.showTeachers(); + } + + + @GetMapping("/teacher/{id}") + public Teacher lookupTeacher(@PathVariable String teacherId){ + + return service.lookupTeacher(teacherId); + + } + + @PatchMapping("/change-salary") + public void changeSalary(@RequestParam String id, @RequestParam double newSalary){ + service.changeSalary(id, newSalary); + } + +} diff --git a/ironschool/src/main/java/az/ironschool/ironschool/dtos/NewStudentDTO.java b/ironschool/src/main/java/az/ironschool/ironschool/dtos/NewStudentDTO.java new file mode 100644 index 00000000..fb692785 --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/dtos/NewStudentDTO.java @@ -0,0 +1,30 @@ +package az.ironschool.ironschool.dtos; + +public class NewStudentDTO { + + //name, address, email, + + private String name; + private String address; + private String email; + + + + public NewStudentDTO(String name, String address, String email) { + this.name = name; + this.address = address; + this.email = email; + } + public String getName() { + return name; + } + public String getAddress() { + return address; + } + public String getEmail() { + return email; + } + + + +} diff --git a/ironschool/src/main/java/az/ironschool/ironschool/entities/Course.java b/ironschool/src/main/java/az/ironschool/ironschool/entities/Course.java new file mode 100644 index 00000000..b86f0124 --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/entities/Course.java @@ -0,0 +1,81 @@ +package az.ironschool.ironschool.entities; + +import java.util.UUID; + +import jakarta.validation.constraints.NotBlank; + +public class Course { + + private String courseId; + + @NotBlank(message = "name bos ola bilmez") + private String name; + + @NotBlank(message = "price bos ola bilmez") + private double price; + + private double moneyEarned; + private Teacher teacher; + private int sold; + + public Course(String name, double price) { + this.courseId = UUID.randomUUID().toString(); + this.name = name; + this.price = price; + } + public Course () { + this.courseId = UUID.randomUUID().toString(); + } + + public String getCourseId() { + return courseId; + } + + + + //getters and setters + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + + public double getMoneyEarned() { + return moneyEarned; + } + + public void setMoneyEarned(double moneyEarned) { + this.moneyEarned = moneyEarned; + } + + public Teacher getTeacher() { + return teacher; + } + + public void setTeacher(Teacher teacher) { + this.teacher = teacher; + } + public int getSold() { + return sold; + } + public void setSold(int sold) { + this.sold = sold; + } + + + + + + +} diff --git a/ironschool/src/main/java/az/ironschool/ironschool/entities/Student.java b/ironschool/src/main/java/az/ironschool/ironschool/entities/Student.java new file mode 100644 index 00000000..fdcddd2d --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/entities/Student.java @@ -0,0 +1,73 @@ +package az.ironschool.ironschool.entities; + +import java.util.UUID; + +import jakarta.validation.constraints.NotBlank; + +public class Student { + + + private String studentId; + + @NotBlank(message = "name bos ola bilmez") + private String name; + + @NotBlank(message = "address bos ola bilmez") + private String address; + + @NotBlank(message = "email bos ola bilmez") + private String email; + + private Course course; + + public Student(String name, String address, String email) { + this.studentId = UUID.randomUUID().toString(); + this.name = name; + this.address = address; + this.email = email; + } + public Student () { + this.studentId = UUID.randomUUID().toString(); + } + + public String getStudentId() { + return studentId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public Course getCourse() { + return course; + } + + public void setCourse(Course course) { + this.course = course; + } + + + + + +} diff --git a/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java b/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java new file mode 100644 index 00000000..9c4cac01 --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java @@ -0,0 +1,84 @@ +package az.ironschool.ironschool.entities; + +import java.util.UUID; + +import jakarta.validation.constraints.NotBlank; + +public class Teacher { + + private String teacherId; + + @NotBlank + private String name; + + @NotBlank + private double salary; + + @NotBlank + private String subject; + + public Teacher(String name, double salary) { + this.teacherId = UUID.randomUUID().toString(); + this.name = name; + this.salary = salary; + } + + + + public Teacher(String name, String subject, double salary) { + this.teacherId = UUID.randomUUID().toString(); + this.name = name; + this.salary = salary; + this.subject = subject; + } + + + + //ONLY THIS CONTRUCTOR + public Teacher () { + this.teacherId = UUID.randomUUID().toString(); + } + + + + public String getTeacherId() { + return teacherId; + } + + + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + public double getSalary() { + return salary; + } + + + public void setSalary(double salary) { + this.salary = salary; + } + + + public String getSubject() { + return subject; + } + + + public void setSubject(String subject) { + this.subject = subject; + } + + + + + + +} diff --git a/ironschool/src/main/java/az/ironschool/ironschool/services/CourseService.java b/ironschool/src/main/java/az/ironschool/ironschool/services/CourseService.java new file mode 100644 index 00000000..3430fb13 --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/services/CourseService.java @@ -0,0 +1,104 @@ +package az.ironschool.ironschool.services; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import az.ironschool.ironschool.entities.Course; +import az.ironschool.ironschool.entities.Teacher; +import az.ironschool.ironschool.utils.Logging; + +public class CourseService { + + private Map courses; + + private TeacherService teacherService; + + + + + public CourseService(TeacherService teacherService) { + this.teacherService = teacherService; + } + + + + public CourseService() { + } + + + + public void assign(String teacherId, String courseId){ + + for(Course course : courses.values()){ + if(course.getCourseId().equals(courseId)){ + course.setTeacher(teacherService.getTeachers().get(teacherId)); + Logging.log("Teacher "+ teacherService.getTeachers().get(teacherId).getName()+ " assingned to "+ courses.get(courseId).getCourseId()+ " course"); + + } + } + + + } + + + public List showCourses(){ + + Logging.log("courses showed"); + return new ArrayList<>(courses.values()); + + } + + public Course lookupCourse(String courseId){ + + Logging.log("course name "+ courses.get(courseId).getName() +" looked up"); + return courses.get(courseId); + } + + public double showSchoolProfit(){ + + double coursesTotal = 0; + double teachersTotal = 0; + + + for(Teacher teacher : teacherService.getTeachers().values()){ + + teachersTotal += teacher.getSalary(); + } + + for (Course course : courses.values()) { + + coursesTotal += course.getMoneyEarned(); + + } + + Logging.log("school's profit is: "+ (coursesTotal - teachersTotal)); + return coursesTotal - teachersTotal; + } + + + public double courseProfit(String courseId){ + + Course course = courses.get(courseId); + Logging.log("course "+ courses.get(courseId).getName()+ "'s profit is: "+ (course.getMoneyEarned() - course.getPrice())); + return course.getMoneyEarned() - course.getPrice(); + } + + public void deleteCourse(String id){ + Logging.log("course "+ courses.get(id).getName()+ " deleted"); + courses.remove(id); + } + + +// getter and setter + public Map getCourses() { + return courses; + } + + public void setCourses(Map courses) { + this.courses = courses; + } + + + +} diff --git a/ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java b/ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java new file mode 100644 index 00000000..f81e822c --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java @@ -0,0 +1,61 @@ +package az.ironschool.ironschool.services; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.springframework.stereotype.Service; + +import az.ironschool.ironschool.dtos.NewStudentDTO; +import az.ironschool.ironschool.entities.Student; +import az.ironschool.ironschool.utils.Logging; + +@Service +public class StudentService { + + private static Map students; + + private static CourseService courseService; + + public void registerNewStudent(NewStudentDTO dto) { + Student newSt = new Student(dto.getName(), dto.getAddress(), dto.getEmail()); + students.put(newSt.getStudentId(), newSt); + + Logging.log("new student registered"); + } + + public void enroll(String studentId, String courseId) { + + students.get(studentId).setCourse(courseService.getCourses().get(courseId)); + + double coursePrice = courseService.getCourses().get(courseId).getPrice(); + double courseProfit = courseService.getCourses().get(courseId).getMoneyEarned(); + + courseService.getCourses().get(courseId).setMoneyEarned(coursePrice + courseProfit); + + Logging.log("Student named "+ students.get(studentId).getName()+ " enrolled to "+ courseService.getCourses().get(courseId)+ " course"); + } + + public List showStudents() { + + Logging.log("list of students showed"); + return new ArrayList<>(students.values()); + } + + public Student lookupStudent(String studentId) { + + Logging.log("student named "+ students.get(studentId).getName() +" looked up"); + + return students.get(studentId); + } + + public List getByCourse(String courseId) { + + Logging.log("returned list of students who have "+ courseService.getCourses().get(courseId).getName()+" course"); + return students.values() + .stream() + .filter(student -> student.getCourse().getCourseId().equals(courseId)) + .toList(); + } + +} diff --git a/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java b/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java new file mode 100644 index 00000000..0afe4dd5 --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java @@ -0,0 +1,46 @@ +package az.ironschool.ironschool.services; + +import az.ironschool.ironschool.entities.Teacher; +import az.ironschool.ironschool.utils.Logging; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class TeacherService { + private static Map teachers; + + + + public List showTeachers() { + + Logging.log("list of teachers returned"); + + return new ArrayList<>(teachers.values()); + } + + public Teacher lookupTeacher(String teacherId) { + + if(teachers.get(teacherId)!= null){Logging.log("teacher named "+ teachers.get(teacherId).getName() +" looked up");} + else{Logging.log("that teacher not found");} + return teachers.get(teacherId); + } + + + //getter and setter + public Map getTeachers() { + return teachers; + } + + public TeacherService() { + } + + public void setTeachers(Map teachers) { + TeacherService.teachers = teachers; + } + + public void changeSalary(String id, double newSalary){ + teachers.get(id).setSalary(newSalary); + } + +} diff --git a/ironschool/src/main/java/az/ironschool/ironschool/utils/Logging.java b/ironschool/src/main/java/az/ironschool/ironschool/utils/Logging.java new file mode 100644 index 00000000..10de0216 --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/utils/Logging.java @@ -0,0 +1,23 @@ +package az.ironschool.ironschool.utils; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.time.LocalDateTime; + +public class Logging { + + public static void log(String message){ + + try (BufferedWriter writer = + new BufferedWriter(new FileWriter("log.txt", true))) { + + writer.write(LocalDateTime.now() + " ---> " + message); + writer.newLine(); + + } catch (IOException e) { + e.printStackTrace(); + } + + } +} diff --git a/ironschool/src/main/resources/application.properties b/ironschool/src/main/resources/application.properties new file mode 100644 index 00000000..64bb90af --- /dev/null +++ b/ironschool/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=ironschool diff --git a/ironschool/src/test/java/az/ironschool/ironschool/CourseServiceTest.java b/ironschool/src/test/java/az/ironschool/ironschool/CourseServiceTest.java new file mode 100644 index 00000000..24b8905d --- /dev/null +++ b/ironschool/src/test/java/az/ironschool/ironschool/CourseServiceTest.java @@ -0,0 +1,94 @@ +package az.ironschool.ironschool; + +import az.ironschool.ironschool.entities.Course; +import az.ironschool.ironschool.entities.Teacher; +import az.ironschool.ironschool.services.CourseService; +import az.ironschool.ironschool.services.TeacherService; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.HashMap; +import java.util.Map; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +public class CourseServiceTest { + + private CourseService courseService; + private TeacherService teacherService; + + + private String teacherId1; + private String teacherId2; + private String courseId1; + private String courseId2; + + + @BeforeEach + void setUp() { + teacherService = new TeacherService(); + Map teachers = new HashMap<>(); + Teacher t1 = new Teacher("John","Geography",2000); + Teacher t2 = new Teacher("Anna","Math", 2500); + teacherId2 = t2.getTeacherId(); + teacherId1 = t1.getTeacherId(); + + teachers.put(teacherId1, t1); + teachers.put(teacherId2, t2); + teacherService.setTeachers(teachers); + + courseService = new CourseService(teacherService); + Map courses = new HashMap<>(); + Course c1 = new Course("Java",100); + courseId1 = c1.getCourseId(); + courses.put(courseId1, c1); + + Course c2 = new Course("Spring",150); + courseId2 = c2.getCourseId(); + courses.put(courseId2, c2); + courseService.setCourses(courses); + } + + @Test + void assign_teacherAssignedToCourse() { + courseService.assign(teacherId1, courseId1); + assertEquals("John", courseService.getCourses().get(courseId1).getTeacher().getName()); + } + + @Test + void showCourses_returnsAllCourses() { + List courses = courseService.showCourses(); + assertEquals(2, courses.size()); + } + + @Test + void lookupCourse_returnsCorrectCourse() { + Course course = courseService.lookupCourse(courseId2); + assertEquals("Spring", course.getName()); + } + + @Test + void showSchoolProfit_calculatesCorrectly() { + courseService.getCourses().get(courseId1).setMoneyEarned(500); + courseService.getCourses().get(courseId2).setMoneyEarned(700); + + double profit = courseService.showSchoolProfit(); + // courses total = 1200, teachers total = 4500 + assertEquals(1200 - (2000 + 2500), profit); + } + + @Test + void courseProfit_returnsCorrectProfit() { + Course course = courseService.getCourses().get(courseId1); + course.setMoneyEarned(300); + double profit = courseService.courseProfit(courseId1); + assertEquals(300 - 100, profit); + } + + @Test + void deleteCourse_removesCourse() { + courseService.deleteCourse(courseId2); + assertFalse(courseService.getCourses().containsKey(courseId2)); + } +} \ No newline at end of file diff --git a/ironschool/src/test/java/az/ironschool/ironschool/IronschoolApplicationTests.java b/ironschool/src/test/java/az/ironschool/ironschool/IronschoolApplicationTests.java new file mode 100644 index 00000000..6ba948bb --- /dev/null +++ b/ironschool/src/test/java/az/ironschool/ironschool/IronschoolApplicationTests.java @@ -0,0 +1,13 @@ +package az.ironschool.ironschool; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class IronschoolApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/ironschool/src/test/java/az/ironschool/ironschool/StudentServiceTests.java b/ironschool/src/test/java/az/ironschool/ironschool/StudentServiceTests.java new file mode 100644 index 00000000..20804c07 --- /dev/null +++ b/ironschool/src/test/java/az/ironschool/ironschool/StudentServiceTests.java @@ -0,0 +1,127 @@ +package az.ironschool.ironschool; + +import az.ironschool.ironschool.dtos.NewStudentDTO; +import az.ironschool.ironschool.entities.Course; +import az.ironschool.ironschool.entities.Student; +import az.ironschool.ironschool.services.CourseService; +import az.ironschool.ironschool.services.StudentService; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.*; + +public class StudentServiceTests { + + private StudentService studentService; + private CourseService courseService; + + private String courseId1; + private String studentId1; + private String courseId2; + private String studentId2; + + @BeforeEach + void setUp() throws Exception { + + studentService = new StudentService(); + courseService = new CourseService(); + + Map students = new HashMap<>(); + Map courses = new HashMap<>(); + + Course c1 = new Course("Java", 100); + courseId1 = c1.getCourseId(); + Course c2 = new Course("Spring", 150); + courseId2 = c2.getCourseId(); + + + Student s1 = new Student("Ali", "Baku", "ali@mail.com"); + s1.setCourse(c1); + studentId1 = s1.getStudentId(); + + + Student s2 = new Student("Leyla", "Baku", "leyla@mail.com"); + s2.setCourse(c2); + studentId2 = s2.getStudentId(); + + + students.put(studentId1, s1); + students.put(studentId2, s2); + + courses.put(courseId1, c1); + courses.put(courseId2, c2); + + courseService.setCourses(courses); + + // idk v + Field studentsField = StudentService.class.getDeclaredField("students"); + studentsField.setAccessible(true); + studentsField.set(null, students); + + Field courseServiceField = StudentService.class.getDeclaredField("courseService"); + courseServiceField.setAccessible(true); + courseServiceField.set(null, courseService); + } + + + @Test + void registerNewStudent_createsStudent() { + NewStudentDTO dto = new NewStudentDTO("Murad", "Baku", "murad@mail.com"); + studentService.registerNewStudent(dto); + + List studentsNew = studentService.showStudents(); + assertEquals(3, studentsNew.size()); // əvvəl 2 idi, indi 3 olmalıdır + } + + @Test + void enroll_assignsCourseToStudent() { + studentService.enroll(studentId2, courseId2); + Student student = studentService.lookupStudent(studentId2); + assertEquals(courseId2, student.getCourse().getCourseId()); + } + + @Test + void enroll_increasesCourseMoneyEarned() { + Course course = courseService.getCourses().get(courseId1); + double oldMoney = course.getMoneyEarned(); + studentService.enroll(studentId1, courseId1); + assertTrue(course.getMoneyEarned() > oldMoney); + } + + @Test + void showStudents_returnsAllStudents() { + List students = studentService.showStudents(); + assertEquals(2, students.size()); + } + + @Test + void showStudents_listIsNotEmpty() { + List students = studentService.showStudents(); + assertFalse(students.isEmpty()); + } + + @Test + void lookupStudent_returnsCorrectStudent() { + Student student = studentService.lookupStudent(studentId1); + assertEquals("Ali", student.getName()); + } + + @Test + void lookupStudent_studentIsNotNull() { + Student student = studentService.lookupStudent(studentId2); + assertNotNull(student); + } + + @Test + void getByCourse_returnsCorrectStudents() { + List javaStudents = studentService.getByCourse(courseId1); + assertEquals(1, javaStudents.size()); + assertEquals(courseId1, javaStudents.get(0).getCourse().getCourseId()); + } +} diff --git a/ironschool/src/test/java/az/ironschool/ironschool/TeacherServiceTests.java b/ironschool/src/test/java/az/ironschool/ironschool/TeacherServiceTests.java new file mode 100644 index 00000000..61105e4e --- /dev/null +++ b/ironschool/src/test/java/az/ironschool/ironschool/TeacherServiceTests.java @@ -0,0 +1,87 @@ +package az.ironschool.ironschool; + +import az.ironschool.ironschool.entities.Teacher; +import az.ironschool.ironschool.services.TeacherService; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.HashMap; +import java.util.Map; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +public class TeacherServiceTests { + + private TeacherService teacherService; + + private String teacherId1; + private String teacherId2; + + @BeforeEach + void setUp() { + teacherService = new TeacherService(); + + Map teachers = new HashMap<>(); + + Teacher t1 = new Teacher("John", 2000.0); + teacherId1 = t1.getTeacherId(); + + Teacher t2 = new Teacher("Anna", 2500.0); + teacherId2 = t2.getTeacherId(); + + + teachers.put(teacherId1, t1); + teachers.put( teacherId2, t2); + + teacherService.setTeachers(teachers); + } + + @Test + void showTeachers_returnsAllTeachers() { + + List result = teacherService.showTeachers(); + + assertEquals(2, result.size()); + } + + @Test + void showTeachers_listIsNotEmpty() { + + List result = teacherService.showTeachers(); + + assertFalse(result.isEmpty()); + } + + @Test + void lookupTeacher_returnsCorrectTeacher() { + + Teacher teacher = teacherService.lookupTeacher(teacherId1); + + assertEquals("John", teacher.getName()); + } + + @Test + void changeSalary_updatesSalary() { + + teacherService.changeSalary(teacherId1, 3000); + + Teacher teacher = teacherService.lookupTeacher(teacherId1); + + assertEquals(3000, teacher.getSalary()); + } + + @Test + void changeSalary_salaryIsDifferentFromOld() { + + Teacher teacher = teacherService.lookupTeacher(teacherId1); + + double oldSalary = teacher.getSalary(); + + teacherService.changeSalary(teacherId1, 4000); + + assertNotEquals(oldSalary, teacher.getSalary()); + } + +}