From 5c567bee3ef8205e66ec58681db79ca6daee96c9 Mon Sep 17 00:00:00 2001 From: Sevinc Date: Fri, 6 Mar 2026 14:30:41 +0400 Subject: [PATCH 01/16] starters --- ironschool/.gitattributes | 2 + ironschool/.gitignore | 33 ++ .../.mvn/wrapper/maven-wrapper.properties | 3 + ironschool/mvnw | 295 ++++++++++++++++++ ironschool/mvnw.cmd | 189 +++++++++++ ironschool/pom.xml | 60 ++++ .../ironschool/IronschoolApplication.java | 13 + .../ironschool/entities/Course.java | 69 ++++ .../ironschool/entities/Student.java | 60 ++++ .../ironschool/entities/Teacher.java | 59 ++++ .../src/main/resources/application.properties | 1 + .../IronschoolApplicationTests.java | 13 + 12 files changed, 797 insertions(+) create mode 100644 ironschool/.gitattributes create mode 100644 ironschool/.gitignore create mode 100644 ironschool/.mvn/wrapper/maven-wrapper.properties create mode 100644 ironschool/mvnw create mode 100644 ironschool/mvnw.cmd create mode 100644 ironschool/pom.xml create mode 100644 ironschool/src/main/java/az/ironschool/ironschool/IronschoolApplication.java create mode 100644 ironschool/src/main/java/az/ironschool/ironschool/entities/Course.java create mode 100644 ironschool/src/main/java/az/ironschool/ironschool/entities/Student.java create mode 100644 ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java create mode 100644 ironschool/src/main/resources/application.properties create mode 100644 ironschool/src/test/java/az/ironschool/ironschool/IronschoolApplicationTests.java 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/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..a3777c92 --- /dev/null +++ b/ironschool/pom.xml @@ -0,0 +1,60 @@ + + + 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 + + + + + + + + + + + + + + + 21 + + + + org.springframework.boot + spring-boot-starter-webmvc + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + org.springframework.boot + spring-boot-starter-webmvc-test + test + + + + + + + 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..46fe4524 --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/IronschoolApplication.java @@ -0,0 +1,13 @@ +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/entities/Course.java b/ironschool/src/main/java/az/ironschool/ironschool/entities/Course.java new file mode 100644 index 00000000..053ecba9 --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/entities/Course.java @@ -0,0 +1,69 @@ +package main.java.az.ironschool.ironschool.entities; + +import java.util.UUID; + +public class Course { + + private String courseId; + private String name; + private double price; + private double money_earned; + private Teacher teacher; + private int pageCount; + + public Course(String name, double price) { + this.courseId = UUID.randomUUID().toString(); + this.name = name; + this.price = price; + } + + public String getCourseId() { + return courseId; + } + + + + 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 getMoney_earned() { + return money_earned; + } + + public void setMoney_earned(double money_earned) { + this.money_earned = money_earned; + } + + public Teacher getTeacher() { + return teacher; + } + + public void setTeacher(Teacher teacher) { + this.teacher = teacher; + } + + public int getPageCount() { + return pageCount; + } + + public void setPageCount(int pageCount) { + this.pageCount = pageCount; + } + + + + +} 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..07dabfdc --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/entities/Student.java @@ -0,0 +1,60 @@ +package main.java.az.ironschool.ironschool.entities; + +import java.util.UUID; + +public class Student { + + private String studentId; + private String name; + private String address; + 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 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..7376d1d6 --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java @@ -0,0 +1,59 @@ +package main.java.az.ironschool.ironschool.entities; + +import java.util.UUID; + +public class Teacher { + + private String teacherId; + private String name; + private double salary; + private String subject; + + public Teacher(String name, double salary) { + this.teacherId = UUID.randomUUID().toString(); + this.name = name; + this.salary = salary; + } + + + 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/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/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() { + } + +} From 738e56621d9898bebc54ecf56db88ba4bb1d6f55 Mon Sep 17 00:00:00 2001 From: Sevinc Date: Fri, 6 Mar 2026 14:36:30 +0400 Subject: [PATCH 02/16] corrected --- .../src/main/java/az/ironschool/ironschool/entities/Course.java | 2 +- .../main/java/az/ironschool/ironschool/entities/Student.java | 2 +- .../main/java/az/ironschool/ironschool/entities/Teacher.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ironschool/src/main/java/az/ironschool/ironschool/entities/Course.java b/ironschool/src/main/java/az/ironschool/ironschool/entities/Course.java index 053ecba9..bfe0086d 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/entities/Course.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/entities/Course.java @@ -1,4 +1,4 @@ -package main.java.az.ironschool.ironschool.entities; +package az.ironschool.ironschool.entities; import java.util.UUID; diff --git a/ironschool/src/main/java/az/ironschool/ironschool/entities/Student.java b/ironschool/src/main/java/az/ironschool/ironschool/entities/Student.java index 07dabfdc..0c74fcdb 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/entities/Student.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/entities/Student.java @@ -1,4 +1,4 @@ -package main.java.az.ironschool.ironschool.entities; +package az.ironschool.ironschool.entities; import java.util.UUID; diff --git a/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java b/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java index 7376d1d6..710f2d00 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java @@ -1,4 +1,4 @@ -package main.java.az.ironschool.ironschool.entities; +package az.ironschool.ironschool.entities; import java.util.UUID; From 2fbf794963cc92ed978ebccfc8b5ce7b0a238306 Mon Sep 17 00:00:00 2001 From: Sevinc Date: Fri, 6 Mar 2026 15:55:36 +0400 Subject: [PATCH 03/16] maps added --- .../ironschool/IronschoolApplication.java | 2 ++ .../ironschool/services/StudentService.java | 15 +++++++++++++++ .../ironschool/services/TeacherService.java | 12 ++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java create mode 100644 ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java diff --git a/ironschool/src/main/java/az/ironschool/ironschool/IronschoolApplication.java b/ironschool/src/main/java/az/ironschool/ironschool/IronschoolApplication.java index 46fe4524..30f71de4 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/IronschoolApplication.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/IronschoolApplication.java @@ -10,4 +10,6 @@ public static void main(String[] args) { SpringApplication.run(IronschoolApplication.class, args); } + + } 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..1c9d0abb --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java @@ -0,0 +1,15 @@ +package az.ironschool.ironschool.services; + +import java.util.Map; + +import org.springframework.stereotype.Service; + +import az.ironschool.ironschool.entities.Student; + +@Service +public class StudentService { + +private static Map students; + + +} 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..12d86ee7 --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java @@ -0,0 +1,12 @@ +package az.ironschool.ironschool.services; + +import java.util.Map; + +import az.ironschool.ironschool.entities.Student; +import az.ironschool.ironschool.entities.Teacher; + +public class TeacherService { + private static Map teachers; + + +} From b3caf8f4f6fef6ea406cc206459c37974d5b0a0b Mon Sep 17 00:00:00 2001 From: Sevinc Date: Fri, 6 Mar 2026 17:30:38 +0400 Subject: [PATCH 04/16] all commands are done --- .vscode/settings.json | 3 + ironschool/pom.xml | 2 +- .../controllers/CreatingSchool.java | 24 +++++++ .../ironschool/services/CourseService.java | 70 +++++++++++++++++++ .../ironschool/services/StudentService.java | 30 +++++++- .../ironschool/services/TeacherService.java | 23 ++++++ 6 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 ironschool/src/main/java/az/ironschool/ironschool/controllers/CreatingSchool.java create mode 100644 ironschool/src/main/java/az/ironschool/ironschool/services/CourseService.java 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/pom.xml b/ironschool/pom.xml index a3777c92..784d67aa 100644 --- a/ironschool/pom.xml +++ b/ironschool/pom.xml @@ -27,7 +27,7 @@ - 21 + 17 diff --git a/ironschool/src/main/java/az/ironschool/ironschool/controllers/CreatingSchool.java b/ironschool/src/main/java/az/ironschool/ironschool/controllers/CreatingSchool.java new file mode 100644 index 00000000..aa7b28fc --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/controllers/CreatingSchool.java @@ -0,0 +1,24 @@ +package az.ironschool.ironschool.controllers; + +import az.ironschool.ironschool.entities.Teacher; + +public class CreatingSchool { + + // public static void createSchool () { + // System.out.println("Please enter a name for your school: " ); + // String schoolName = sc.next(); + + // System.out.println("Enter how many teachers you want to have in your school: "); + // int teacherCount = sc.nextInt; + // for (int i = 0 ; i < teacherCount ; i++){ + // Teacher teacher = new Teacher(); + // System.out.println("Enter the name of the teacher with id" + teacher.getTeacherId() + ": "); + // String teacherName = sc.next(); + // teacher.setName(); + + // System.out.println("Enter the teacher ' " + teacherName " 's salary: "); + // double teacherSalary = sc.next(); + // } + // } + +} 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..b54cb15c --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/services/CourseService.java @@ -0,0 +1,70 @@ +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; + +public class CourseService { + + private static Map courses; + + private static TeacherService teacherService; + + + + public void assign(String teacherId, String courseId){ + + for(Course course : courses.values()){ + if(course.getCourseId().equals(courseId)){ + course.setTeacher(teacherService.getTeachers().get(teacherId)); + } + } + } + + + public List showCourses(){ + return new ArrayList<>(courses.values()); + } + + public Course lookupCourse(String courseId){ + return courses.get(courseId); + } + + public double showProfit(){ + + double coursesTotal = 0; + double teachersTotal = 0; + + + for(Teacher teacher : teacherService.getTeachers().values()){ + + teachersTotal += teacher.getSalary(); + } + + for (Course course : courses.values()) { + + coursesTotal += course.getMoney_earned(); + + } + + + return coursesTotal - teachersTotal; + } + + + + + public static Map getCourses() { + return courses; + } + + public static void setCourses(Map courses) { + CourseService.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 index 1c9d0abb..181add4c 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java @@ -1,15 +1,43 @@ 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.entities.Course; import az.ironschool.ironschool.entities.Student; @Service public class StudentService { -private static Map students; + private static Map students; + private static CourseService courseService; + + public void enroll(String studentId, String courseId) { + + for (Student student : students.values()) { + + if (student.getStudentId().equals(studentId)) { + student.setCourse(courseService.getCourses().get(courseId)); + + double coursePrice = courseService.getCourses().get(courseId).getPrice(); + double courseProfit = courseService.getCourses().get(courseId).getMoney_earned(); + + + courseService.getCourses().get(courseId).setMoney_earned(coursePrice+ courseProfit); + } + } + } + + public List showStudents() { + return new ArrayList<>(students.values()); + } + + public Student lookupCourse(String studentId) { + return students.get(studentId); + } } diff --git a/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java b/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java index 12d86ee7..9478ca42 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java @@ -1,5 +1,7 @@ package az.ironschool.ironschool.services; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import az.ironschool.ironschool.entities.Student; @@ -9,4 +11,25 @@ public class TeacherService { private static Map teachers; + + public List showTeachers() { + return new ArrayList<>(teachers.values()); + } + + public Teacher lookupCourse(String teacherId) { + return teachers.get(teacherId); + } + + + + + public static Map getTeachers() { + return teachers; + } + + public static void setTeachers(Map teachers) { + TeacherService.teachers = teachers; + } + + } From fd0ff6a90bf6f97b5d7225a05b7796ebadd6a9ea Mon Sep 17 00:00:00 2001 From: Lala Date: Fri, 6 Mar 2026 18:27:06 +0400 Subject: [PATCH 05/16] Homewrok 2 --- .idea/.gitignore | 10 +++ .idea/compiler.xml | 22 +++++++ .idea/encodings.xml | 7 +++ .idea/homework-java-ironschool.iml | 11 ++++ .idea/jarRepositories.xml | 20 ++++++ .idea/misc.xml | 23 +++++++ .idea/modules.xml | 8 +++ .idea/vcs.xml | 7 +++ .../ironschool/IronschoolApplication.java | 12 +++- .../ironschool/controllers/CreateSchool.java | 62 +++++++++++++++++++ .../controllers/CreatingSchool.java | 24 ------- .../ironschool/entities/Course.java | 3 + .../ironschool/entities/Student.java | 3 + .../ironschool/entities/Teacher.java | 3 + .../ironschool/services/TeacherService.java | 7 ++- .../resources/application.properties | 1 + 16 files changed, 195 insertions(+), 28 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/homework-java-ironschool.iml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 ironschool/src/main/java/az/ironschool/ironschool/controllers/CreateSchool.java delete mode 100644 ironschool/src/main/java/az/ironschool/ironschool/controllers/CreatingSchool.java create mode 100644 out/production/homework-java-ironschool/resources/application.properties 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/ironschool/src/main/java/az/ironschool/ironschool/IronschoolApplication.java b/ironschool/src/main/java/az/ironschool/ironschool/IronschoolApplication.java index 30f71de4..f4845c54 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/IronschoolApplication.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/IronschoolApplication.java @@ -1,5 +1,6 @@ package az.ironschool.ironschool; +import az.ironschool.ironschool.controllers.CreateSchool; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -8,8 +9,17 @@ public class IronschoolApplication { public static void main(String[] args) { SpringApplication.run(IronschoolApplication.class, args); + CreateSchool.createSchool(); } - +// @Bean +// public CommandLineRunner run(TeacherService teacherService){ +// return args -> { +// Scanner sc = new Scanner (System.in); +// System.out.println("School creation has started..."); +// +// createSchool (teacherService,sc); +// }; +// } } 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..e9476302 --- /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 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++) { + az.ironschool.ironschool.entities.Teacher teacher = new az.ironschool.ironschool.entities.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.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/CreatingSchool.java b/ironschool/src/main/java/az/ironschool/ironschool/controllers/CreatingSchool.java deleted file mode 100644 index aa7b28fc..00000000 --- a/ironschool/src/main/java/az/ironschool/ironschool/controllers/CreatingSchool.java +++ /dev/null @@ -1,24 +0,0 @@ -package az.ironschool.ironschool.controllers; - -import az.ironschool.ironschool.entities.Teacher; - -public class CreatingSchool { - - // public static void createSchool () { - // System.out.println("Please enter a name for your school: " ); - // String schoolName = sc.next(); - - // System.out.println("Enter how many teachers you want to have in your school: "); - // int teacherCount = sc.nextInt; - // for (int i = 0 ; i < teacherCount ; i++){ - // Teacher teacher = new Teacher(); - // System.out.println("Enter the name of the teacher with id" + teacher.getTeacherId() + ": "); - // String teacherName = sc.next(); - // teacher.setName(); - - // System.out.println("Enter the teacher ' " + teacherName " 's salary: "); - // double teacherSalary = sc.next(); - // } - // } - -} diff --git a/ironschool/src/main/java/az/ironschool/ironschool/entities/Course.java b/ironschool/src/main/java/az/ironschool/ironschool/entities/Course.java index bfe0086d..4393bccd 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/entities/Course.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/entities/Course.java @@ -16,6 +16,9 @@ public Course(String name, double price) { this.name = name; this.price = price; } + public Course () { + this.courseId = UUID.randomUUID().toString(); + } public String getCourseId() { return courseId; diff --git a/ironschool/src/main/java/az/ironschool/ironschool/entities/Student.java b/ironschool/src/main/java/az/ironschool/ironschool/entities/Student.java index 0c74fcdb..6a540054 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/entities/Student.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/entities/Student.java @@ -16,6 +16,9 @@ public Student(String name, String address, String email) { this.address = address; this.email = email; } + public Student () { + this.studentId = UUID.randomUUID().toString(); + } public String getStudentId() { return studentId; diff --git a/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java b/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java index 710f2d00..552c661f 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java @@ -15,6 +15,9 @@ public Teacher(String name, double salary) { this.salary = salary; } + public Teacher () { + this.teacherId = UUID.randomUUID().toString(); + } public String getTeacherId() { return teacherId; diff --git a/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java b/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java index 9478ca42..cea38962 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java @@ -1,12 +1,11 @@ package az.ironschool.ironschool.services; +import az.ironschool.ironschool.entities.Teacher; + import java.util.ArrayList; import java.util.List; import java.util.Map; -import az.ironschool.ironschool.entities.Student; -import az.ironschool.ironschool.entities.Teacher; - public class TeacherService { private static Map teachers; @@ -32,4 +31,6 @@ public static void setTeachers(Map teachers) { } + public void put(String teacherId, Teacher teacher) { + } } diff --git a/out/production/homework-java-ironschool/resources/application.properties b/out/production/homework-java-ironschool/resources/application.properties new file mode 100644 index 00000000..64bb90af --- /dev/null +++ b/out/production/homework-java-ironschool/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=ironschool From 9f229c65d21cc82b19ff86aef79bbd22fe5c3e5d Mon Sep 17 00:00:00 2001 From: Sevinc Date: Fri, 6 Mar 2026 18:39:17 +0400 Subject: [PATCH 06/16] 2 controllers finished --- .../controllers/CreatingSchool.java | 24 ----------- .../controllers/StudentController.java | 43 +++++++++++++++++++ .../controllers/TeacherController.java | 34 +++++++++++++++ .../ironschool/services/TeacherService.java | 7 +-- 4 files changed, 81 insertions(+), 27 deletions(-) delete mode 100644 ironschool/src/main/java/az/ironschool/ironschool/controllers/CreatingSchool.java create mode 100644 ironschool/src/main/java/az/ironschool/ironschool/controllers/StudentController.java create mode 100644 ironschool/src/main/java/az/ironschool/ironschool/controllers/TeacherController.java diff --git a/ironschool/src/main/java/az/ironschool/ironschool/controllers/CreatingSchool.java b/ironschool/src/main/java/az/ironschool/ironschool/controllers/CreatingSchool.java deleted file mode 100644 index aa7b28fc..00000000 --- a/ironschool/src/main/java/az/ironschool/ironschool/controllers/CreatingSchool.java +++ /dev/null @@ -1,24 +0,0 @@ -package az.ironschool.ironschool.controllers; - -import az.ironschool.ironschool.entities.Teacher; - -public class CreatingSchool { - - // public static void createSchool () { - // System.out.println("Please enter a name for your school: " ); - // String schoolName = sc.next(); - - // System.out.println("Enter how many teachers you want to have in your school: "); - // int teacherCount = sc.nextInt; - // for (int i = 0 ; i < teacherCount ; i++){ - // Teacher teacher = new Teacher(); - // System.out.println("Enter the name of the teacher with id" + teacher.getTeacherId() + ": "); - // String teacherName = sc.next(); - // teacher.setName(); - - // System.out.println("Enter the teacher ' " + teacherName " 's salary: "); - // double teacherSalary = sc.next(); - // } - // } - -} 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..8ef994da --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/controllers/StudentController.java @@ -0,0 +1,43 @@ +package az.ironschool.ironschool.controllers; + +import java.util.ArrayList; +import java.util.List; + +import org.springframework.web.bind.annotation.RestController; + +import az.ironschool.ironschool.entities.Student; + +@RestController +public class StudentController { + + + // public void enroll(String studentId, String courseId) { + + // for (Student student : students.values()) { + + // if (student.getStudentId().equals(studentId)) { + // student.setCourse(courseService.getCourses().get(courseId)); + + // double coursePrice = courseService.getCourses().get(courseId).getPrice(); + // double courseProfit = courseService.getCourses().get(courseId).getMoney_earned(); + + + // courseService.getCourses().get(courseId).setMoney_earned(coursePrice+ courseProfit); + // } + // } + // } + + + + + // public List showStudents() { + // return new ArrayList<>(students.values()); + // } + + // public Student lookupCourse(String studentId) { + // return students.get(studentId); + // } + + + +} 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..5177e2a1 --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/controllers/TeacherController.java @@ -0,0 +1,34 @@ +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.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +import az.ironschool.ironschool.entities.Teacher; +import az.ironschool.ironschool.services.TeacherService; + +@RestController("/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); + + } + + +} diff --git a/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java b/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java index 9478ca42..436f6fce 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java @@ -16,18 +16,19 @@ public List showTeachers() { return new ArrayList<>(teachers.values()); } - public Teacher lookupCourse(String teacherId) { + public Teacher lookupTeacher(String teacherId) { return teachers.get(teacherId); } - public static Map getTeachers() { + //getter and setter + public Map getTeachers() { return teachers; } - public static void setTeachers(Map teachers) { + public void setTeachers(Map teachers) { TeacherService.teachers = teachers; } From 2e0beb24571904b7806a4036ef956881587dd35c Mon Sep 17 00:00:00 2001 From: Sevinc Date: Fri, 6 Mar 2026 22:18:04 +0400 Subject: [PATCH 07/16] controllers modified --- .../controllers/StudentController.java | 42 ++++++++++--------- .../ironschool/entities/Teacher.java | 6 +++ .../ironschool/services/StudentService.java | 2 +- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/ironschool/src/main/java/az/ironschool/ironschool/controllers/StudentController.java b/ironschool/src/main/java/az/ironschool/ironschool/controllers/StudentController.java index 8ef994da..cc43030a 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/controllers/StudentController.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/controllers/StudentController.java @@ -6,38 +6,40 @@ import org.springframework.web.bind.annotation.RestController; import az.ironschool.ironschool.entities.Student; +import az.ironschool.ironschool.services.StudentService; -@RestController -public class StudentController { - - - // public void enroll(String studentId, String courseId) { +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; - // for (Student student : students.values()) { - // if (student.getStudentId().equals(studentId)) { - // student.setCourse(courseService.getCourses().get(courseId)); +@RestController("/students") +public class StudentController { - // double coursePrice = courseService.getCourses().get(courseId).getPrice(); - // double courseProfit = courseService.getCourses().get(courseId).getMoney_earned(); - + private static StudentService studentService; - // courseService.getCourses().get(courseId).setMoney_earned(coursePrice+ courseProfit); - // } - // } - // } + @PostMapping("/enroll") + public void enroll(@RequestParam String studentId, @RequestParam String courseId) { + studentService.enroll(studentId, courseId); + + + } + - - - // public List showStudents() { - // return new ArrayList<>(students.values()); - // } + @GetMapping("/show-all") + public List showAll(){ + return studentService.showStudents(); + } // public Student lookupCourse(String studentId) { // return students.get(studentId); // } + + + } diff --git a/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java b/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java index 552c661f..2a89755b 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java @@ -14,6 +14,12 @@ public Teacher(String name, double salary) { this.name = name; this.salary = salary; } + + + + public Teacher() { + } + public Teacher () { this.teacherId = UUID.randomUUID().toString(); diff --git a/ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java b/ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java index 181add4c..52f64680 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java @@ -36,7 +36,7 @@ public List showStudents() { return new ArrayList<>(students.values()); } - public Student lookupCourse(String studentId) { + public Student lookupStudent(String studentId) { return students.get(studentId); } From 54a9162c55f2f3fd7ec7e30d26add421cb5a8989 Mon Sep 17 00:00:00 2001 From: Sevinc Date: Fri, 6 Mar 2026 22:20:35 +0400 Subject: [PATCH 08/16] createschool class modified #1 --- .../az/ironschool/ironschool/controllers/CreateSchool.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ironschool/src/main/java/az/ironschool/ironschool/controllers/CreateSchool.java b/ironschool/src/main/java/az/ironschool/ironschool/controllers/CreateSchool.java index e9476302..6dce7e8b 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/controllers/CreateSchool.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/controllers/CreateSchool.java @@ -1,7 +1,7 @@ package az.ironschool.ironschool.controllers; import az.ironschool.ironschool.services.TeacherService; - +import az.ironschool.ironschool.entities.Teacher; import java.util.Scanner; public class CreateSchool { @@ -27,7 +27,7 @@ public static void createSchool() { sc.nextLine(); for (int i = 1; i < teacherCount + 1; i++) { - az.ironschool.ironschool.entities.Teacher teacher = new az.ironschool.ironschool.entities.Teacher(); + Teacher teacher = new Teacher(); System.out.println("Enter the name of the teacher number " + i + " : "); String teacherName = sc.nextLine(); teacher.setName(teacherName); @@ -45,7 +45,7 @@ public static void createSchool() { } } if (teacherService != null) { - teacherService.put(teacher.getTeacherId(), teacher); + teacherService.getTeachers().put(teacher.getTeacherId(), teacher); } System.out.println("Enter the subject teacher ' " + teacherName + "' teachs: "); From 859f93d7ebb7d56188f3fc41bc8b499ec7fe4ea4 Mon Sep 17 00:00:00 2001 From: Sevinc Date: Fri, 6 Mar 2026 22:23:02 +0400 Subject: [PATCH 09/16] teacher class updated --- .../main/java/az/ironschool/ironschool/entities/Teacher.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java b/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java index 2a89755b..2d560634 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java @@ -16,11 +16,6 @@ public Teacher(String name, double salary) { } - - public Teacher() { - } - - public Teacher () { this.teacherId = UUID.randomUUID().toString(); } From a84579363e0199df4ba67ceb3174e119e813a732 Mon Sep 17 00:00:00 2001 From: Sevinc Date: Fri, 6 Mar 2026 22:33:04 +0400 Subject: [PATCH 10/16] ayble commit olda --- .../main/java/az/ironschool/ironschool/entities/Teacher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java b/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java index 2d560634..4f75d923 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java @@ -15,7 +15,7 @@ public Teacher(String name, double salary) { this.salary = salary; } - + //ONLY THIS CONTRUCTOR public Teacher () { this.teacherId = UUID.randomUUID().toString(); } From 1a4e64819cbd32a5880779e5535658e1ac1301b7 Mon Sep 17 00:00:00 2001 From: Sevinc Date: Sat, 7 Mar 2026 13:34:14 +0400 Subject: [PATCH 11/16] deleting unnecessery method --- .../java/az/ironschool/ironschool/services/TeacherService.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java b/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java index a654595b..5e2a9deb 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java @@ -31,7 +31,4 @@ public void setTeachers(Map teachers) { TeacherService.teachers = teachers; } - - public void put(String teacherId, Teacher teacher) { - } } From dfb4ca2b9cac468a5cbeabd24e6580ead485e179 Mon Sep 17 00:00:00 2001 From: Sevinc Date: Sat, 7 Mar 2026 22:04:30 +0400 Subject: [PATCH 12/16] cleaning and correcting --- .../ironschool/IronschoolApplication.java | 10 ---------- .../ironschool/controllers/StudentController.java | 14 +++++++++----- .../az/ironschool/ironschool/entities/Course.java | 10 +++++----- .../ironschool/services/CourseService.java | 15 +++++++++++---- .../ironschool/services/StudentService.java | 5 +++-- 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/ironschool/src/main/java/az/ironschool/ironschool/IronschoolApplication.java b/ironschool/src/main/java/az/ironschool/ironschool/IronschoolApplication.java index f4845c54..654b0a25 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/IronschoolApplication.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/IronschoolApplication.java @@ -12,14 +12,4 @@ public static void main(String[] args) { CreateSchool.createSchool(); } -// @Bean -// public CommandLineRunner run(TeacherService teacherService){ -// return args -> { -// Scanner sc = new Scanner (System.in); -// System.out.println("School creation has started..."); -// -// createSchool (teacherService,sc); -// }; -// } - } diff --git a/ironschool/src/main/java/az/ironschool/ironschool/controllers/StudentController.java b/ironschool/src/main/java/az/ironschool/ironschool/controllers/StudentController.java index cc43030a..b1cb8cb3 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/controllers/StudentController.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/controllers/StudentController.java @@ -9,6 +9,7 @@ import az.ironschool.ironschool.services.StudentService; 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.RequestBody; import org.springframework.web.bind.annotation.RequestParam; @@ -33,13 +34,16 @@ public List showAll(){ return studentService.showStudents(); } - // public Student lookupCourse(String studentId) { - // return students.get(studentId); - // } - + @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/entities/Course.java b/ironschool/src/main/java/az/ironschool/ironschool/entities/Course.java index 4393bccd..b1f42aca 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/entities/Course.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/entities/Course.java @@ -7,7 +7,7 @@ public class Course { private String courseId; private String name; private double price; - private double money_earned; + private double moneyEarned; private Teacher teacher; private int pageCount; @@ -42,12 +42,12 @@ public void setPrice(double price) { this.price = price; } - public double getMoney_earned() { - return money_earned; + public double getMoneyEarned() { + return moneyEarned; } - public void setMoney_earned(double money_earned) { - this.money_earned = money_earned; + public void setMoney_earned(double moneyEarned) { + this.moneyEarned = moneyEarned; } public Teacher getTeacher() { diff --git a/ironschool/src/main/java/az/ironschool/ironschool/services/CourseService.java b/ironschool/src/main/java/az/ironschool/ironschool/services/CourseService.java index b54cb15c..ffc14f50 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/services/CourseService.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/services/CourseService.java @@ -33,7 +33,7 @@ public Course lookupCourse(String courseId){ return courses.get(courseId); } - public double showProfit(){ + public double showSchoolProfit(){ double coursesTotal = 0; double teachersTotal = 0; @@ -46,7 +46,7 @@ public double showProfit(){ for (Course course : courses.values()) { - coursesTotal += course.getMoney_earned(); + coursesTotal += course.getMoneyEarned(); } @@ -55,13 +55,20 @@ public double showProfit(){ } + public double courseProfit(String courseId){ + + Course course = courses.get(courseId); + return course.getMoneyEarned() - course.getPrice(); + } + - public static Map getCourses() { +// getter and setter + public Map getCourses() { return courses; } - public static void setCourses(Map courses) { + public void setCourses(Map courses) { CourseService.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 index 52f64680..d09d5b71 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java @@ -6,7 +6,6 @@ import org.springframework.stereotype.Service; -import az.ironschool.ironschool.entities.Course; import az.ironschool.ironschool.entities.Student; @Service @@ -16,6 +15,8 @@ public class StudentService { private static CourseService courseService; + + public void enroll(String studentId, String courseId) { for (Student student : students.values()) { @@ -24,7 +25,7 @@ public void enroll(String studentId, String courseId) { student.setCourse(courseService.getCourses().get(courseId)); double coursePrice = courseService.getCourses().get(courseId).getPrice(); - double courseProfit = courseService.getCourses().get(courseId).getMoney_earned(); + double courseProfit = courseService.getCourses().get(courseId).getMoneyEarned(); courseService.getCourses().get(courseId).setMoney_earned(coursePrice+ courseProfit); From ef6ef07f5d6d2f809f358c0720f1abc3fed2cde4 Mon Sep 17 00:00:00 2001 From: Sevinc Date: Sat, 7 Mar 2026 22:04:50 +0400 Subject: [PATCH 13/16] . --- .../controllers/CourseController.java | 53 +++++++++++++++++++ .../ironschool/services/StudentService.java | 7 +++ 2 files changed, 60 insertions(+) create mode 100644 ironschool/src/main/java/az/ironschool/ironschool/controllers/CourseController.java 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..6899775f --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/controllers/CourseController.java @@ -0,0 +1,53 @@ +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 org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + + +@RestController("/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); + } + + +} diff --git a/ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java b/ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java index d09d5b71..76487ced 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java @@ -41,4 +41,11 @@ public Student lookupStudent(String studentId) { return students.get(studentId); } + public List getByCourse(String courseId){ + return students.values() + .stream() + .filter(student -> student.getCourse().getCourseId().equals(courseId)) + .toList(); + } + } From 20588845559fafe188220caf9ee4f0367fa79e1f Mon Sep 17 00:00:00 2001 From: Sevinc Date: Mon, 9 Mar 2026 22:57:21 +0400 Subject: [PATCH 14/16] logging completed --- ironschool/pom.xml | 6 ++++ .../ironschool/IronschoolApplication.java | 3 +- .../controllers/CourseController.java | 8 +++++ .../controllers/StudentController.java | 13 +++++-- .../controllers/TeacherController.java | 6 ++++ .../ironschool/dtos/NewStudentDTO.java | 24 +++++++++++++ .../ironschool/entities/Course.java | 25 ++++++++----- .../ironschool/entities/Student.java | 10 ++++++ .../ironschool/entities/Teacher.java | 21 +++++++++++ .../ironschool/services/CourseService.java | 17 ++++++++- .../ironschool/services/StudentService.java | 36 ++++++++++++------- .../ironschool/services/TeacherService.java | 16 +++++++-- .../{controllers => utils}/CreateSchool.java | 2 +- .../ironschool/ironschool/utils/Logging.java | 23 ++++++++++++ .../resources/application.properties | 1 - 15 files changed, 181 insertions(+), 30 deletions(-) create mode 100644 ironschool/src/main/java/az/ironschool/ironschool/dtos/NewStudentDTO.java rename ironschool/src/main/java/az/ironschool/ironschool/{controllers => utils}/CreateSchool.java (98%) create mode 100644 ironschool/src/main/java/az/ironschool/ironschool/utils/Logging.java delete mode 100644 out/production/homework-java-ironschool/resources/application.properties diff --git a/ironschool/pom.xml b/ironschool/pom.xml index 784d67aa..815d237f 100644 --- a/ironschool/pom.xml +++ b/ironschool/pom.xml @@ -29,6 +29,7 @@ 17 + org.springframework.boot @@ -46,6 +47,11 @@ spring-boot-starter-webmvc-test test + + org.springframework.boot + spring-boot-starter-validation + + diff --git a/ironschool/src/main/java/az/ironschool/ironschool/IronschoolApplication.java b/ironschool/src/main/java/az/ironschool/ironschool/IronschoolApplication.java index 654b0a25..de689381 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/IronschoolApplication.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/IronschoolApplication.java @@ -1,6 +1,5 @@ package az.ironschool.ironschool; -import az.ironschool.ironschool.controllers.CreateSchool; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -9,7 +8,7 @@ public class IronschoolApplication { public static void main(String[] args) { SpringApplication.run(IronschoolApplication.class, args); - CreateSchool.createSchool(); + } } diff --git a/ironschool/src/main/java/az/ironschool/ironschool/controllers/CourseController.java b/ironschool/src/main/java/az/ironschool/ironschool/controllers/CourseController.java index 6899775f..79d75712 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/controllers/CourseController.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/controllers/CourseController.java @@ -9,9 +9,11 @@ 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.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -24,6 +26,7 @@ public class CourseController { @PutMapping("/assign") public void assign(@RequestParam String teacherId, @RequestParam String courseId){ courseService.assign(teacherId, courseId); + } @@ -48,6 +51,11 @@ public double showSchoolProfit(){ 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/StudentController.java b/ironschool/src/main/java/az/ironschool/ironschool/controllers/StudentController.java index b1cb8cb3..a91cd571 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/controllers/StudentController.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/controllers/StudentController.java @@ -1,16 +1,18 @@ package az.ironschool.ironschool.controllers; -import java.util.ArrayList; 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.RequestParam; @@ -20,8 +22,15 @@ public class StudentController { private static StudentService studentService; + @PostMapping("/register-new") + public void newStudent(@Valid @RequestBody NewStudentDTO newStudent){ - @PostMapping("/enroll") + studentService.registerNewStudent(newStudent); + + } + + + @PutMapping("/enroll") public void enroll(@RequestParam String studentId, @RequestParam String courseId) { studentService.enroll(studentId, 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 index 5177e2a1..a098a9d0 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/controllers/TeacherController.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/controllers/TeacherController.java @@ -5,7 +5,9 @@ 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.RequestParam; import org.springframework.web.bind.annotation.RestController; import az.ironschool.ironschool.entities.Teacher; @@ -30,5 +32,9 @@ public Teacher lookupTeacher(@PathVariable String 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..1a78aa5d --- /dev/null +++ b/ironschool/src/main/java/az/ironschool/ironschool/dtos/NewStudentDTO.java @@ -0,0 +1,24 @@ +package az.ironschool.ironschool.dtos; + +public class NewStudentDTO { + + //name, address, email, + + private String name; + private String address; + private String 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 index b1f42aca..b86f0124 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/entities/Course.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/entities/Course.java @@ -2,14 +2,21 @@ 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 pageCount; + private int sold; public Course(String name, double price) { this.courseId = UUID.randomUUID().toString(); @@ -26,6 +33,8 @@ public String getCourseId() { + //getters and setters + public String getName() { return name; } @@ -46,7 +55,7 @@ public double getMoneyEarned() { return moneyEarned; } - public void setMoney_earned(double moneyEarned) { + public void setMoneyEarned(double moneyEarned) { this.moneyEarned = moneyEarned; } @@ -57,15 +66,15 @@ public Teacher getTeacher() { public void setTeacher(Teacher teacher) { this.teacher = teacher; } - - public int getPageCount() { - return pageCount; + public int getSold() { + return sold; } - - public void setPageCount(int pageCount) { - this.pageCount = pageCount; + 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 index 6a540054..fdcddd2d 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/entities/Student.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/entities/Student.java @@ -2,12 +2,22 @@ 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) { diff --git a/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java b/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java index 4f75d923..408b22c4 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java @@ -2,11 +2,19 @@ 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) { @@ -14,12 +22,25 @@ public Teacher(String name, double salary) { this.name = name; this.salary = salary; } + + + public Teacher(String name, double salary, String subject) { + 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; } diff --git a/ironschool/src/main/java/az/ironschool/ironschool/services/CourseService.java b/ironschool/src/main/java/az/ironschool/ironschool/services/CourseService.java index ffc14f50..2cad903a 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/services/CourseService.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/services/CourseService.java @@ -6,6 +6,7 @@ import az.ironschool.ironschool.entities.Course; import az.ironschool.ironschool.entities.Teacher; +import az.ironschool.ironschool.utils.Logging; public class CourseService { @@ -20,16 +21,25 @@ 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); } @@ -50,7 +60,7 @@ public double showSchoolProfit(){ } - + Logging.log("school's profit is: "+ (coursesTotal - teachersTotal)); return coursesTotal - teachersTotal; } @@ -58,9 +68,14 @@ public double showSchoolProfit(){ 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 diff --git a/ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java b/ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java index 76487ced..903d41b4 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java @@ -4,9 +4,12 @@ import java.util.List; import java.util.Map; +import org.apache.commons.logging.Log; 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 { @@ -15,37 +18,44 @@ public class StudentService { private static CourseService courseService; + public void registerNewStudent(NewStudentDTO dto) { + new Student(dto.getName(), dto.getAddress(), dto.getEmail()); + Logging.log("new student registered"); + } public void enroll(String studentId, String courseId) { - for (Student student : students.values()) { + students.get(studentId).setCourse(courseService.getCourses().get(courseId)); - if (student.getStudentId().equals(studentId)) { - student.setCourse(courseService.getCourses().get(courseId)); + double coursePrice = courseService.getCourses().get(courseId).getPrice(); + double courseProfit = courseService.getCourses().get(courseId).getMoneyEarned(); - double coursePrice = courseService.getCourses().get(courseId).getPrice(); - double courseProfit = courseService.getCourses().get(courseId).getMoneyEarned(); - + courseService.getCourses().get(courseId).setMoneyEarned(coursePrice + courseProfit); - courseService.getCourses().get(courseId).setMoney_earned(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){ + 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(); + .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 index 5e2a9deb..0147e637 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java @@ -1,6 +1,7 @@ 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; @@ -12,14 +13,18 @@ public class TeacherService { public List showTeachers() { + + Logging.log("list of teachers returned"); + return new ArrayList<>(teachers.values()); } public Teacher lookupTeacher(String teacherId) { - return teachers.get(teacherId); - } + Logging.log("teacher named "+ teachers.get(teacherId).getName() +" looked up"); + return teachers.get(teacherId); + } //getter and setter @@ -27,8 +32,15 @@ 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/controllers/CreateSchool.java b/ironschool/src/main/java/az/ironschool/ironschool/utils/CreateSchool.java similarity index 98% rename from ironschool/src/main/java/az/ironschool/ironschool/controllers/CreateSchool.java rename to ironschool/src/main/java/az/ironschool/ironschool/utils/CreateSchool.java index 6dce7e8b..5e0ef30c 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/controllers/CreateSchool.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/utils/CreateSchool.java @@ -1,4 +1,4 @@ -package az.ironschool.ironschool.controllers; +package az.ironschool.ironschool.utils; import az.ironschool.ironschool.services.TeacherService; import az.ironschool.ironschool.entities.Teacher; 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/out/production/homework-java-ironschool/resources/application.properties b/out/production/homework-java-ironschool/resources/application.properties deleted file mode 100644 index 64bb90af..00000000 --- a/out/production/homework-java-ironschool/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.application.name=ironschool From 68fd10ae9c475772a7467cee711dc70cadfc3594 Mon Sep 17 00:00:00 2001 From: Sevinc Date: Tue, 10 Mar 2026 01:29:23 +0400 Subject: [PATCH 15/16] unit testing done --- ironschool/log.txt | 26 ++++ ironschool/pom.xml | 8 ++ .../{utils => controllers}/CreateSchool.java | 2 +- .../ironschool/dtos/NewStudentDTO.java | 6 + .../ironschool/entities/Teacher.java | 2 +- .../ironschool/services/CourseService.java | 18 ++- .../ironschool/services/StudentService.java | 4 +- .../ironschool/services/TeacherService.java | 4 +- .../ironschool/CourseServiceTest.java | 94 +++++++++++++ .../ironschool/StudentServiceTests.java | 127 ++++++++++++++++++ .../ironschool/TeacherServiceTests.java | 87 ++++++++++++ 11 files changed, 369 insertions(+), 9 deletions(-) create mode 100644 ironschool/log.txt rename ironschool/src/main/java/az/ironschool/ironschool/{utils => controllers}/CreateSchool.java (98%) create mode 100644 ironschool/src/test/java/az/ironschool/ironschool/CourseServiceTest.java create mode 100644 ironschool/src/test/java/az/ironschool/ironschool/StudentServiceTests.java create mode 100644 ironschool/src/test/java/az/ironschool/ironschool/TeacherServiceTests.java 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/pom.xml b/ironschool/pom.xml index 815d237f..dfe62a8d 100644 --- a/ironschool/pom.xml +++ b/ironschool/pom.xml @@ -42,6 +42,14 @@ runtime true + + + org.junit.jupiter + junit-jupiter + 5.10.2 + test + + org.springframework.boot spring-boot-starter-webmvc-test diff --git a/ironschool/src/main/java/az/ironschool/ironschool/utils/CreateSchool.java b/ironschool/src/main/java/az/ironschool/ironschool/controllers/CreateSchool.java similarity index 98% rename from ironschool/src/main/java/az/ironschool/ironschool/utils/CreateSchool.java rename to ironschool/src/main/java/az/ironschool/ironschool/controllers/CreateSchool.java index 5e0ef30c..6dce7e8b 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/utils/CreateSchool.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/controllers/CreateSchool.java @@ -1,4 +1,4 @@ -package az.ironschool.ironschool.utils; +package az.ironschool.ironschool.controllers; import az.ironschool.ironschool.services.TeacherService; import az.ironschool.ironschool.entities.Teacher; diff --git a/ironschool/src/main/java/az/ironschool/ironschool/dtos/NewStudentDTO.java b/ironschool/src/main/java/az/ironschool/ironschool/dtos/NewStudentDTO.java index 1a78aa5d..fb692785 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/dtos/NewStudentDTO.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/dtos/NewStudentDTO.java @@ -9,6 +9,12 @@ public class NewStudentDTO { 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; } diff --git a/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java b/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java index 408b22c4..9c4cac01 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/entities/Teacher.java @@ -25,7 +25,7 @@ public Teacher(String name, double salary) { - public Teacher(String name, double salary, String subject) { + public Teacher(String name, String subject, double salary) { this.teacherId = UUID.randomUUID().toString(); this.name = name; this.salary = salary; diff --git a/ironschool/src/main/java/az/ironschool/ironschool/services/CourseService.java b/ironschool/src/main/java/az/ironschool/ironschool/services/CourseService.java index 2cad903a..3430fb13 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/services/CourseService.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/services/CourseService.java @@ -10,9 +10,21 @@ public class CourseService { - private static Map courses; + private Map courses; - private static TeacherService teacherService; + private TeacherService teacherService; + + + + + public CourseService(TeacherService teacherService) { + this.teacherService = teacherService; + } + + + + public CourseService() { + } @@ -84,7 +96,7 @@ public Map getCourses() { } public void setCourses(Map courses) { - CourseService.courses = 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 index 903d41b4..f81e822c 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/services/StudentService.java @@ -4,7 +4,6 @@ import java.util.List; import java.util.Map; -import org.apache.commons.logging.Log; import org.springframework.stereotype.Service; import az.ironschool.ironschool.dtos.NewStudentDTO; @@ -19,7 +18,8 @@ public class StudentService { private static CourseService courseService; public void registerNewStudent(NewStudentDTO dto) { - new Student(dto.getName(), dto.getAddress(), dto.getEmail()); + Student newSt = new Student(dto.getName(), dto.getAddress(), dto.getEmail()); + students.put(newSt.getStudentId(), newSt); Logging.log("new student registered"); } diff --git a/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java b/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java index 0147e637..0afe4dd5 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/services/TeacherService.java @@ -21,8 +21,8 @@ public List showTeachers() { public Teacher lookupTeacher(String teacherId) { - Logging.log("teacher named "+ teachers.get(teacherId).getName() +" looked up"); - + 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); } 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/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()); + } + +} From 39f68af2821c897da9d0f3bffe82754eda599fc4 Mon Sep 17 00:00:00 2001 From: Sevinc Date: Tue, 10 Mar 2026 17:06:21 +0400 Subject: [PATCH 16/16] some correctings --- .../ironschool/ironschool/controllers/CourseController.java | 4 +++- .../ironschool/ironschool/controllers/StudentController.java | 4 +++- .../ironschool/ironschool/controllers/TeacherController.java | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ironschool/src/main/java/az/ironschool/ironschool/controllers/CourseController.java b/ironschool/src/main/java/az/ironschool/ironschool/controllers/CourseController.java index 79d75712..121118aa 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/controllers/CourseController.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/controllers/CourseController.java @@ -13,12 +13,14 @@ 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("/courses") +@RestController +@RequestMapping("/courses") public class CourseController { private static CourseService courseService; diff --git a/ironschool/src/main/java/az/ironschool/ironschool/controllers/StudentController.java b/ironschool/src/main/java/az/ironschool/ironschool/controllers/StudentController.java index a91cd571..cda53d0a 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/controllers/StudentController.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/controllers/StudentController.java @@ -14,10 +14,12 @@ 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("/students") +@RestController +@RequestMapping("/students") public class StudentController { private static StudentService studentService; diff --git a/ironschool/src/main/java/az/ironschool/ironschool/controllers/TeacherController.java b/ironschool/src/main/java/az/ironschool/ironschool/controllers/TeacherController.java index a098a9d0..c0265f20 100644 --- a/ironschool/src/main/java/az/ironschool/ironschool/controllers/TeacherController.java +++ b/ironschool/src/main/java/az/ironschool/ironschool/controllers/TeacherController.java @@ -7,13 +7,15 @@ 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("/teachers") +@RestController +@RequestMapping("/teachers") public class TeacherController { private static TeacherService service;