From 2c19d7ab825310c92e087bb68a80b58b7fcc3048 Mon Sep 17 00:00:00 2001 From: Anar Vali Date: Sun, 8 Mar 2026 09:41:33 -0700 Subject: [PATCH 1/7] ironschoo.3 --- .idea/.gitignore | 10 + .idea/ironschool.iml | 9 + .idea/misc.xml | 6 + .idea/modules.xml | 9 + .idea/vcs.xml | 6 + 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 + .../ironhack/ironschool/models/Course.java | 34 ++ .../ironhack/ironschool/models/Student.java | 33 ++ .../ironhack/ironschool/models/Teacher.java | 24 ++ .../src/main/resources/application.properties | 1 + .../IronschoolApplicationTests.java | 13 + homework-java-ironschool | 1 + 18 files changed, 741 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/ironschool.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml 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/com/ironhack/ironschool/IronschoolApplication.java create mode 100644 Ironschool/src/main/java/com/ironhack/ironschool/models/Course.java create mode 100644 Ironschool/src/main/java/com/ironhack/ironschool/models/Student.java create mode 100644 Ironschool/src/main/java/com/ironhack/ironschool/models/Teacher.java create mode 100644 Ironschool/src/main/resources/application.properties create mode 100644 Ironschool/src/test/java/com/ironhack/ironschool/IronschoolApplicationTests.java create mode 160000 homework-java-ironschool 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/ironschool.iml b/.idea/ironschool.iml new file mode 100644 index 00000000..d6ebd480 --- /dev/null +++ b/.idea/ironschool.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..a20905f6 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..98d28b2b --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..c0589aa1 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Ironschool/.gitattributes b/Ironschool/.gitattributes new file mode 100644 index 00000000..3b41682a --- /dev/null +++ b/Ironschool/.gitattributes @@ -0,0 +1,2 @@ +/mvnw text eol=lf +*.cmd text eol=crlf diff --git a/Ironschool/.gitignore b/Ironschool/.gitignore new file mode 100644 index 00000000..667aaef0 --- /dev/null +++ b/Ironschool/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/Ironschool/.mvn/wrapper/maven-wrapper.properties b/Ironschool/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 00000000..8dea6c22 --- /dev/null +++ b/Ironschool/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,3 @@ +wrapperVersion=3.3.4 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.12/apache-maven-3.9.12-bin.zip diff --git a/Ironschool/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..d3fb6a17 --- /dev/null +++ b/Ironschool/pom.xml @@ -0,0 +1,60 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 4.0.3 + + + com.ironhack + Ironschool + 0.0.1-SNAPSHOT + Ironschool + Ironschool + + + + + + + + + + + + + + + 17 + + + + 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/com/ironhack/ironschool/IronschoolApplication.java b/Ironschool/src/main/java/com/ironhack/ironschool/IronschoolApplication.java new file mode 100644 index 00000000..11ea10bc --- /dev/null +++ b/Ironschool/src/main/java/com/ironhack/ironschool/IronschoolApplication.java @@ -0,0 +1,13 @@ +package com.ironhack.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/com/ironhack/ironschool/models/Course.java b/Ironschool/src/main/java/com/ironhack/ironschool/models/Course.java new file mode 100644 index 00000000..9399fd24 --- /dev/null +++ b/Ironschool/src/main/java/com/ironhack/ironschool/models/Course.java @@ -0,0 +1,34 @@ +package com.ironhack.ironschool.models; + + +import java.util.UUID; + +public class Course { + private String courseId; + private String name; + private double price; + private double money_earned; + private Teacher teacher; // This stays null until a teacher is ASSIGNED + + public Course(String name, double price) { + this.courseId = UUID.randomUUID().toString(); + this.name = name; + this.price = price; + this.money_earned = 0; // Always starts at 0 + } + + public String getCourseId() { return courseId; } + public void setCourseId(String courseId) { this.courseId = 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; } +} \ No newline at end of file diff --git a/Ironschool/src/main/java/com/ironhack/ironschool/models/Student.java b/Ironschool/src/main/java/com/ironhack/ironschool/models/Student.java new file mode 100644 index 00000000..e81a7fba --- /dev/null +++ b/Ironschool/src/main/java/com/ironhack/ironschool/models/Student.java @@ -0,0 +1,33 @@ +package com.ironhack.ironschool.models; + +import java.util.UUID; + +public class Student { + private String studentId; + private String name; + private String address; + private String email; + private Course course; // This stays null until the student is ENROLLED + + 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 void setStudentId(String studentId) { this.studentId = 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; } +} \ No newline at end of file diff --git a/Ironschool/src/main/java/com/ironhack/ironschool/models/Teacher.java b/Ironschool/src/main/java/com/ironhack/ironschool/models/Teacher.java new file mode 100644 index 00000000..638bc7c6 --- /dev/null +++ b/Ironschool/src/main/java/com/ironhack/ironschool/models/Teacher.java @@ -0,0 +1,24 @@ +package com.ironhack.ironschool.models; + +import java.util.UUID; + +public class Teacher { + private String teacherId; + private String name; + private double salary; + + public Teacher(String name, double salary) { + this.teacherId = UUID.randomUUID().toString(); + this.name = name; + this.salary = salary; + } + + public String getTeacherId() { return teacherId; } + public void setTeacherId(String teacherId) { this.teacherId = 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; } +} \ No newline at end of file diff --git a/Ironschool/src/main/resources/application.properties b/Ironschool/src/main/resources/application.properties new file mode 100644 index 00000000..0ab37189 --- /dev/null +++ b/Ironschool/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=Ironschool diff --git a/Ironschool/src/test/java/com/ironhack/ironschool/IronschoolApplicationTests.java b/Ironschool/src/test/java/com/ironhack/ironschool/IronschoolApplicationTests.java new file mode 100644 index 00000000..28b8b6c7 --- /dev/null +++ b/Ironschool/src/test/java/com/ironhack/ironschool/IronschoolApplicationTests.java @@ -0,0 +1,13 @@ +package com.ironhack.ironschool; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class IronschoolApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/homework-java-ironschool b/homework-java-ironschool new file mode 160000 index 00000000..20093cd0 --- /dev/null +++ b/homework-java-ironschool @@ -0,0 +1 @@ +Subproject commit 20093cd0b21bacf2d3c2815dbc364eccf51c4aef From 69b4cc8033c8d32d8eb6ea73dd232f763f63794b Mon Sep 17 00:00:00 2001 From: yagutrslbyl Date: Mon, 9 Mar 2026 11:06:30 +0400 Subject: [PATCH 2/7] Service classes added --- .idea/compiler.xml | 18 ++++ .idea/ironschool.iml | 5 +- .idea/jarRepositories.xml | 20 +++++ .idea/misc.xml | 8 ++ .idea/modules.xml | 1 - .idea/vcs.xml | 1 + Ironschool/pom.xml | 8 +- .../ironschool/services/SchoolService.java | 82 +++++++++++++++++++ 8 files changed, 139 insertions(+), 4 deletions(-) create mode 100644 .idea/compiler.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 Ironschool/src/main/java/com/ironhack/ironschool/services/SchoolService.java diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 00000000..d06124d5 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/ironschool.iml b/.idea/ironschool.iml index d6ebd480..5358fe94 100644 --- a/.idea/ironschool.iml +++ b/.idea/ironschool.iml @@ -2,7 +2,10 @@ - + + + + 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 index a20905f6..68b5b753 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,13 @@ + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml index 98d28b2b..b9ee0c3e 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,6 @@ - diff --git a/.idea/vcs.xml b/.idea/vcs.xml index c0589aa1..dbce9205 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,7 @@ + \ No newline at end of file diff --git a/Ironschool/pom.xml b/Ironschool/pom.xml index d3fb6a17..087ac45c 100644 --- a/Ironschool/pom.xml +++ b/Ironschool/pom.xml @@ -5,8 +5,8 @@ org.springframework.boot spring-boot-starter-parent - 4.0.3 - + 3.2.5 + com.ironhack Ironschool @@ -30,6 +30,10 @@ 17 + + org.springframework.boot + spring-boot-starter + org.springframework.boot spring-boot-starter-webmvc diff --git a/Ironschool/src/main/java/com/ironhack/ironschool/services/SchoolService.java b/Ironschool/src/main/java/com/ironhack/ironschool/services/SchoolService.java new file mode 100644 index 00000000..edf580d5 --- /dev/null +++ b/Ironschool/src/main/java/com/ironhack/ironschool/services/SchoolService.java @@ -0,0 +1,82 @@ +package com.ironhack.ironschool.services; + +import com.ironhack.ironschool.models.Course; +import com.ironhack.ironschool.models.Student; +import com.ironhack.ironschool.models.Teacher; +import org.springframework.stereotype.Service; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +@Service +public class SchoolService { + + private final Map teacherMap = new HashMap<>(); + private final Map courseMap = new HashMap<>(); + private final Map studentMap = new HashMap<>(); + + public void addTeacher(Teacher teacher) { + teacherMap.put(teacher.getTeacherId() , teacher); + } + public void addCourse(Course course) { + courseMap.put(course.getCourseId(), course); + + } + public void addStudent(Student student) { + studentMap.put(student.getStudentId(), student); + + } + + + public void enrollStudent(String studentId, String courseId) { + Student student = studentMap.get(studentId); + Course course = courseMap.get(courseId); + + if (student == null) throw new IllegalArgumentException("Student ID not found: " + studentId); + if (course == null ) throw new IllegalArgumentException("Course ID not found: " + courseId); + + student.setCourse(course); + + + double currentMoney = course.getMoney_earned(); + course.setMoney_earned(currentMoney + course.getPrice()); + + + } + + public void assignTeacher(String teacherId, String courseId) { + Teacher teacher = teacherMap.get(teacherId); + Course course = courseMap.get(courseId); + + if (teacher == null) throw new IllegalArgumentException("Teacher ID not found: " + teacherId); + if (course == null) throw new IllegalArgumentException("Course ID not found: " + courseId); + + course.setTeacher(teacher); + } + + public double calculateProfit() { + double totalRevenue = 0; + double totalSalaries = 0; + + + + for (Course course : courseMap.values()) { + + totalRevenue += course.getMoney_earned( ); + } + + for (Teacher teacher : teacherMap.values()) { + totalSalaries += teacher.getSalary(); + } + + return totalRevenue - totalSalaries; + } + + public Collection getAllTeachers() { return teacherMap.values(); } + public Collection getAllCourses() { return courseMap.values(); } + public Collection getAllStudents() { return studentMap.values(); } + + public Teacher getTeacherById(String id) { return teacherMap.get(id); } + public Course getCourseById(String id) { return courseMap.get(id); } + public Student getStudentById(String id) { return studentMap.get(id); } +} \ No newline at end of file From 0f80df353682bff0f779dcb6a33df89f6c784efc Mon Sep 17 00:00:00 2001 From: yagutrslbyl Date: Mon, 9 Mar 2026 11:12:57 +0400 Subject: [PATCH 3/7] ide config --- .idea/misc.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/.idea/misc.xml b/.idea/misc.xml index a20905f6..fb6489a5 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,6 @@ + From e26f2faf6738ade80e25d6ec53bebe82c7dcdf57 Mon Sep 17 00:00:00 2001 From: Anar Vali Date: Mon, 9 Mar 2026 10:19:12 -0700 Subject: [PATCH 4/7] full project --- Ironschool/pom.xml | 4 +- .../ironschool/IronschoolApplication.java | 152 +++++++++++++++++- .../controllers/SchoolController.java | 41 +++++ .../ironschool/SchoolServiceTest.java | 75 +++++++++ 4 files changed, 268 insertions(+), 4 deletions(-) create mode 100644 Ironschool/src/main/java/com/ironhack/ironschool/controllers/SchoolController.java create mode 100644 Ironschool/src/test/java/com/ironhack/ironschool/SchoolServiceTest.java diff --git a/Ironschool/pom.xml b/Ironschool/pom.xml index 087ac45c..dcd19c9d 100644 --- a/Ironschool/pom.xml +++ b/Ironschool/pom.xml @@ -36,7 +36,7 @@ org.springframework.boot - spring-boot-starter-webmvc + spring-boot-starter-web @@ -47,7 +47,7 @@ org.springframework.boot - spring-boot-starter-webmvc-test + spring-boot-starter-test test diff --git a/Ironschool/src/main/java/com/ironhack/ironschool/IronschoolApplication.java b/Ironschool/src/main/java/com/ironhack/ironschool/IronschoolApplication.java index 11ea10bc..d95cc89a 100644 --- a/Ironschool/src/main/java/com/ironhack/ironschool/IronschoolApplication.java +++ b/Ironschool/src/main/java/com/ironhack/ironschool/IronschoolApplication.java @@ -1,13 +1,161 @@ package com.ironhack.ironschool; +import com.ironhack.ironschool.models.Course; +import com.ironhack.ironschool.models.Student; +import com.ironhack.ironschool.models.Teacher; +import com.ironhack.ironschool.services.SchoolService; +import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import java.util.Scanner; @SpringBootApplication -public class IronschoolApplication { +public class + +IronschoolApplication implements CommandLineRunner { + + private final SchoolService schoolService; + + + public IronschoolApplication(SchoolService schoolService) { + this.schoolService = schoolService; + } public static void main(String[] args) { SpringApplication.run(IronschoolApplication.class, args); } -} + + @Override + public void run(String... args) { + Scanner scanner = new Scanner(System.in); + + System.out.println("=== Welcome to the School Management System ==="); + System.out.print("Enter the name fr the school: "); + String schoolName = scanner.nextLine(); + + + int numTeachers = getValidInt(scanner , "How many teachers should be created? "); + for (int i = 0; i < numTeachers; i++) { + + System.out.print("Enter name for teacher " + (i + 1) + ": "); + String name = scanner.nextLine(); + double salary = getValidDouble(scanner, "Enter salary for teacher " + (i + 1) + ": "); + schoolService.addTeacher(new Teacher(name, salary)); + } + + + + int numCourses = getValidInt(scanner, "How many courses should be created? "); + for (int i = 0; i < numCourses; i++) { + System.out.print("Enter name for course " + (i + 1) + ": "); + String name = scanner.nextLine(); + + double price = getValidDouble(scanner, "Enter price for course " + (i + 1) + ": "); + schoolService.addCourse(new Course(name, price)); + + + + } + + int numStudents = getValidInt(scanner, "How many students should be created? "); + for ( int i = 0; i < numStudents; i++) { + System.out.print("Enter name for student " + (i + 1) + ": "); + String name = scanner.nextLine(); + System.out.print("Enter address for student " + (i + 1) + ": "); + String address = scanner.nextLine(); + System.out.print("Enter email for student " + (i + 1) + ": "); + String email = scanner.nextLine(); + schoolService.addStudent(new Student(name, address, email)); + } + + System.out.println ("\n=== Setup complete for " + schoolName + " ==="); + System.out.println("Type 'HELP' to see all available commands."); + + + while (true) { + System.out.print("\n> "); + String input = scanner.nextLine().trim(); + String[] parts = input.split(" "); // Splits "ENROLL S-1 C-1" into an array of 3 words + + try { + if (input.equals("HELP")) { + + System.out.println("Commands: ENROLL [studentId] [courseId], ASSIGN [teacherId] [courseId], SHOW COURSES, SHOW STUDENTS, SHOW TEACHERS, LOOKUP COURSE [id], LOOKUP STUDENT [id], LOOKUP TEACHER [id], SHOW PROFIT"); + } + + else if (input.startsWith("ENROLL") && parts.length == 3) { + schoolService.enrollStudent(parts[1], parts[2]); + System.out.println("Success: Student enrolled."); + } + + else if (input.startsWith("ASSIGN") && parts.length == 3) { + schoolService.assignTeacher(parts[1], parts[2]); + System.out.println("Success: Teacher assigned."); + } + else if (input.equals("SHOW PROFIT")) { + System.out.println("Total Profit: $" + schoolService.calculateProfit()); + } + else if (input.equals("SHOW COURSES")) { + schoolService.getAllCourses().forEach(c -> System.out.println("ID: " + c.getCourseId() + " | Name: " + c.getName() + " | Price: $" + c.getPrice())); + } + else if (input.equals("SHOW STUDENTS")) { + schoolService.getAllStudents().forEach(s -> System.out.println("ID: " + s.getStudentId() + " | Name: " + s.getName())); + } + else if (input.equals("SHOW TEACHERS")) { + + schoolService.getAllTeachers().forEach(t -> System.out.println("ID: " + t.getTeacherId() + " | Name: " + t.getName() + " | Salary: $" + t.getSalary())); + } + else if (input.startsWith("LOOKUP COURSE") && parts.length == 3) { + Course c = schoolService.getCourseById(parts[2]); + if (c != null) System.out.println("Course: " + c.getName() + " | Earned: $" + c.getMoney_earned() + " | Teacher: " + (c.getTeacher() != null ? c.getTeacher().getName() : "None")); + else System.out.println("Course not found."); + } + + else if (input.startsWith( "LOOKUP STUDENT") && parts.length == 3) { + Student s = schoolService.getStudentById(parts[2]); + if (s != null) System.out.println("Student: " + s.getName() + " | Email: " + s.getEmail() + " | Enrolled in: " + (s.getCourse() != null ? s.getCourse().getName() : "None")); + else System.out.println("Student not found."); + } + else if (input.startsWith("LOOKUP TEACHER") && parts.length == 3) { + Teacher t = schoolService.getTeacherById(parts[2]); + if (t != null) System.out.println("Teacher: " + t.getName() + " | Salary: $" + t.getSalary()); + else System.out.println("Teacher not found."); + } + else { + System.out.println("Command not recognized or missing IDs. Type HELP for the list."); + } + } catch (IllegalArgumentException e) { + System.out.println("Logic Error: " + e.getMessage()); + } catch (Exception e) { + System.out.println("An unexpected error occurred. Please check your command format."); + } + } + } + + + private int getValidInt(Scanner scanner, String prompt) { + while (true ) { + System.out.print(prompt); + try { + return Integer.parseInt(scanner.nextLine().trim()); + } catch (NumberFormatException e) { + System.out.println("Invalid input. Please enter a whole number (e.g., 2)."); + } + } + + + } + + private double getValidDouble(Scanner scanner, String prompt) { + while (true) { + System.out.print(prompt) ; + try { + return Double.parseDouble(scanner.nextLine().trim()); + } catch (NumberFormatException e) { + System.out.println("Invalid input. Please enter a valid number (e.g., 50.5)."); + } + + } + } +} \ No newline at end of file diff --git a/Ironschool/src/main/java/com/ironhack/ironschool/controllers/SchoolController.java b/Ironschool/src/main/java/com/ironhack/ironschool/controllers/SchoolController.java new file mode 100644 index 00000000..75b110f9 --- /dev/null +++ b/Ironschool/src/main/java/com/ironhack/ironschool/controllers/SchoolController.java @@ -0,0 +1,41 @@ +package com.ironhack.ironschool.controllers; + +import com.ironhack.ironschool.models.Course; +import com.ironhack.ironschool.models.Student; +import com.ironhack.ironschool.models.Teacher; +import com.ironhack.ironschool.services.SchoolService; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Collection; + +@RestController +public class SchoolController { + + private final SchoolService schoolService; + + public SchoolController(SchoolService schoolService) { + this.schoolService = schoolService; + } + + + @GetMapping("/students") + public Collection viewStudents() { + return schoolService.getAllStudents(); + } + + @GetMapping("/courses") + public Collection viewCourses() { + return schoolService.getAllCourses(); + } + + @GetMapping("/teachers") + public Collection viewTeachers() { + return schoolService.getAllTeachers(); + } + + @GetMapping("/profit") + public String viewProfit() { + return "Total Profit: $" + schoolService.calculateProfit(); + } +} diff --git a/Ironschool/src/test/java/com/ironhack/ironschool/SchoolServiceTest.java b/Ironschool/src/test/java/com/ironhack/ironschool/SchoolServiceTest.java new file mode 100644 index 00000000..573716fd --- /dev/null +++ b/Ironschool/src/test/java/com/ironhack/ironschool/SchoolServiceTest.java @@ -0,0 +1,75 @@ +package com.ironhack.ironschool; + + +import com.ironhack.ironschool.models.Course; +import com.ironhack.ironschool.models.Student; +import com.ironhack.ironschool.models.Teacher; +import com.ironhack.ironschool.services.SchoolService; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class SchoolServiceTest { + + private SchoolService schoolService; + private Student testStudent; + private Course testCourse; + private Teacher testTeacher; + + + @BeforeEach + void setUp() { + schoolService = new SchoolService(); + + testStudent = new Student("Test Student", "123 Main St", "test@test.com"); + testCourse = new Course("Java 101", 100.0); + testTeacher = new Teacher("Test Teacher", 40.0); + + schoolService.addStudent(testStudent); + schoolService.addCourse(testCourse); + schoolService.addTeacher(testTeacher); + } + + @Test + void testEnrollStudent_Success_AddsMoneyEarned() { + schoolService.enrollStudent(testStudent.getStudentId(), testCourse.getCourseId()); + + + assertEquals(testCourse, testStudent.getCourse()); + + + + assertEquals(100.0, testCourse.getMoney_earned()); + } + + @Test + void testEnrollStudent_ThrowsExceptionForBadStudentId() { + Exception exception = assertThrows(IllegalArgumentException.class, () -> { + schoolService.enrollStudent("S-999", testCourse.getCourseId()); + } ); + + assertTrue(exception.getMessage().contains("Student ID not found")); + } + + + @Test + void testAssignTeacher_Success_AttachesTeacher() { + + schoolService.assignTeacher(testTeacher.getTeacherId(), testCourse.getCourseId()); + assertEquals(testTeacher, testCourse.getTeacher()); + } + + @Test + void testCalculateProfit_ReturnsCorrectMath() { + + + + + schoolService.enrollStudent(testStudent.getStudentId(), testCourse.getCourseId()); + + double profit = schoolService.calculateProfit(); + + assertEquals(60.0, profit); + } +} \ No newline at end of file From acf8dd5dd9c9b8db134fa20a851f09c9647c545a Mon Sep 17 00:00:00 2001 From: Anar Vali Date: Mon, 9 Mar 2026 10:28:52 -0700 Subject: [PATCH 5/7] added gitignore to keep repo clean --- Ironschool/.gitignore | 42 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 30 deletions(-) diff --git a/Ironschool/.gitignore b/Ironschool/.gitignore index 667aaef0..523844f3 100644 --- a/Ironschool/.gitignore +++ b/Ironschool/.gitignore @@ -1,33 +1,15 @@ -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 +# IntelliJ files +.idea/ *.iml -*.ipr +out/ + +# Java compiled files +target/ +*.class -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ +# Log files +*.log -### VS Code ### -.vscode/ +# OS files +.DS_Store +Thumbs.db \ No newline at end of file From a4b0f62439a1168c49648459591fed577e9189dc Mon Sep 17 00:00:00 2001 From: Anar Vali Date: Mon, 9 Mar 2026 11:03:17 -0700 Subject: [PATCH 6/7] added README with project description --- Ironschool/README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Ironschool/README.md diff --git a/Ironschool/README.md b/Ironschool/README.md new file mode 100644 index 00000000..b01b68e4 --- /dev/null +++ b/Ironschool/README.md @@ -0,0 +1,37 @@ +# IronSchool Project 🚀 + +hey guys! this is the repo for the ironschool project. me and the team built this for the java course. +its a spring boot api for managing our next big edtech startup (well right now just a MVP lol) + +## how to run / demo + +1. clone it +2. open in intellij or whatever u use +3. run `IronschoolApplication.java` +(or just do `./mvnw spring-boot:run` in terminal, kinda easier) + +we tested it with postman and it works on `localhost:8080` (mostly). + +## the tech / how it works +for the examiners/reviewers, here is what we actually built inside: + +**models we got:** +- `Student`: holds student info +- `Teacher`: holds teacher info & salary +- `Course`: has the course details, price, and tracks how much `money_earned` + +**data storage:** +tbh we didn't add a real database yet so it's all running on in-memory `HashMap`s inside the `SchoolService`. just run the app and hit the endpoints to test, but remember if you restart the app the data goes + +**what the API does:** +we have a `SchoolController` that handles these GET endpoints: +- `GET /students` -> spits out all students +- `GET /courses` -> shows all courses and their stats +- `GET /teachers` -> lists the teachers +- `GET /profit` -> this is the big one for the startup! calculates `total revenue (from enrolled students) - total salaries (from teachers)` + +the `SchoolService` has the methods to `addStudent`, `addTeacher`, `addCourse`, `enrollStudent` (which automatically updates the course revenue!), and `assignTeacher`. + +if something crashes during your review just try to restart it lol + +✌️ From a6be41eec90ad5885d822c6ffae859ec620c0ad5 Mon Sep 17 00:00:00 2001 From: Anar Vali Date: Mon, 9 Mar 2026 11:23:14 -0700 Subject: [PATCH 7/7] the ironschool project --- Ironschool/HELP.md | 28 +++++++++++++++++++ .../SchoolController.java | 0 2 files changed, 28 insertions(+) create mode 100644 Ironschool/HELP.md rename Ironschool/src/main/{java/com/ironhack/ironschool/controllers => resources}/SchoolController.java (100%) diff --git a/Ironschool/HELP.md b/Ironschool/HELP.md new file mode 100644 index 00000000..05bea92b --- /dev/null +++ b/Ironschool/HELP.md @@ -0,0 +1,28 @@ +# Getting Started + +### Reference Documentation + +For further reference, please consider the following sections: + +* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) +* [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/4.0.3/maven-plugin) +* [Create an OCI image](https://docs.spring.io/spring-boot/4.0.3/maven-plugin/build-image.html) +* [Spring Boot DevTools](https://docs.spring.io/spring-boot/4.0.3/reference/using/devtools.html) +* [Spring Web](https://docs.spring.io/spring-boot/4.0.3/reference/web/servlet.html) + +### Guides + +The following guides illustrate how to use some features concretely: + +* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) +* [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) +* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/) + +### Maven Parent overrides + +Due to Maven's design, elements are inherited from the parent POM to the project POM. +While most of the inheritance is fine, it also inherits unwanted elements like `` and `` from the +parent. +To prevent this, the project POM contains empty overrides for these elements. +If you manually switch to a different parent and actually want the inheritance, you need to remove those overrides. + diff --git a/Ironschool/src/main/java/com/ironhack/ironschool/controllers/SchoolController.java b/Ironschool/src/main/resources/SchoolController.java similarity index 100% rename from Ironschool/src/main/java/com/ironhack/ironschool/controllers/SchoolController.java rename to Ironschool/src/main/resources/SchoolController.java