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..0d15c4a --- /dev/null +++ b/task1/pom.xml @@ -0,0 +1,82 @@ + + + 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 + + + net.datafaker + datafaker + 2.4.0 + + + 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..8ae99ba --- /dev/null +++ b/task1/src/main/java/com/ironhack/task1/Task1Application.java @@ -0,0 +1,12 @@ +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/java/com/ironhack/task1/dataloader/DataLoader.java b/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java new file mode 100644 index 0000000..a6fc3f2 --- /dev/null +++ b/task1/src/main/java/com/ironhack/task1/dataloader/DataLoader.java @@ -0,0 +1,136 @@ +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 net.datafaker.Faker; +import org.springframework.boot.CommandLineRunner; +import org.springframework.stereotype.Component; +import java.time.ZonedDateTime; +import java.util.Optional; + +@Component +@RequiredArgsConstructor +public class DataLoader implements CommandLineRunner { + + private final MemberService memberService; + + private final ChapterService chapterService; + + private Faker faker = new Faker(); + + @Override + public void run(String... args) throws Exception { + 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( + faker.name().fullName(), + ZonedDateTime.now(), + 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); + 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() { + + for(int i = 0; i < 1; 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); + + Member member = new Member( + faker.name().femaleFirstName(), + ZonedDateTime.now(), + MemberStatus.ACTIVE); + chapter.addMember(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 new file mode 100644 index 0000000..ccc51c7 --- /dev/null +++ b/task1/src/main/java/com/ironhack/task1/model/Chapter.java @@ -0,0 +1,44 @@ +package com.ironhack.task1.model; + +import jakarta.persistence.*; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; + +@Data +@NoArgsConstructor +@Entity +public class Chapter { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String district; + + private String name; + + @OneToOne(cascade = CascadeType.ALL) + @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; + } + + public void addMember(Member member) { + member.setChapter(this); + members.add(member); + } + + public void removeMember(Member member) { + members.remove(member); + } +} 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..486cfbb --- /dev/null +++ b/task1/src/main/java/com/ironhack/task1/model/Member.java @@ -0,0 +1,32 @@ +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; + + @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; + 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/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/repository/MemberRepository.java b/task1/src/main/java/com/ironhack/task1/repository/MemberRepository.java new file mode 100644 index 0000000..a7b4665 --- /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/ChapterService.java b/task1/src/main/java/com/ironhack/task1/service/ChapterService.java new file mode 100644 index 0000000..f9048eb --- /dev/null +++ b/task1/src/main/java/com/ironhack/task1/service/ChapterService.java @@ -0,0 +1,35 @@ +package com.ironhack.task1.service; + +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; + +import java.util.Optional; + +@Service +@RequiredArgsConstructor +@Slf4j +public class ChapterService { + + private final ChapterRepository chapterRepository; + + @Transactional + 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); + } +} 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..2900724 --- /dev/null +++ b/task1/src/main/java/com/ironhack/task1/service/MemberService.java @@ -0,0 +1,36 @@ +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; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.util.Optional; + +@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); + } + + @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); + } +} diff --git a/task1/src/main/resources/application.properties b/task1/src/main/resources/application.properties new file mode 100644 index 0000000..cced6d9 --- /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=update +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..61452ea --- /dev/null +++ b/task2/pom.xml @@ -0,0 +1,82 @@ + + + 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 + + + net.datafaker + datafaker + 2.4.0 + + + 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/java/com/ironhack/task2/dataloader/DataLoader.java b/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java new file mode 100644 index 0000000..6f3314f --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/dataloader/DataLoader.java @@ -0,0 +1,145 @@ +package com.ironhack.task2.dataloader; + +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; + +import java.time.LocalDate; +import java.util.List; +import java.util.Optional; + +@Component +@RequiredArgsConstructor +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; + private Faker faker = new Faker(); + + @Override + public void run(String... args) throws Exception { + Event event = new Event(); + event.setDuration(32); + event.setLocation("paris"); + event.setTitle("mondial tattoo"); + 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()); + } + } + + 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()); + } + } + + 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) { + 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(faker.number().positive()); + exposition.setLocation(faker.address().city()); + exposition.setTitle(faker.artist().name()); + exposition.setDate(LocalDate.now()); + 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(faker.number().positive()); + conference.setLocation(faker.address().city()); + conference.setTitle(faker.community().character()); + conference.setDate(LocalDate.now()); + return conferenceService.save(conference); + } + + +} 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..299e907 --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/model/Conference.java @@ -0,0 +1,26 @@ +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; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +@Data +@NoArgsConstructor +@Entity +@PrimaryKeyJoinColumn(name="id") +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/Event.java b/task2/src/main/java/com/ironhack/task2/model/Event.java new file mode 100644 index 0000000..657d050 --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/model/Event.java @@ -0,0 +1,41 @@ +package com.ironhack.task2.model; + +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 +duration: the duration of the event +location: the location of the event +title: the title of the event + */ +@Data +@NoArgsConstructor +@Entity +@Inheritance(strategy=InheritanceType.JOINED) +public class Event { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String title; + private String location; + 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; + this.date = date; + this.duration = duration; + } +} 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..28fb2c3 --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/model/Exposition.java @@ -0,0 +1,20 @@ +package com.ironhack.task2.model; + +import jakarta.persistence.Entity; +import jakarta.persistence.PrimaryKeyJoinColumn; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDate; + +@Data +@NoArgsConstructor +@Entity +@PrimaryKeyJoinColumn(name="id") +public class Exposition extends Event { + + public Exposition(String title, String location, LocalDate date, Integer duration) { + super(title, location, date, duration); + } +} 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..16c341c --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/model/Guest.java @@ -0,0 +1,30 @@ +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; + + //we want a lazy loading by default eager + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "eventId", referencedColumnName = "id") + private Event event; + + 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 +} 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..f7a593f --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/model/Speaker.java @@ -0,0 +1,27 @@ +package com.ironhack.task2.model; + +import jakarta.persistence.*; +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; + + //we want a lazy loading by default eager + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "conferenceId" , referencedColumnName = "id") + private Conference conference; + + public Speaker(String name, Integer presentationDuration) { + this.name = name; + this.presentationDuration = presentationDuration; + } +} 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 { +} 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 { +} 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 { +} 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 { +} 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 { +} 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..6edc07e --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/service/ConferenceService.java @@ -0,0 +1,28 @@ +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; + +import java.util.Optional; + +@Service +@RequiredArgsConstructor +public class ConferenceService { + private final ConferenceRepository conferenceRepository; + + @Transactional + public Conference save(Conference conference) { + return conferenceRepository.save(conference); + } + + public long count() { + return conferenceRepository.count(); + } + + public Optional findById(long id) { + return conferenceRepository.findById(id); + } +} 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..d802e16 --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/service/EventService.java @@ -0,0 +1,22 @@ +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); + } + + 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 new file mode 100644 index 0000000..699df5d --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/service/ExpositionService.java @@ -0,0 +1,28 @@ +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; + +import java.util.Optional; + +@Service +@RequiredArgsConstructor +public class ExpositionService { + private final ExpositionRepository expositionRepository; + + @Transactional + public Exposition save(Exposition exposition) { + return expositionRepository.save(exposition); + } + + public long count() { + return expositionRepository.count(); + } + + public Optional findById(long id) { + return expositionRepository.findById(id); + } +} 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..6b1d105 --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/service/GuestService.java @@ -0,0 +1,34 @@ +package com.ironhack.task2.service; + +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; +import java.util.Optional; + +@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); + } + + public Optional findById(Long id) { + return guestRepository.findById(id); + } +} 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..b2a31e4 --- /dev/null +++ b/task2/src/main/java/com/ironhack/task2/service/SpeakerService.java @@ -0,0 +1,34 @@ +package com.ironhack.task2.service; + +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; +import java.util.Optional; + +@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); + } + + public Optional findById(Long id) { + return speakerRepository.findById(id); + } +} diff --git a/task2/src/main/resources/application.properties b/task2/src/main/resources/application.properties new file mode 100644 index 0000000..7e8f276 --- /dev/null +++ b/task2/src/main/resources/application.properties @@ -0,0 +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 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() { + } + +}