From 2f22f4db0f20e75a83f13718c6d6c1306757592e Mon Sep 17 00:00:00 2001 From: pugeaale Date: Wed, 2 Oct 2024 15:12:46 +0200 Subject: [PATCH 01/48] :tada: --- .gitignore | 1 + task1/.gitignore | 33 +++ task1/.mvn/wrapper/maven-wrapper.properties | 19 ++ task1/mvnw | 259 ++++++++++++++++++ task1/mvnw.cmd | 149 ++++++++++ task1/pom.xml | 78 ++++++ .../com/ironhack/task1/Task1Application.java | 13 + .../src/main/resources/application.properties | 6 + .../ironhack/task1/Task1ApplicationTests.java | 13 + task2/.gitignore | 33 +++ task2/.mvn/wrapper/maven-wrapper.properties | 19 ++ task2/mvnw | 259 ++++++++++++++++++ task2/mvnw.cmd | 149 ++++++++++ task2/pom.xml | 78 ++++++ .../com/ironhack/task2/Task2Application.java | 13 + .../src/main/resources/application.properties | 1 + .../ironhack/task2/Task2ApplicationTests.java | 13 + 17 files changed, 1136 insertions(+) create mode 100644 .gitignore create mode 100644 task1/.gitignore create mode 100644 task1/.mvn/wrapper/maven-wrapper.properties create mode 100644 task1/mvnw create mode 100644 task1/mvnw.cmd create mode 100644 task1/pom.xml create mode 100644 task1/src/main/java/com/ironhack/task1/Task1Application.java create mode 100644 task1/src/main/resources/application.properties create mode 100644 task1/src/test/java/com/ironhack/task1/Task1ApplicationTests.java create mode 100644 task2/.gitignore create mode 100644 task2/.mvn/wrapper/maven-wrapper.properties create mode 100644 task2/mvnw create mode 100644 task2/mvnw.cmd create mode 100644 task2/pom.xml create mode 100644 task2/src/main/java/com/ironhack/task2/Task2Application.java create mode 100644 task2/src/main/resources/application.properties create mode 100644 task2/src/test/java/com/ironhack/task2/Task2ApplicationTests.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..85e7c1d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.idea/ diff --git a/task1/.gitignore b/task1/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/task1/.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/task1/.mvn/wrapper/maven-wrapper.properties b/task1/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..d58dfb7 --- /dev/null +++ b/task1/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +wrapperVersion=3.3.2 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip diff --git a/task1/mvnw b/task1/mvnw new file mode 100644 index 0000000..19529dd --- /dev/null +++ b/task1/mvnw @@ -0,0 +1,259 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.2 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/task1/mvnw.cmd b/task1/mvnw.cmd new file mode 100644 index 0000000..249bdf3 --- /dev/null +++ b/task1/mvnw.cmd @@ -0,0 +1,149 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.2 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' +$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" +if ($env:MAVEN_USER_HOME) { + $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" +} +$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/task1/pom.xml b/task1/pom.xml new file mode 100644 index 0000000..1d87f6d --- /dev/null +++ b/task1/pom.xml @@ -0,0 +1,78 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.3.4 + + + com.ironhack + task1 + 0.0.1-SNAPSHOT + task1 + task1 + + + + + + + + + + + + + + + 17 + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + com.mysql + mysql-connector-j + runtime + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/task1/src/main/java/com/ironhack/task1/Task1Application.java b/task1/src/main/java/com/ironhack/task1/Task1Application.java new file mode 100644 index 0000000..bd9ab0f --- /dev/null +++ b/task1/src/main/java/com/ironhack/task1/Task1Application.java @@ -0,0 +1,13 @@ +package com.ironhack.task1; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Task1Application { + + public static void main(String[] args) { + SpringApplication.run(Task1Application.class, args); + } + +} diff --git a/task1/src/main/resources/application.properties b/task1/src/main/resources/application.properties new file mode 100644 index 0000000..4c57c10 --- /dev/null +++ b/task1/src/main/resources/application.properties @@ -0,0 +1,6 @@ +spring.application.name=task1 +spring.datasource.url=jdbc:mysql://localhost:3306/associations_db +spring.datasource.username=root +spring.datasource.password=${MYSQLPWD} +spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.show-sql=true \ No newline at end of file diff --git a/task1/src/test/java/com/ironhack/task1/Task1ApplicationTests.java b/task1/src/test/java/com/ironhack/task1/Task1ApplicationTests.java new file mode 100644 index 0000000..f5f46be --- /dev/null +++ b/task1/src/test/java/com/ironhack/task1/Task1ApplicationTests.java @@ -0,0 +1,13 @@ +package com.ironhack.task1; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class Task1ApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/task2/.gitignore b/task2/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/task2/.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/task2/.mvn/wrapper/maven-wrapper.properties b/task2/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..d58dfb7 --- /dev/null +++ b/task2/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +wrapperVersion=3.3.2 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip diff --git a/task2/mvnw b/task2/mvnw new file mode 100644 index 0000000..19529dd --- /dev/null +++ b/task2/mvnw @@ -0,0 +1,259 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.2 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/task2/mvnw.cmd b/task2/mvnw.cmd new file mode 100644 index 0000000..249bdf3 --- /dev/null +++ b/task2/mvnw.cmd @@ -0,0 +1,149 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.2 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' +$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain" +if ($env:MAVEN_USER_HOME) { + $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain" +} +$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/task2/pom.xml b/task2/pom.xml new file mode 100644 index 0000000..47bd116 --- /dev/null +++ b/task2/pom.xml @@ -0,0 +1,78 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 3.3.4 + + + com.ironhack + task2 + 0.0.1-SNAPSHOT + task2 + task2 + + + + + + + + + + + + + + + 17 + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + com.mysql + mysql-connector-j + runtime + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/task2/src/main/java/com/ironhack/task2/Task2Application.java b/task2/src/main/java/com/ironhack/task2/Task2Application.java new file mode 100644 index 0000000..cf5fad9 --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/Task2Application.java @@ -0,0 +1,13 @@ +package com.ironhack.task2; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Task2Application { + + public static void main(String[] args) { + SpringApplication.run(Task2Application.class, args); + } + +} diff --git a/task2/src/main/resources/application.properties b/task2/src/main/resources/application.properties new file mode 100644 index 0000000..91a0ec8 --- /dev/null +++ b/task2/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=task2 diff --git a/task2/src/test/java/com/ironhack/task2/Task2ApplicationTests.java b/task2/src/test/java/com/ironhack/task2/Task2ApplicationTests.java new file mode 100644 index 0000000..0f8a223 --- /dev/null +++ b/task2/src/test/java/com/ironhack/task2/Task2ApplicationTests.java @@ -0,0 +1,13 @@ +package com.ironhack.task2; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class Task2ApplicationTests { + + @Test + void contextLoads() { + } + +} From b1c3f8e64ea071881d366e12011a141c13614e25 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Thu, 3 Oct 2024 10:35:49 +0200 Subject: [PATCH 02/48] :sparkles: implement member entity --- .../ironhack/task1/dataloader/DataLoader.java | 28 +++++++++++++++++++ .../java/com/ironhack/task1/model/Member.java | 28 +++++++++++++++++++ .../ironhack/task1/model/MemberStatus.java | 5 ++++ .../task1/repository/MemberRepository.java | 9 ++++++ .../ironhack/task1/service/MemberService.java | 22 +++++++++++++++ 5 files changed, 92 insertions(+) create mode 100644 task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java create mode 100644 task1/src/main/java/com/ironhack/task1/model/Member.java create mode 100644 task1/src/main/java/com/ironhack/task1/model/MemberStatus.java create mode 100644 task1/src/main/java/com/ironhack/task1/repository/MemberRepository.java create mode 100644 task1/src/main/java/com/ironhack/task1/service/MemberService.java diff --git a/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java b/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java new file mode 100644 index 0000000..4c08c98 --- /dev/null +++ b/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java @@ -0,0 +1,28 @@ +package com.ironhack.task1.dataloader; + +import com.ironhack.task1.model.Member; +import com.ironhack.task1.model.MemberStatus; +import com.ironhack.task1.service.MemberService; +import lombok.RequiredArgsConstructor; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +import java.time.ZonedDateTime; + +@Component +@RequiredArgsConstructor +public class DataLoader implements CommandLineRunner { + + private final MemberService memberService; + + @Override + public void run(String... args) throws Exception { + Member member = new Member("salvatore", + ZonedDateTime.now(), + MemberStatus.ACTIVE); + Member memberSaved = memberService.save(member); + System.out.println(memberSaved); + + + } +} diff --git a/task1/src/main/java/com/ironhack/task1/model/Member.java b/task1/src/main/java/com/ironhack/task1/model/Member.java new file mode 100644 index 0000000..d28c4b1 --- /dev/null +++ b/task1/src/main/java/com/ironhack/task1/model/Member.java @@ -0,0 +1,28 @@ +package com.ironhack.task1.model; + +import jakarta.persistence.*; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.ZonedDateTime; + +@Data +@NoArgsConstructor +@Entity +@Table(name = "members") +public class Member { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + private String name; + private ZonedDateTime renewalDate; + @Enumerated(EnumType.STRING) + private MemberStatus status; + + public Member(String name, ZonedDateTime renewalDate, MemberStatus status) { + this.name = name; + this.renewalDate = renewalDate; + this.status = status; + } +} diff --git a/task1/src/main/java/com/ironhack/task1/model/MemberStatus.java b/task1/src/main/java/com/ironhack/task1/model/MemberStatus.java new file mode 100644 index 0000000..8e85e90 --- /dev/null +++ b/task1/src/main/java/com/ironhack/task1/model/MemberStatus.java @@ -0,0 +1,5 @@ +package com.ironhack.task1.model; + +public enum MemberStatus { + ACTIVE, LAPSED +} diff --git a/task1/src/main/java/com/ironhack/task1/repository/MemberRepository.java b/task1/src/main/java/com/ironhack/task1/repository/MemberRepository.java new file mode 100644 index 0000000..0f87caf --- /dev/null +++ b/task1/src/main/java/com/ironhack/task1/repository/MemberRepository.java @@ -0,0 +1,9 @@ +package com.ironhack.task1.repository; + +import com.ironhack.task1.model.Member; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface MemberRepository extends JpaRepository { +} diff --git a/task1/src/main/java/com/ironhack/task1/service/MemberService.java b/task1/src/main/java/com/ironhack/task1/service/MemberService.java new file mode 100644 index 0000000..13b59b2 --- /dev/null +++ b/task1/src/main/java/com/ironhack/task1/service/MemberService.java @@ -0,0 +1,22 @@ +package com.ironhack.task1.service; + +import com.ironhack.task1.model.Member; +import com.ironhack.task1.repository.MemberRepository; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +@Slf4j +public class MemberService { + + private final MemberRepository memberRepository; + + @Transactional + public Member save(Member member) { + log.info("Saving member {}", member); + return memberRepository.save(member); + } +} From 43be0a5ca4ee43629186ea4f8edf099e24945ef3 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Thu, 3 Oct 2024 10:46:22 +0200 Subject: [PATCH 03/48] :sparkles: implement chapter entity --- .../ironhack/task1/dataloader/DataLoader.java | 8 +++++- .../com/ironhack/task1/model/Chapter.java | 27 +++++++++++++++++++ .../task1/repository/ChapterRepository.java | 9 +++++++ .../task1/service/ChapterService.java | 20 ++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 task1/src/main/java/com/ironhack/task1/model/Chapter.java create mode 100644 task1/src/main/java/com/ironhack/task1/repository/ChapterRepository.java create mode 100644 task1/src/main/java/com/ironhack/task1/service/ChapterService.java diff --git a/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java b/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java index 4c08c98..d202ac9 100644 --- a/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java +++ b/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java @@ -1,7 +1,9 @@ package com.ironhack.task1.dataloader; +import com.ironhack.task1.model.Chapter; import com.ironhack.task1.model.Member; import com.ironhack.task1.model.MemberStatus; +import com.ironhack.task1.service.ChapterService; import com.ironhack.task1.service.MemberService; import lombok.RequiredArgsConstructor; import org.springframework.boot.CommandLineRunner; @@ -15,6 +17,8 @@ public class DataLoader implements CommandLineRunner { private final MemberService memberService; + private final ChapterService chapterService; + @Override public void run(String... args) throws Exception { Member member = new Member("salvatore", @@ -23,6 +27,8 @@ public void run(String... args) throws Exception { Member memberSaved = memberService.save(member); System.out.println(memberSaved); - + Chapter chapter = new Chapter("bronx","one"); + Chapter chapterSaved = chapterService.save(chapter); + System.out.println(chapterSaved); } } diff --git a/task1/src/main/java/com/ironhack/task1/model/Chapter.java b/task1/src/main/java/com/ironhack/task1/model/Chapter.java new file mode 100644 index 0000000..5346021 --- /dev/null +++ b/task1/src/main/java/com/ironhack/task1/model/Chapter.java @@ -0,0 +1,27 @@ +package com.ironhack.task1.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@Entity +public class Chapter { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String district; + + private String name; + + public Chapter(String district, String name) { + this.district = district; + this.name = name; + } +} diff --git a/task1/src/main/java/com/ironhack/task1/repository/ChapterRepository.java b/task1/src/main/java/com/ironhack/task1/repository/ChapterRepository.java new file mode 100644 index 0000000..e35f6e4 --- /dev/null +++ b/task1/src/main/java/com/ironhack/task1/repository/ChapterRepository.java @@ -0,0 +1,9 @@ +package com.ironhack.task1.repository; + +import com.ironhack.task1.model.Chapter; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ChapterRepository extends JpaRepository { +} diff --git a/task1/src/main/java/com/ironhack/task1/service/ChapterService.java b/task1/src/main/java/com/ironhack/task1/service/ChapterService.java new file mode 100644 index 0000000..8296563 --- /dev/null +++ b/task1/src/main/java/com/ironhack/task1/service/ChapterService.java @@ -0,0 +1,20 @@ +package com.ironhack.task1.service; + +import com.ironhack.task1.model.Chapter; +import com.ironhack.task1.repository.ChapterRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +@Slf4j +public class ChapterService { + + private final ChapterRepository chapterRepository; + + public Chapter save(Chapter chapter) { + log.info("Saving chapter: {}", chapter); + return chapterRepository.save(chapter); + } +} From 4bcedbe5d1b7c3ca9e220641a1a22d14bed04102 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Thu, 3 Oct 2024 11:06:13 +0200 Subject: [PATCH 04/48] :sparkles: implement one to one relationship between chapter and entity for the president of chapter --- .../com/ironhack/task1/dataloader/DataLoader.java | 8 +++++++- .../main/java/com/ironhack/task1/model/Chapter.java | 12 +++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java b/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java index d202ac9..04f083c 100644 --- a/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java +++ b/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java @@ -27,7 +27,13 @@ public void run(String... args) throws Exception { Member memberSaved = memberService.save(member); System.out.println(memberSaved); - Chapter chapter = new Chapter("bronx","one"); + Member president = new Member("joseph", + ZonedDateTime.now(), + MemberStatus.ACTIVE); + Member presidentSaved = memberService.save(president); + System.out.println(presidentSaved); + + Chapter chapter = new Chapter("bronx","one", presidentSaved); Chapter chapterSaved = chapterService.save(chapter); System.out.println(chapterSaved); } diff --git a/task1/src/main/java/com/ironhack/task1/model/Chapter.java b/task1/src/main/java/com/ironhack/task1/model/Chapter.java index 5346021..73dc665 100644 --- a/task1/src/main/java/com/ironhack/task1/model/Chapter.java +++ b/task1/src/main/java/com/ironhack/task1/model/Chapter.java @@ -1,9 +1,6 @@ package com.ironhack.task1.model; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; +import jakarta.persistence.*; import lombok.Data; import lombok.NoArgsConstructor; @@ -20,8 +17,13 @@ public class Chapter { private String name; - public Chapter(String district, String name) { + @OneToOne + @JoinColumn(name = "presidentId") + private Member president; + + public Chapter(String district, String name, Member president) { this.district = district; this.name = name; + this.president = president; } } From fb51c8d268aa08490704dfc1569e6551060b4e31 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Thu, 3 Oct 2024 20:48:42 +0200 Subject: [PATCH 05/48] :sparkles: refactor save chapter as transactional --- .../main/java/com/ironhack/task1/service/ChapterService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/task1/src/main/java/com/ironhack/task1/service/ChapterService.java b/task1/src/main/java/com/ironhack/task1/service/ChapterService.java index 8296563..72b9a35 100644 --- a/task1/src/main/java/com/ironhack/task1/service/ChapterService.java +++ b/task1/src/main/java/com/ironhack/task1/service/ChapterService.java @@ -2,6 +2,7 @@ import com.ironhack.task1.model.Chapter; import com.ironhack.task1.repository.ChapterRepository; +import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -13,6 +14,7 @@ public class ChapterService { private final ChapterRepository chapterRepository; + @Transactional public Chapter save(Chapter chapter) { log.info("Saving chapter: {}", chapter); return chapterRepository.save(chapter); From c5300f697539a9d86e5cc41bf887e1f5db9bde86 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Thu, 3 Oct 2024 21:18:12 +0200 Subject: [PATCH 06/48] :recycle: refactor chapter to have cascade on president when persisting --- .../ironhack/task1/dataloader/DataLoader.java | 18 ++++++++---------- .../java/com/ironhack/task1/model/Chapter.java | 5 ++--- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java b/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java index 04f083c..a5a350c 100644 --- a/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java +++ b/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java @@ -21,20 +21,18 @@ public class DataLoader implements CommandLineRunner { @Override public void run(String... args) throws Exception { - Member member = new Member("salvatore", - ZonedDateTime.now(), - MemberStatus.ACTIVE); - Member memberSaved = memberService.save(member); - System.out.println(memberSaved); + Chapter chapter = new Chapter("bronx","one"); Member president = new Member("joseph", ZonedDateTime.now(), MemberStatus.ACTIVE); - Member presidentSaved = memberService.save(president); - System.out.println(presidentSaved); - Chapter chapter = new Chapter("bronx","one", presidentSaved); - Chapter chapterSaved = chapterService.save(chapter); - System.out.println(chapterSaved); + chapter.setPresident(president); + chapterService.save(chapter); + + Member member = new Member("salvatore", + ZonedDateTime.now(), + MemberStatus.ACTIVE); + memberService.save(member); } } diff --git a/task1/src/main/java/com/ironhack/task1/model/Chapter.java b/task1/src/main/java/com/ironhack/task1/model/Chapter.java index 73dc665..8731509 100644 --- a/task1/src/main/java/com/ironhack/task1/model/Chapter.java +++ b/task1/src/main/java/com/ironhack/task1/model/Chapter.java @@ -17,13 +17,12 @@ public class Chapter { private String name; - @OneToOne + @OneToOne(cascade = CascadeType.ALL) @JoinColumn(name = "presidentId") private Member president; - public Chapter(String district, String name, Member president) { + public Chapter(String district, String name) { this.district = district; this.name = name; - this.president = president; } } From 62825a24987912230e0d3439ab47590e79e949eb Mon Sep 17 00:00:00 2001 From: pugeaale Date: Thu, 3 Oct 2024 22:08:45 +0200 Subject: [PATCH 07/48] :sparkles: adding data faker to have fun datas --- task1/pom.xml | 6 +++++- .../java/com/ironhack/task1/Task1Application.java | 1 - .../com/ironhack/task1/dataloader/DataLoader.java | 15 +++++++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/task1/pom.xml b/task1/pom.xml index 1d87f6d..0d15c4a 100644 --- a/task1/pom.xml +++ b/task1/pom.xml @@ -34,7 +34,11 @@ org.springframework.boot spring-boot-starter-data-jpa - + + net.datafaker + datafaker + 2.4.0 + org.springframework.boot spring-boot-devtools diff --git a/task1/src/main/java/com/ironhack/task1/Task1Application.java b/task1/src/main/java/com/ironhack/task1/Task1Application.java index bd9ab0f..8ae99ba 100644 --- a/task1/src/main/java/com/ironhack/task1/Task1Application.java +++ b/task1/src/main/java/com/ironhack/task1/Task1Application.java @@ -5,7 +5,6 @@ @SpringBootApplication public class Task1Application { - public static void main(String[] args) { SpringApplication.run(Task1Application.class, args); } diff --git a/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java b/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java index a5a350c..af6d24f 100644 --- a/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java +++ b/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java @@ -6,9 +6,9 @@ import com.ironhack.task1.service.ChapterService; import com.ironhack.task1.service.MemberService; import lombok.RequiredArgsConstructor; +import net.datafaker.Faker; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component; - import java.time.ZonedDateTime; @Component @@ -21,18 +21,25 @@ public class DataLoader implements CommandLineRunner { @Override public void run(String... args) throws Exception { - Chapter chapter = new Chapter("bronx","one"); + Faker faker = new Faker(); + + Chapter chapter = new Chapter( + faker.address().cityName(), + faker.funnyName().name()); - Member president = new Member("joseph", + Member president = new Member( + faker.name().fullName(), ZonedDateTime.now(), MemberStatus.ACTIVE); chapter.setPresident(president); chapterService.save(chapter); - Member member = new Member("salvatore", + Member member = new Member( + faker.name().femaleFirstName(), ZonedDateTime.now(), MemberStatus.ACTIVE); memberService.save(member); + } } From 066a8af4777a4d405addaa697dc70343d6263ffd Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 10:28:42 +0200 Subject: [PATCH 08/48] :sparkles: implementing create chapter and president with datas --- .../ironhack/task1/dataloader/DataLoader.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java b/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java index af6d24f..6f055fd 100644 --- a/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java +++ b/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java @@ -22,19 +22,7 @@ public class DataLoader implements CommandLineRunner { @Override public void run(String... args) throws Exception { Faker faker = new Faker(); - - Chapter chapter = new Chapter( - faker.address().cityName(), - faker.funnyName().name()); - - Member president = new Member( - faker.name().fullName(), - ZonedDateTime.now(), - MemberStatus.ACTIVE); - - chapter.setPresident(president); - chapterService.save(chapter); - + create7chaptersWithPresidents(); Member member = new Member( faker.name().femaleFirstName(), ZonedDateTime.now(), @@ -42,4 +30,22 @@ public void run(String... args) throws Exception { memberService.save(member); } + + public void create7chaptersWithPresidents() { + Faker faker = new Faker(); + for(int i = 0; i < 7; i++) { + Chapter chapter = new Chapter( + faker.address().cityName(), + faker.funnyName().name()); + + Member president = new Member( + faker.name().fullName(), + ZonedDateTime.now(), + MemberStatus.ACTIVE); + + chapter.setPresident(president); + chapterService.save(chapter); + } + + } } From cf63634e29100524beab6f777f4baaf3f993a9e4 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 11:10:06 +0200 Subject: [PATCH 09/48] :sparkles: implementing birectional ONE TO MANY relationship between chapter and member --- .../ironhack/task1/dataloader/DataLoader.java | 20 +++++++++++++------ .../com/ironhack/task1/model/Chapter.java | 7 +++++++ .../java/com/ironhack/task1/model/Member.java | 4 ++++ .../src/main/resources/application.properties | 2 +- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java b/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java index 6f055fd..acb0645 100644 --- a/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java +++ b/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java @@ -21,19 +21,20 @@ public class DataLoader implements CommandLineRunner { @Override public void run(String... args) throws Exception { - Faker faker = new Faker(); - create7chaptersWithPresidents(); + //create7chaptersWithPresidents(); Member member = new Member( - faker.name().femaleFirstName(), + "dd", ZonedDateTime.now(), - MemberStatus.ACTIVE); + MemberStatus.ACTIVE + ); + Chapter chapter = new Chapter("d","dd"); + member.setChapter(chapter); memberService.save(member); - } public void create7chaptersWithPresidents() { Faker faker = new Faker(); - for(int i = 0; i < 7; i++) { + for(int i = 0; i < 1; i++) { Chapter chapter = new Chapter( faker.address().cityName(), faker.funnyName().name()); @@ -44,6 +45,13 @@ public void create7chaptersWithPresidents() { MemberStatus.ACTIVE); chapter.setPresident(president); + + Member member = new Member( + faker.name().femaleFirstName(), + ZonedDateTime.now(), + MemberStatus.ACTIVE); + chapter.getMembers().add(member); + chapterService.save(chapter); } diff --git a/task1/src/main/java/com/ironhack/task1/model/Chapter.java b/task1/src/main/java/com/ironhack/task1/model/Chapter.java index 8731509..2c1deae 100644 --- a/task1/src/main/java/com/ironhack/task1/model/Chapter.java +++ b/task1/src/main/java/com/ironhack/task1/model/Chapter.java @@ -4,6 +4,9 @@ import lombok.Data; import lombok.NoArgsConstructor; +import java.util.ArrayList; +import java.util.List; + @Data @NoArgsConstructor @Entity @@ -21,6 +24,10 @@ public class Chapter { @JoinColumn(name = "presidentId") private Member president; + @OneToMany(mappedBy = "chapter", fetch = FetchType.EAGER, cascade = CascadeType.ALL) + //@JoinColumn(name = "chapterId", referencedColumnName = "id") + private List members = new ArrayList(); + public Chapter(String district, String name) { this.district = district; this.name = name; diff --git a/task1/src/main/java/com/ironhack/task1/model/Member.java b/task1/src/main/java/com/ironhack/task1/model/Member.java index d28c4b1..486cfbb 100644 --- a/task1/src/main/java/com/ironhack/task1/model/Member.java +++ b/task1/src/main/java/com/ironhack/task1/model/Member.java @@ -20,6 +20,10 @@ public class Member { @Enumerated(EnumType.STRING) private MemberStatus status; + @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) + @JoinColumn(name = "chapterId" , referencedColumnName = "id") + private Chapter chapter; + public Member(String name, ZonedDateTime renewalDate, MemberStatus status) { this.name = name; this.renewalDate = renewalDate; diff --git a/task1/src/main/resources/application.properties b/task1/src/main/resources/application.properties index 4c57c10..cced6d9 100644 --- a/task1/src/main/resources/application.properties +++ b/task1/src/main/resources/application.properties @@ -2,5 +2,5 @@ spring.application.name=task1 spring.datasource.url=jdbc:mysql://localhost:3306/associations_db spring.datasource.username=root spring.datasource.password=${MYSQLPWD} -spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true \ No newline at end of file From a88c3c021fdea0c8ac89b07b4f95bebd9b29fa7a Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 11:13:24 +0200 Subject: [PATCH 10/48] :tada: task2 : event management application --- task2/pom.xml | 6 +++++- task2/src/main/resources/application.properties | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/task2/pom.xml b/task2/pom.xml index 47bd116..61452ea 100644 --- a/task2/pom.xml +++ b/task2/pom.xml @@ -34,7 +34,11 @@ org.springframework.boot spring-boot-starter-data-jpa - + + net.datafaker + datafaker + 2.4.0 + org.springframework.boot spring-boot-devtools diff --git a/task2/src/main/resources/application.properties b/task2/src/main/resources/application.properties index 91a0ec8..7e8f276 100644 --- a/task2/src/main/resources/application.properties +++ b/task2/src/main/resources/application.properties @@ -1 +1,6 @@ spring.application.name=task2 +spring.datasource.url=jdbc:mysql://localhost:3306/events_db +spring.datasource.username=root +spring.datasource.password=${MYSQLPWD} +spring.jpa.hibernate.ddl-auto=update +spring.jpa.show-sql=true \ No newline at end of file From e200db8714056abb69a2f509770f25eb4d6694d8 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 11:23:10 +0200 Subject: [PATCH 11/48] :sparkles: implementing speaker entity --- .../com/ironhack/task2/model/Speaker.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 task2/src/main/java/com/ironhack/task2/model/Speaker.java diff --git a/task2/src/main/java/com/ironhack/task2/model/Speaker.java b/task2/src/main/java/com/ironhack/task2/model/Speaker.java new file mode 100644 index 0000000..cc49226 --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/model/Speaker.java @@ -0,0 +1,25 @@ +package com.ironhack.task2.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@Entity +public class Speaker { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + private String name; + private Integer presentationDuration; + + public Speaker(String name, Integer presentationDuration) { + this.name = name; + this.presentationDuration = presentationDuration; + } +} From 1d93d8eda4aa9aa611a8324937d84a5ee4c78949 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 11:24:16 +0200 Subject: [PATCH 12/48] :sparkles: implementing speaker repository --- .../com/ironhack/task2/repository/SpeakerRepository.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 task2/src/main/java/com/ironhack/task2/repository/SpeakerRepository.java diff --git a/task2/src/main/java/com/ironhack/task2/repository/SpeakerRepository.java b/task2/src/main/java/com/ironhack/task2/repository/SpeakerRepository.java new file mode 100644 index 0000000..38a6517 --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/repository/SpeakerRepository.java @@ -0,0 +1,9 @@ +package com.ironhack.task2.repository; + +import com.ironhack.task2.model.Speaker; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface SpeakerRepository extends JpaRepository { +} From f0132989ce57f21e76878149db0bd9b7a1582aa3 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 11:25:50 +0200 Subject: [PATCH 13/48] :sparkles: implementing speaker service with save implementation --- .../ironhack/task2/service/SpeakerService.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 task2/src/main/java/com/ironhack/task2/service/SpeakerService.java diff --git a/task2/src/main/java/com/ironhack/task2/service/SpeakerService.java b/task2/src/main/java/com/ironhack/task2/service/SpeakerService.java new file mode 100644 index 0000000..037b73e --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/service/SpeakerService.java @@ -0,0 +1,16 @@ +package com.ironhack.task2.service; + +import com.ironhack.task2.model.Speaker; +import com.ironhack.task2.repository.SpeakerRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class SpeakerService { + private final SpeakerRepository speakerRepository; + + public Speaker save(Speaker speaker) { + return speakerRepository.save(speaker); + } +} From 416ec592d881a17925462359056166d756e3ac98 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 11:31:06 +0200 Subject: [PATCH 14/48] :sparkles: implementing data loader with creating a speaker --- .../ironhack/task2/dataloader/DataLoader.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java diff --git a/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java b/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java new file mode 100644 index 0000000..36ec67c --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java @@ -0,0 +1,21 @@ +package com.ironhack.task2.dataloader; + +import com.ironhack.task2.model.Speaker; +import com.ironhack.task2.service.SpeakerService; +import lombok.RequiredArgsConstructor; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class DataLoader implements CommandLineRunner { + private final SpeakerService speakerService; + + @Override + public void run(String... args) throws Exception { + Speaker speaker = new Speaker(); + speaker.setName("ddd"); + speaker.setPresentationDuration(33); + speakerService.save(speaker); + } +} From efaaf32abda56de172d2272cff453d2cf39ce772 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 11:45:15 +0200 Subject: [PATCH 15/48] :sparkles: implementing guest entity and guest status --- .../java/com/ironhack/task2/model/Guest.java | 25 +++++++++++++++++++ .../com/ironhack/task2/model/GuestStatus.java | 5 ++++ 2 files changed, 30 insertions(+) create mode 100644 task2/src/main/java/com/ironhack/task2/model/Guest.java create mode 100644 task2/src/main/java/com/ironhack/task2/model/GuestStatus.java diff --git a/task2/src/main/java/com/ironhack/task2/model/Guest.java b/task2/src/main/java/com/ironhack/task2/model/Guest.java new file mode 100644 index 0000000..f8dd795 --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/model/Guest.java @@ -0,0 +1,25 @@ +package com.ironhack.task2.model; + +import jakarta.persistence.*; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@Entity +public class Guest { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String name; + + @Enumerated(EnumType.STRING) + private GuestStatus status; + + public Guest(String name, GuestStatus status) { + this.name = name; + this.status = status; + } +} diff --git a/task2/src/main/java/com/ironhack/task2/model/GuestStatus.java b/task2/src/main/java/com/ironhack/task2/model/GuestStatus.java new file mode 100644 index 0000000..05159e0 --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/model/GuestStatus.java @@ -0,0 +1,5 @@ +package com.ironhack.task2.model; + +public enum GuestStatus { + ATTENDING, NOT_ATTENDING, NO_RESPONSE +} From b9ad806f5d0ae358b5882ff68142391548efa488 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 11:46:15 +0200 Subject: [PATCH 16/48] :sparkles: implementing guest repository --- .../com/ironhack/task2/repository/GuestRepository.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 task2/src/main/java/com/ironhack/task2/repository/GuestRepository.java diff --git a/task2/src/main/java/com/ironhack/task2/repository/GuestRepository.java b/task2/src/main/java/com/ironhack/task2/repository/GuestRepository.java new file mode 100644 index 0000000..aebfe3f --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/repository/GuestRepository.java @@ -0,0 +1,9 @@ +package com.ironhack.task2.repository; + +import com.ironhack.task2.model.Guest; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface GuestRepository extends JpaRepository { +} From 1c2431eb2b788a3d644f3ec59d025477abe85555 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 11:47:34 +0200 Subject: [PATCH 17/48] :sparkles: implementing guest service with save implementation --- .../com/ironhack/task2/service/GuestService.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 task2/src/main/java/com/ironhack/task2/service/GuestService.java diff --git a/task2/src/main/java/com/ironhack/task2/service/GuestService.java b/task2/src/main/java/com/ironhack/task2/service/GuestService.java new file mode 100644 index 0000000..c5495c5 --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/service/GuestService.java @@ -0,0 +1,16 @@ +package com.ironhack.task2.service; + +import com.ironhack.task2.model.Guest; +import com.ironhack.task2.repository.GuestRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class GuestService { + private final GuestRepository guestRepository; + + public Guest save(Guest guest) { + return guestRepository.save(guest); + } +} From 0fb2341f48e8e4914543c2b63736822cdda695b0 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 11:51:00 +0200 Subject: [PATCH 18/48] :sparkles: loading new data with creating new guest --- .../com/ironhack/task2/dataloader/DataLoader.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java b/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java index 36ec67c..396c07b 100644 --- a/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java +++ b/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java @@ -1,6 +1,9 @@ package com.ironhack.task2.dataloader; +import com.ironhack.task2.model.Guest; +import com.ironhack.task2.model.GuestStatus; import com.ironhack.task2.model.Speaker; +import com.ironhack.task2.service.GuestService; import com.ironhack.task2.service.SpeakerService; import lombok.RequiredArgsConstructor; import org.springframework.boot.CommandLineRunner; @@ -10,12 +13,18 @@ @RequiredArgsConstructor public class DataLoader implements CommandLineRunner { private final SpeakerService speakerService; + private final GuestService guestService; @Override public void run(String... args) throws Exception { Speaker speaker = new Speaker(); - speaker.setName("ddd"); + speaker.setName("warren"); speaker.setPresentationDuration(33); speakerService.save(speaker); + + Guest guest = new Guest(); + guest.setName("azer"); + guest.setStatus(GuestStatus.ATTENDING); + guestService.save(guest); } } From fef47977f9ffbc3a28c5861ca6d43117eb1ba74b Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 13:31:51 +0200 Subject: [PATCH 19/48] :sparkles: implementing event model --- .../java/com/ironhack/task2/model/Event.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 task2/src/main/java/com/ironhack/task2/model/Event.java diff --git a/task2/src/main/java/com/ironhack/task2/model/Event.java b/task2/src/main/java/com/ironhack/task2/model/Event.java new file mode 100644 index 0000000..23a5090 --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/model/Event.java @@ -0,0 +1,38 @@ +package com.ironhack.task2.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +/* +date: the date the event will take place +duration: the duration of the event +location: the location of the event +title: the title of the event + */ +@Data +@NoArgsConstructor +@Entity +public class Event { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String title; + private String location; + private LocalDate date; + private Integer duration; + + public Event(String title, String location, LocalDate date, Integer duration) { + this.title = title; + this.location = location; + this.date = date; + this.duration = duration; + } +} From 3cab70edef3fa7ea468b9843875d1f7d25e2e36b Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 13:33:00 +0200 Subject: [PATCH 20/48] :sparkles: implementing repository for event --- .../com/ironhack/task2/repository/EventRepository.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 task2/src/main/java/com/ironhack/task2/repository/EventRepository.java diff --git a/task2/src/main/java/com/ironhack/task2/repository/EventRepository.java b/task2/src/main/java/com/ironhack/task2/repository/EventRepository.java new file mode 100644 index 0000000..8a7519c --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/repository/EventRepository.java @@ -0,0 +1,9 @@ +package com.ironhack.task2.repository; + +import com.ironhack.task2.model.Event; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface EventRepository extends JpaRepository { +} From dd8c1812390ee9a56b54e4783666f4647ac3587d Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 13:34:56 +0200 Subject: [PATCH 21/48] :sparkles: implementing service for event with save implementation --- .../ironhack/task2/service/EventService.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 task2/src/main/java/com/ironhack/task2/service/EventService.java diff --git a/task2/src/main/java/com/ironhack/task2/service/EventService.java b/task2/src/main/java/com/ironhack/task2/service/EventService.java new file mode 100644 index 0000000..d883f75 --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/service/EventService.java @@ -0,0 +1,18 @@ +package com.ironhack.task2.service; + +import com.ironhack.task2.model.Event; +import com.ironhack.task2.repository.EventRepository; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class EventService { + private final EventRepository eventRepository; + + @Transactional + public Event save(Event event) { + return eventRepository.save(event); + } +} From ae40c1b58c1aaa1187ce580c93fce9dd6ae6b975 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 13:39:18 +0200 Subject: [PATCH 22/48] :sparkles: loading data with creating new event --- .../ironhack/task2/dataloader/DataLoader.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java b/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java index 396c07b..4ea1fab 100644 --- a/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java +++ b/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java @@ -1,30 +1,42 @@ package com.ironhack.task2.dataloader; +import com.ironhack.task2.model.Event; import com.ironhack.task2.model.Guest; import com.ironhack.task2.model.GuestStatus; import com.ironhack.task2.model.Speaker; +import com.ironhack.task2.service.EventService; import com.ironhack.task2.service.GuestService; import com.ironhack.task2.service.SpeakerService; import lombok.RequiredArgsConstructor; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component; +import java.time.LocalDate; + @Component @RequiredArgsConstructor public class DataLoader implements CommandLineRunner { private final SpeakerService speakerService; private final GuestService guestService; + private final EventService eventService; @Override public void run(String... args) throws Exception { Speaker speaker = new Speaker(); - speaker.setName("warren"); + speaker.setName("john"); speaker.setPresentationDuration(33); speakerService.save(speaker); Guest guest = new Guest(); - guest.setName("azer"); + guest.setName("julie"); guest.setStatus(GuestStatus.ATTENDING); guestService.save(guest); + + Event event = new Event(); + event.setDuration(32); + event.setLocation("paris"); + event.setTitle("mondial tattoo"); + event.setDate(LocalDate.now()); + eventService.save(event); } } From 76432544af9a0197844a2ef4f9729f6aba13b996 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 14:06:01 +0200 Subject: [PATCH 23/48] :sparkles: implementing exposition model extending event --- .../com/ironhack/task2/model/Exposition.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 task2/src/main/java/com/ironhack/task2/model/Exposition.java diff --git a/task2/src/main/java/com/ironhack/task2/model/Exposition.java b/task2/src/main/java/com/ironhack/task2/model/Exposition.java new file mode 100644 index 0000000..6ec5e80 --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/model/Exposition.java @@ -0,0 +1,18 @@ +package com.ironhack.task2.model; + +import jakarta.persistence.Entity; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +@Data +@NoArgsConstructor +@Entity +public class Exposition extends Event { + + public Exposition(String title, String location, LocalDate date, Integer duration) { + super(title, location, date, duration); + } +} From f9d737093c4e0520379f7c45fdf511f3b56a0e67 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 14:07:31 +0200 Subject: [PATCH 24/48] :sparkles: implementing exposition repository --- .../ironhack/task2/repository/ExpositionRepository.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 task2/src/main/java/com/ironhack/task2/repository/ExpositionRepository.java diff --git a/task2/src/main/java/com/ironhack/task2/repository/ExpositionRepository.java b/task2/src/main/java/com/ironhack/task2/repository/ExpositionRepository.java new file mode 100644 index 0000000..eae09f3 --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/repository/ExpositionRepository.java @@ -0,0 +1,9 @@ +package com.ironhack.task2.repository; + +import com.ironhack.task2.model.Exposition; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ExpositionRepository extends JpaRepository { +} From 702ef7c234fddb2f85b12195ac789028f1dd2f98 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 14:08:57 +0200 Subject: [PATCH 25/48] :sparkles: implementing exposition service --- .../task2/service/ExpositionService.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 task2/src/main/java/com/ironhack/task2/service/ExpositionService.java diff --git a/task2/src/main/java/com/ironhack/task2/service/ExpositionService.java b/task2/src/main/java/com/ironhack/task2/service/ExpositionService.java new file mode 100644 index 0000000..377b68e --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/service/ExpositionService.java @@ -0,0 +1,18 @@ +package com.ironhack.task2.service; + +import com.ironhack.task2.model.Exposition; +import com.ironhack.task2.repository.ExpositionRepository; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class ExpositionService { + private final ExpositionRepository expositionRepository; + + @Transactional + public Exposition save(Exposition exposition) { + return expositionRepository.save(exposition); + } +} From 7855169a3aa6a40def9be5e288a0424777f49d37 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 14:14:21 +0200 Subject: [PATCH 26/48] :sparkles: implementing conference model --- .../com/ironhack/task2/model/Conference.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 task2/src/main/java/com/ironhack/task2/model/Conference.java diff --git a/task2/src/main/java/com/ironhack/task2/model/Conference.java b/task2/src/main/java/com/ironhack/task2/model/Conference.java new file mode 100644 index 0000000..9cefc0f --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/model/Conference.java @@ -0,0 +1,17 @@ +package com.ironhack.task2.model; + +import jakarta.persistence.Entity; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +@Data +@NoArgsConstructor +@Entity +public class Conference extends Event { + + public Conference(String title, String location, LocalDate date, Integer duration) { + super(title, location, date, duration); + } +} From a1e1e3eb62ca21d65dd679a918d6249c494a95e7 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 14:15:33 +0200 Subject: [PATCH 27/48] :sparkles: implementing conference repository --- .../ironhack/task2/repository/ConferenceRepository.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 task2/src/main/java/com/ironhack/task2/repository/ConferenceRepository.java diff --git a/task2/src/main/java/com/ironhack/task2/repository/ConferenceRepository.java b/task2/src/main/java/com/ironhack/task2/repository/ConferenceRepository.java new file mode 100644 index 0000000..100fe99 --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/repository/ConferenceRepository.java @@ -0,0 +1,9 @@ +package com.ironhack.task2.repository; + +import com.ironhack.task2.model.Conference; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ConferenceRepository extends JpaRepository { +} From dc371423816b7a2c32d0d1369d3e46b553c8c1f9 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 14:17:37 +0200 Subject: [PATCH 28/48] :sparkles: implementing conference service --- .../task2/service/ConferenceService.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 task2/src/main/java/com/ironhack/task2/service/ConferenceService.java diff --git a/task2/src/main/java/com/ironhack/task2/service/ConferenceService.java b/task2/src/main/java/com/ironhack/task2/service/ConferenceService.java new file mode 100644 index 0000000..fa0267b --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/service/ConferenceService.java @@ -0,0 +1,18 @@ +package com.ironhack.task2.service; + +import com.ironhack.task2.model.Conference; +import com.ironhack.task2.repository.ConferenceRepository; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class ConferenceService { + private final ConferenceRepository conferenceRepository; + + @Transactional + public Conference save(Conference conference) { + return conferenceRepository.save(conference); + } +} From 55f33defa74fe4d4468f572b8e652a4328714059 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 14:20:32 +0200 Subject: [PATCH 29/48] :sparkles: loading datas with creating conference and exposition --- .../ironhack/task2/dataloader/DataLoader.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java b/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java index 4ea1fab..3c199c1 100644 --- a/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java +++ b/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java @@ -1,12 +1,7 @@ package com.ironhack.task2.dataloader; -import com.ironhack.task2.model.Event; -import com.ironhack.task2.model.Guest; -import com.ironhack.task2.model.GuestStatus; -import com.ironhack.task2.model.Speaker; -import com.ironhack.task2.service.EventService; -import com.ironhack.task2.service.GuestService; -import com.ironhack.task2.service.SpeakerService; +import com.ironhack.task2.model.*; +import com.ironhack.task2.service.*; import lombok.RequiredArgsConstructor; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component; @@ -19,6 +14,8 @@ public class DataLoader implements CommandLineRunner { private final SpeakerService speakerService; private final GuestService guestService; private final EventService eventService; + private final ExpositionService expositionService; + private final ConferenceService conferenceService; @Override public void run(String... args) throws Exception { @@ -38,5 +35,19 @@ public void run(String... args) throws Exception { event.setTitle("mondial tattoo"); event.setDate(LocalDate.now()); eventService.save(event); + + Exposition exposition = new Exposition(); + exposition.setDuration(4); + exposition.setLocation("PANAME"); + exposition.setTitle("mondial_tattoo"); + exposition.setDate(LocalDate.now()); + expositionService.save(exposition); + + Conference conference = new Conference(); + conference.setDuration(3); + conference.setLocation("PANAME"); + conference.setTitle("devoxx 2025"); + conference.setDate(LocalDate.now()); + conferenceService.save(conference); } } From 622aebfbf7db2fadb2d3359f348e1baf8a2035db Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 18:04:30 +0200 Subject: [PATCH 30/48] :sparkles: implementing one to many relationship between conference and speaker --- .../main/java/com/ironhack/task2/model/Conference.java | 6 ++++++ .../src/main/java/com/ironhack/task2/model/Speaker.java | 9 +++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/task2/src/main/java/com/ironhack/task2/model/Conference.java b/task2/src/main/java/com/ironhack/task2/model/Conference.java index 9cefc0f..1569439 100644 --- a/task2/src/main/java/com/ironhack/task2/model/Conference.java +++ b/task2/src/main/java/com/ironhack/task2/model/Conference.java @@ -1,16 +1,22 @@ package com.ironhack.task2.model; import jakarta.persistence.Entity; +import jakarta.persistence.OneToMany; import lombok.Data; import lombok.NoArgsConstructor; import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; @Data @NoArgsConstructor @Entity public class Conference extends Event { + @OneToMany(mappedBy = "conference") + private List speakers = new ArrayList<>(); + public Conference(String title, String location, LocalDate date, Integer duration) { super(title, location, date, duration); } diff --git a/task2/src/main/java/com/ironhack/task2/model/Speaker.java b/task2/src/main/java/com/ironhack/task2/model/Speaker.java index cc49226..01044ea 100644 --- a/task2/src/main/java/com/ironhack/task2/model/Speaker.java +++ b/task2/src/main/java/com/ironhack/task2/model/Speaker.java @@ -1,9 +1,6 @@ package com.ironhack.task2.model; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; +import jakarta.persistence.*; import lombok.Data; import lombok.NoArgsConstructor; @@ -18,6 +15,10 @@ public class Speaker { private String name; private Integer presentationDuration; + @ManyToOne + @JoinColumn(name = "conferenceId" , referencedColumnName = "id") + private Conference conference; + public Speaker(String name, Integer presentationDuration) { this.name = name; this.presentationDuration = presentationDuration; From 0d33e67fbe79bed7eb5ed731532f360d8b9b4bab Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 18:15:11 +0200 Subject: [PATCH 31/48] :sparkles: implementing one to many relationship between event and guest --- .../src/main/java/com/ironhack/task2/model/Event.java | 10 ++++++---- .../src/main/java/com/ironhack/task2/model/Guest.java | 4 ++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/task2/src/main/java/com/ironhack/task2/model/Event.java b/task2/src/main/java/com/ironhack/task2/model/Event.java index 23a5090..18b68f4 100644 --- a/task2/src/main/java/com/ironhack/task2/model/Event.java +++ b/task2/src/main/java/com/ironhack/task2/model/Event.java @@ -1,13 +1,12 @@ package com.ironhack.task2.model; -import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; +import jakarta.persistence.*; import lombok.Data; import lombok.NoArgsConstructor; import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; /* date: the date the event will take place @@ -29,6 +28,9 @@ public class Event { private LocalDate date; private Integer duration; + @OneToMany(mappedBy = "event") + private List guests = new ArrayList<>(); + public Event(String title, String location, LocalDate date, Integer duration) { this.title = title; this.location = location; diff --git a/task2/src/main/java/com/ironhack/task2/model/Guest.java b/task2/src/main/java/com/ironhack/task2/model/Guest.java index f8dd795..443f405 100644 --- a/task2/src/main/java/com/ironhack/task2/model/Guest.java +++ b/task2/src/main/java/com/ironhack/task2/model/Guest.java @@ -18,6 +18,10 @@ public class Guest { @Enumerated(EnumType.STRING) private GuestStatus status; + @ManyToOne + @JoinColumn(name = "eventId", referencedColumnName = "id") + private Event event; + public Guest(String name, GuestStatus status) { this.name = name; this.status = status; From a26a1edc063f7228d043180065f0e620ccaf16e5 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 18:20:52 +0200 Subject: [PATCH 32/48] :sparkles: loading datas to test one to many relationships with data faker --- .../ironhack/task2/dataloader/DataLoader.java | 58 +++++++++++++------ 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java b/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java index 3c199c1..5ef6edf 100644 --- a/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java +++ b/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java @@ -3,6 +3,7 @@ import com.ironhack.task2.model.*; import com.ironhack.task2.service.*; import lombok.RequiredArgsConstructor; +import net.datafaker.Faker; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component; @@ -16,19 +17,10 @@ public class DataLoader implements CommandLineRunner { private final EventService eventService; private final ExpositionService expositionService; private final ConferenceService conferenceService; + private Faker faker = new Faker(); @Override public void run(String... args) throws Exception { - Speaker speaker = new Speaker(); - speaker.setName("john"); - speaker.setPresentationDuration(33); - speakerService.save(speaker); - - Guest guest = new Guest(); - guest.setName("julie"); - guest.setStatus(GuestStatus.ATTENDING); - guestService.save(guest); - Event event = new Event(); event.setDuration(32); event.setLocation("paris"); @@ -36,18 +28,48 @@ public void run(String... args) throws Exception { event.setDate(LocalDate.now()); eventService.save(event); + Exposition expositionSaved = createNewExposition(); + + Guest guestSaved = createNewGuest(expositionSaved); + + Conference confSaved = createNewConference(); + + Speaker speakerSaved = createNewSpeaker(confSaved); + } + + private Guest createNewGuest( Event event) { + Guest guest = new Guest(); + guest.setName(faker.name().femaleFirstName()); + guest.setStatus(GuestStatus.ATTENDING); + guest.setEvent(event); + return guestService.save(guest); + } + + private Exposition createNewExposition() { Exposition exposition = new Exposition(); - exposition.setDuration(4); - exposition.setLocation("PANAME"); - exposition.setTitle("mondial_tattoo"); + exposition.setDuration(faker.number().positive()); + exposition.setLocation(faker.address().city()); + exposition.setTitle(faker.artist().name()); exposition.setDate(LocalDate.now()); - expositionService.save(exposition); + return expositionService.save(exposition); + } + private Speaker createNewSpeaker(Conference confSaved) { + Speaker speaker = new Speaker(); + speaker.setName(faker.name().fullName()); + speaker.setPresentationDuration(faker.number().positive()); + speaker.setConference(confSaved); + return speakerService.save(speaker); + } + + private Conference createNewConference() { Conference conference = new Conference(); - conference.setDuration(3); - conference.setLocation("PANAME"); - conference.setTitle("devoxx 2025"); + conference.setDuration(faker.number().positive()); + conference.setLocation(faker.address().city()); + conference.setTitle(faker.community().character()); conference.setDate(LocalDate.now()); - conferenceService.save(conference); + return conferenceService.save(conference); } + + } From c736e2daa8eefa707c594aa4060e97edc3d9d8e3 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 18:39:42 +0200 Subject: [PATCH 33/48] :sparkles: implementing findAll and deleteById for guest model --- .../com/ironhack/task2/service/GuestService.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/task2/src/main/java/com/ironhack/task2/service/GuestService.java b/task2/src/main/java/com/ironhack/task2/service/GuestService.java index c5495c5..2a6484a 100644 --- a/task2/src/main/java/com/ironhack/task2/service/GuestService.java +++ b/task2/src/main/java/com/ironhack/task2/service/GuestService.java @@ -2,15 +2,28 @@ import com.ironhack.task2.model.Guest; import com.ironhack.task2.repository.GuestRepository; +import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.List; + @Service @RequiredArgsConstructor public class GuestService { private final GuestRepository guestRepository; + @Transactional public Guest save(Guest guest) { return guestRepository.save(guest); } + + public List findAll() { + return guestRepository.findAll(); + } + + @Transactional + public void deleteById(Long id) { + guestRepository.deleteById(id); + } } From f03e92b784ffd9476b4a9fc24f099ca97f67b36b Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 18:40:02 +0200 Subject: [PATCH 34/48] :sparkles: implementing findAll and deleteById for speaker model --- .../com/ironhack/task2/service/SpeakerService.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/task2/src/main/java/com/ironhack/task2/service/SpeakerService.java b/task2/src/main/java/com/ironhack/task2/service/SpeakerService.java index 037b73e..9e676c0 100644 --- a/task2/src/main/java/com/ironhack/task2/service/SpeakerService.java +++ b/task2/src/main/java/com/ironhack/task2/service/SpeakerService.java @@ -2,15 +2,28 @@ import com.ironhack.task2.model.Speaker; import com.ironhack.task2.repository.SpeakerRepository; +import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.List; + @Service @RequiredArgsConstructor public class SpeakerService { private final SpeakerRepository speakerRepository; + @Transactional public Speaker save(Speaker speaker) { return speakerRepository.save(speaker); } + + public List findAll() { + return speakerRepository.findAll(); + } + + @Transactional + public void deleteById(Long id) { + speakerRepository.deleteById(id); + } } From 038d5b24d7ef95968cfea2cff4393227b7f8d34f Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 20:44:31 +0200 Subject: [PATCH 35/48] :zap: implementing lazy fetching mode for event in guest --- task2/src/main/java/com/ironhack/task2/model/Guest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/task2/src/main/java/com/ironhack/task2/model/Guest.java b/task2/src/main/java/com/ironhack/task2/model/Guest.java index 443f405..16c341c 100644 --- a/task2/src/main/java/com/ironhack/task2/model/Guest.java +++ b/task2/src/main/java/com/ironhack/task2/model/Guest.java @@ -18,7 +18,8 @@ public class Guest { @Enumerated(EnumType.STRING) private GuestStatus status; - @ManyToOne + //we want a lazy loading by default eager + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "eventId", referencedColumnName = "id") private Event event; From 3fd1556a85be6d0e0b2c3abc92f5afea0da23ad7 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 20:44:55 +0200 Subject: [PATCH 36/48] :zap: implementing lazy fetching mode for conference in speaker --- task2/src/main/java/com/ironhack/task2/model/Speaker.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/task2/src/main/java/com/ironhack/task2/model/Speaker.java b/task2/src/main/java/com/ironhack/task2/model/Speaker.java index 01044ea..f7a593f 100644 --- a/task2/src/main/java/com/ironhack/task2/model/Speaker.java +++ b/task2/src/main/java/com/ironhack/task2/model/Speaker.java @@ -15,7 +15,8 @@ public class Speaker { private String name; private Integer presentationDuration; - @ManyToOne + //we want a lazy loading by default eager + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "conferenceId" , referencedColumnName = "id") private Conference conference; From 9281249a69073450205f0ae25d124648c4dfbeb0 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Fri, 4 Oct 2024 20:58:56 +0200 Subject: [PATCH 37/48] :sparkles: implementing count feature to count all expositions, conferences and events --- .../java/com/ironhack/task2/service/ConferenceService.java | 4 ++++ .../main/java/com/ironhack/task2/service/EventService.java | 4 ++++ .../java/com/ironhack/task2/service/ExpositionService.java | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/task2/src/main/java/com/ironhack/task2/service/ConferenceService.java b/task2/src/main/java/com/ironhack/task2/service/ConferenceService.java index fa0267b..244028f 100644 --- a/task2/src/main/java/com/ironhack/task2/service/ConferenceService.java +++ b/task2/src/main/java/com/ironhack/task2/service/ConferenceService.java @@ -15,4 +15,8 @@ public class ConferenceService { public Conference save(Conference conference) { return conferenceRepository.save(conference); } + + public long count() { + return conferenceRepository.count(); + } } diff --git a/task2/src/main/java/com/ironhack/task2/service/EventService.java b/task2/src/main/java/com/ironhack/task2/service/EventService.java index d883f75..d802e16 100644 --- a/task2/src/main/java/com/ironhack/task2/service/EventService.java +++ b/task2/src/main/java/com/ironhack/task2/service/EventService.java @@ -15,4 +15,8 @@ public class EventService { public Event save(Event event) { return eventRepository.save(event); } + + public long count() { + return eventRepository.count(); + } } diff --git a/task2/src/main/java/com/ironhack/task2/service/ExpositionService.java b/task2/src/main/java/com/ironhack/task2/service/ExpositionService.java index 377b68e..921005a 100644 --- a/task2/src/main/java/com/ironhack/task2/service/ExpositionService.java +++ b/task2/src/main/java/com/ironhack/task2/service/ExpositionService.java @@ -15,4 +15,8 @@ public class ExpositionService { public Exposition save(Exposition exposition) { return expositionRepository.save(exposition); } + + public long count() { + return expositionRepository.count(); + } } From 5be613d242abff599d0f3b8c433ba7d6514fbcf2 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Sat, 5 Oct 2024 09:50:14 +0200 Subject: [PATCH 38/48] :sparkles: implementing find by id for conference --- .../java/com/ironhack/task2/service/ConferenceService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/task2/src/main/java/com/ironhack/task2/service/ConferenceService.java b/task2/src/main/java/com/ironhack/task2/service/ConferenceService.java index 244028f..6edc07e 100644 --- a/task2/src/main/java/com/ironhack/task2/service/ConferenceService.java +++ b/task2/src/main/java/com/ironhack/task2/service/ConferenceService.java @@ -6,6 +6,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.Optional; + @Service @RequiredArgsConstructor public class ConferenceService { @@ -19,4 +21,8 @@ public Conference save(Conference conference) { public long count() { return conferenceRepository.count(); } + + public Optional findById(long id) { + return conferenceRepository.findById(id); + } } From e20ae8afa3afcd705c58e7b41a30d66339324034 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Sat, 5 Oct 2024 09:50:37 +0200 Subject: [PATCH 39/48] :sparkles: implementing find by id for exposition --- .../java/com/ironhack/task2/service/ExpositionService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/task2/src/main/java/com/ironhack/task2/service/ExpositionService.java b/task2/src/main/java/com/ironhack/task2/service/ExpositionService.java index 921005a..699df5d 100644 --- a/task2/src/main/java/com/ironhack/task2/service/ExpositionService.java +++ b/task2/src/main/java/com/ironhack/task2/service/ExpositionService.java @@ -6,6 +6,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.Optional; + @Service @RequiredArgsConstructor public class ExpositionService { @@ -19,4 +21,8 @@ public Exposition save(Exposition exposition) { public long count() { return expositionRepository.count(); } + + public Optional findById(long id) { + return expositionRepository.findById(id); + } } From b0e8822f2b3ac4d916ca6668cadbf46cf20ee619 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Sat, 5 Oct 2024 09:52:02 +0200 Subject: [PATCH 40/48] :sparkles: implementing find by id for guest --- .../main/java/com/ironhack/task2/service/GuestService.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/task2/src/main/java/com/ironhack/task2/service/GuestService.java b/task2/src/main/java/com/ironhack/task2/service/GuestService.java index 2a6484a..6b1d105 100644 --- a/task2/src/main/java/com/ironhack/task2/service/GuestService.java +++ b/task2/src/main/java/com/ironhack/task2/service/GuestService.java @@ -7,6 +7,7 @@ import org.springframework.stereotype.Service; import java.util.List; +import java.util.Optional; @Service @RequiredArgsConstructor @@ -26,4 +27,8 @@ public List findAll() { public void deleteById(Long id) { guestRepository.deleteById(id); } + + public Optional findById(Long id) { + return guestRepository.findById(id); + } } From ee2fdd79889b3c23875618a77bc8736bfc7219c4 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Sat, 5 Oct 2024 09:52:17 +0200 Subject: [PATCH 41/48] :sparkles: implementing find by id for speaker --- .../main/java/com/ironhack/task2/service/SpeakerService.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/task2/src/main/java/com/ironhack/task2/service/SpeakerService.java b/task2/src/main/java/com/ironhack/task2/service/SpeakerService.java index 9e676c0..b2a31e4 100644 --- a/task2/src/main/java/com/ironhack/task2/service/SpeakerService.java +++ b/task2/src/main/java/com/ironhack/task2/service/SpeakerService.java @@ -7,6 +7,7 @@ import org.springframework.stereotype.Service; import java.util.List; +import java.util.Optional; @Service @RequiredArgsConstructor @@ -26,4 +27,8 @@ public List findAll() { public void deleteById(Long id) { speakerRepository.deleteById(id); } + + public Optional findById(Long id) { + return speakerRepository.findById(id); + } } From a2f501e8aa93bffe8b74b5fcfac84d930e2d4c73 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Sat, 5 Oct 2024 10:29:45 +0200 Subject: [PATCH 42/48] :art: --- .../ironhack/task2/dataloader/DataLoader.java | 74 ++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java b/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java index 5ef6edf..6f3314f 100644 --- a/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java +++ b/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java @@ -8,6 +8,8 @@ import org.springframework.stereotype.Component; import java.time.LocalDate; +import java.util.List; +import java.util.Optional; @Component @RequiredArgsConstructor @@ -28,13 +30,81 @@ public void run(String... args) throws Exception { event.setDate(LocalDate.now()); eventService.save(event); + testCreateExposition(); + testCreateExpositionWithGuest(); + testDeleteGuestFromExposition(); + testCreateConference(); + testCreateConferenceWithSpeaker(); + testDeletingSpeakerFromConference(); + testCreatingConferenceWithGuest(); + testDeletingGuestFromConference(); + } + + public void testCreateExposition() { Exposition expositionSaved = createNewExposition(); + Optional result = expositionService.findById(expositionSaved.getId().longValue()); + if(result.isPresent()) { + System.out.println(result.get().getId() == expositionSaved.getId()); + } + } - Guest guestSaved = createNewGuest(expositionSaved); + public void testCreateExpositionWithGuest() { + Guest guest = createNewGuest(createNewExposition()); + Optional result = guestService.findById(guest.getId().longValue()); + if(result.isPresent()) { + System.out.println(result.get().getId() == guest.getId()); + } + } + public void testDeleteGuestFromExposition() { + Guest guest = createNewGuest(createNewExposition()); + guestService.deleteById(guest.getId()); + Optional result = guestService.findById(guest.getId().longValue()); + if(result.isEmpty()) { + System.out.println("TEST deleting exposition guest : OK"); + } + } + + public void testCreateConference() { Conference confSaved = createNewConference(); + Optional conferenceRetrieved = conferenceService.findById(confSaved.getId().longValue()); + if(conferenceRetrieved.isPresent()) { + System.out.println(conferenceRetrieved.get().getId() == confSaved.getId()); + } + } + + public void testCreateConferenceWithSpeaker() { + Speaker speaker = createNewSpeaker(createNewConference()); + Optional result = speakerService.findById(speaker.getId().longValue()); + if(result.isPresent()) { + System.out.println(result.get().getId() == speaker.getId()); + } + } + + public void testDeletingSpeakerFromConference() { + Speaker speaker = createNewSpeaker(createNewConference()); + speakerService.deleteById(speaker.getId()); + Optional result = speakerService.findById(speaker.getId().longValue()); + if(result.isEmpty()) { + System.out.println("TEST deleting speaker : OK"); + } + } + + public void testCreatingConferenceWithGuest() { + Guest guest = createNewGuest(createNewConference()); + Optional result = guestService.findById(guest.getId().longValue()); + if(result.isPresent()) { + System.out.println(result.get().getId() == guest.getId()); + } + } - Speaker speakerSaved = createNewSpeaker(confSaved); + public void testDeletingGuestFromConference() { + Guest guest = createNewGuest(createNewConference()); + guestService.deleteById(guest.getId()); + Optional result = guestService.findById(guest.getId().longValue()); + if(result.isEmpty()) { + System.out.println("TEST deleting conference guest : OK"); + } } private Guest createNewGuest( Event event) { From 665901c252773d21a881c4601d18149d8a408ba3 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Sat, 5 Oct 2024 14:41:00 +0200 Subject: [PATCH 43/48] :sparkles: implementing find by id and delete by id for chapter --- .../com/ironhack/task1/service/ChapterService.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/task1/src/main/java/com/ironhack/task1/service/ChapterService.java b/task1/src/main/java/com/ironhack/task1/service/ChapterService.java index 72b9a35..f9048eb 100644 --- a/task1/src/main/java/com/ironhack/task1/service/ChapterService.java +++ b/task1/src/main/java/com/ironhack/task1/service/ChapterService.java @@ -7,6 +7,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import java.util.Optional; + @Service @RequiredArgsConstructor @Slf4j @@ -19,4 +21,15 @@ public Chapter save(Chapter chapter) { log.info("Saving chapter: {}", chapter); return chapterRepository.save(chapter); } + + @Transactional + public void deleteById(Long id) { + log.info("Deleting chapter: {}", id); + chapterRepository.deleteById(id); + } + + public Optional findById(Long id) { + log.info("Finding chapter: {}", id); + return chapterRepository.findById(id); + } } From 8a37c1731a41f1935fad1a41f9d8083f3ffccdbc Mon Sep 17 00:00:00 2001 From: pugeaale Date: Sat, 5 Oct 2024 14:43:01 +0200 Subject: [PATCH 44/48] :bug: --- .../java/com/ironhack/task1/repository/MemberRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task1/src/main/java/com/ironhack/task1/repository/MemberRepository.java b/task1/src/main/java/com/ironhack/task1/repository/MemberRepository.java index 0f87caf..a7b4665 100644 --- a/task1/src/main/java/com/ironhack/task1/repository/MemberRepository.java +++ b/task1/src/main/java/com/ironhack/task1/repository/MemberRepository.java @@ -5,5 +5,5 @@ import org.springframework.stereotype.Repository; @Repository -public interface MemberRepository extends JpaRepository { +public interface MemberRepository extends JpaRepository { } From 628f9c5ab3203f2a1b89a05783be986b45507899 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Sat, 5 Oct 2024 14:43:21 +0200 Subject: [PATCH 45/48] :sparkles: implementing find by id and delete by id for member --- .../com/ironhack/task1/service/MemberService.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/task1/src/main/java/com/ironhack/task1/service/MemberService.java b/task1/src/main/java/com/ironhack/task1/service/MemberService.java index 13b59b2..2900724 100644 --- a/task1/src/main/java/com/ironhack/task1/service/MemberService.java +++ b/task1/src/main/java/com/ironhack/task1/service/MemberService.java @@ -1,5 +1,6 @@ package com.ironhack.task1.service; +import com.ironhack.task1.model.Chapter; import com.ironhack.task1.model.Member; import com.ironhack.task1.repository.MemberRepository; import jakarta.transaction.Transactional; @@ -7,6 +8,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import java.util.Optional; + @Service @RequiredArgsConstructor @Slf4j @@ -19,4 +22,15 @@ public Member save(Member member) { log.info("Saving member {}", member); return memberRepository.save(member); } + + @Transactional + public void deleteById(Long id) { + log.info("Deleting member: {}", id); + memberRepository.deleteById(id); + } + + public Optional findById(Long id) { + log.info("Finding member: {}", id); + return memberRepository.findById(id); + } } From 55bde755ea6a156921f74c29087b2d74c7d6293f Mon Sep 17 00:00:00 2001 From: pugeaale Date: Sat, 5 Oct 2024 14:54:51 +0200 Subject: [PATCH 46/48] :sparkles: implementing add member for chapter to set the chapter properly to the member --- .../src/main/java/com/ironhack/task1/model/Chapter.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/task1/src/main/java/com/ironhack/task1/model/Chapter.java b/task1/src/main/java/com/ironhack/task1/model/Chapter.java index 2c1deae..ccc51c7 100644 --- a/task1/src/main/java/com/ironhack/task1/model/Chapter.java +++ b/task1/src/main/java/com/ironhack/task1/model/Chapter.java @@ -32,4 +32,13 @@ public Chapter(String district, String name) { this.district = district; this.name = name; } + + public void addMember(Member member) { + member.setChapter(this); + members.add(member); + } + + public void removeMember(Member member) { + members.remove(member); + } } From 63054acf1cafa0aec7f18d7f3daa8bb705d9ade9 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Sat, 5 Oct 2024 14:56:11 +0200 Subject: [PATCH 47/48] :art: implementing test for crud operations --- .../ironhack/task1/dataloader/DataLoader.java | 93 +++++++++++++++++-- 1 file changed, 85 insertions(+), 8 deletions(-) diff --git a/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java b/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java index acb0645..a6fc3f2 100644 --- a/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java +++ b/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java @@ -10,6 +10,7 @@ import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component; import java.time.ZonedDateTime; +import java.util.Optional; @Component @RequiredArgsConstructor @@ -19,21 +20,97 @@ public class DataLoader implements CommandLineRunner { private final ChapterService chapterService; + private Faker faker = new Faker(); + @Override public void run(String... args) throws Exception { - //create7chaptersWithPresidents(); + testCreateChapterWithoutPresident(); + testFindChapterById(); + testDeleteChapterById(); + + testCreateMemberWithoutChapter(); + testFindMemberById(); + testDeleteMemberById(); + + testCreateMemberWithChapter(); + testCreateChapterWithPresident(); + } + + private void testDeleteMemberById() { + memberService.deleteById(1L); + Optional opt = memberService.findById(1L); + System.out.println(opt.isEmpty()); + } + + private void testFindMemberById() { + Optional opt = memberService.findById(1L); + System.out.println(opt.isPresent()); + } + + private void testDeleteChapterById() { + chapterService.deleteById(1L); + Optional opt = chapterService.findById(1L); + System.out.println(opt.isEmpty()); + } + + private void testFindChapterById() { + Optional opt = chapterService.findById(1L); + System.out.println(opt.isPresent()); + } + + public void testCreateChapterWithoutPresident() { + Chapter chapter = new Chapter( + faker.address().city(), + faker.name().fullName()); + Chapter chapterSaved = chapterService.save(chapter); + System.out.println(chapterSaved.getName().equals(chapter.getName())); + } + + public void testCreateMemberWithoutChapter() { Member member = new Member( - "dd", + faker.name().fullName(), ZonedDateTime.now(), - MemberStatus.ACTIVE - ); - Chapter chapter = new Chapter("d","dd"); + MemberStatus.ACTIVE); + Member memberSaved = memberService.save(member); + System.out.println(memberSaved.getName().equals(member.getName())); + + } + + public void testCreateMemberWithChapter() { + Member member = new Member( + faker.name().fullName(), + ZonedDateTime.now(), + MemberStatus.ACTIVE); + Chapter chapter = new Chapter( + faker.address().city(), + faker.name().fullName()); member.setChapter(chapter); - memberService.save(member); + Member memberSaved = memberService.save(member); + System.out.println("testCreateMemberWithChapter : " + + memberSaved.getName().equals(member.getName()) + " - " + + memberSaved.getChapter().getName().equals(chapter.getName()) + ); + + } + + public void testCreateChapterWithPresident() { + Chapter chapter = new Chapter( + faker.address().city(), + faker.name().fullName()); + Member president = new Member( + faker.name().fullName(), + ZonedDateTime.now(), + MemberStatus.ACTIVE); + chapter.setPresident(president); + Chapter chapterSaved = chapterService.save(chapter); + System.out.println("testCreateChapterWithPresident : " + + chapterSaved.getName().equals(chapter.getName()) + " - " + + chapterSaved.getPresident().getName().equals(president.getName()) + ); } public void create7chaptersWithPresidents() { - Faker faker = new Faker(); + for(int i = 0; i < 1; i++) { Chapter chapter = new Chapter( faker.address().cityName(), @@ -50,7 +127,7 @@ public void create7chaptersWithPresidents() { faker.name().femaleFirstName(), ZonedDateTime.now(), MemberStatus.ACTIVE); - chapter.getMembers().add(member); + chapter.addMember(member); chapterService.save(chapter); } From 98b89c2dbc25ac1c1348531c94c158d7d6e9d3d4 Mon Sep 17 00:00:00 2001 From: pugeaale Date: Sat, 5 Oct 2024 22:10:12 +0200 Subject: [PATCH 48/48] :sparkles: implementing joined Inheritance strategy --- task2/src/main/java/com/ironhack/task2/model/Conference.java | 3 +++ task2/src/main/java/com/ironhack/task2/model/Event.java | 1 + task2/src/main/java/com/ironhack/task2/model/Exposition.java | 2 ++ 3 files changed, 6 insertions(+) diff --git a/task2/src/main/java/com/ironhack/task2/model/Conference.java b/task2/src/main/java/com/ironhack/task2/model/Conference.java index 1569439..299e907 100644 --- a/task2/src/main/java/com/ironhack/task2/model/Conference.java +++ b/task2/src/main/java/com/ironhack/task2/model/Conference.java @@ -1,7 +1,9 @@ package com.ironhack.task2.model; import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; import jakarta.persistence.OneToMany; +import jakarta.persistence.PrimaryKeyJoinColumn; import lombok.Data; import lombok.NoArgsConstructor; @@ -12,6 +14,7 @@ @Data @NoArgsConstructor @Entity +@PrimaryKeyJoinColumn(name="id") public class Conference extends Event { @OneToMany(mappedBy = "conference") diff --git a/task2/src/main/java/com/ironhack/task2/model/Event.java b/task2/src/main/java/com/ironhack/task2/model/Event.java index 18b68f4..657d050 100644 --- a/task2/src/main/java/com/ironhack/task2/model/Event.java +++ b/task2/src/main/java/com/ironhack/task2/model/Event.java @@ -17,6 +17,7 @@ @Data @NoArgsConstructor @Entity +@Inheritance(strategy=InheritanceType.JOINED) public class Event { @Id diff --git a/task2/src/main/java/com/ironhack/task2/model/Exposition.java b/task2/src/main/java/com/ironhack/task2/model/Exposition.java index 6ec5e80..28fb2c3 100644 --- a/task2/src/main/java/com/ironhack/task2/model/Exposition.java +++ b/task2/src/main/java/com/ironhack/task2/model/Exposition.java @@ -1,6 +1,7 @@ package com.ironhack.task2.model; import jakarta.persistence.Entity; +import jakarta.persistence.PrimaryKeyJoinColumn; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -10,6 +11,7 @@ @Data @NoArgsConstructor @Entity +@PrimaryKeyJoinColumn(name="id") public class Exposition extends Event { public Exposition(String title, String location, LocalDate date, Integer duration) {