diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..3b41682 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +/mvnw text eol=lf +*.cmd text eol=crlf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..667aaef --- /dev/null +++ b/.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/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..8dea6c2 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,3 @@ +wrapperVersion=3.3.4 +distributionType=only-script +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.12/apache-maven-3.9.12-bin.zip diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f5f438d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,5 @@ +FROM eclipse-temurin:25 +WORKDIR /app +COPY target/demo-0.0.1-SNAPSHOT.jar app.jar +EXPOSE 8080 +ENTRYPOINT ["java","-jar","app.jar"] diff --git a/mvnw b/mvnw new file mode 100644 index 0000000..bd8896b --- /dev/null +++ b/mvnw @@ -0,0 +1,295 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.4 +# +# Optional ENV vars +# ----------------- +# JAVA_HOME - location of a JDK home dir, required when download maven via java source +# MVNW_REPOURL - repo url base for downloading maven distribution +# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output +# ---------------------------------------------------------------------------- + +set -euf +[ "${MVNW_VERBOSE-}" != debug ] || set -x + +# OS specific support. +native_path() { printf %s\\n "$1"; } +case "$(uname)" in +CYGWIN* | MINGW*) + [ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")" + native_path() { cygpath --path --windows "$1"; } + ;; +esac + +# set JAVACMD and JAVACCMD +set_java_home() { + # For Cygwin and MinGW, ensure paths are in Unix format before anything is touched + if [ -n "${JAVA_HOME-}" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACCMD="$JAVA_HOME/jre/sh/javac" + else + JAVACMD="$JAVA_HOME/bin/java" + JAVACCMD="$JAVA_HOME/bin/javac" + + if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then + echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2 + echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2 + return 1 + fi + fi + else + JAVACMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v java + )" || : + JAVACCMD="$( + 'set' +e + 'unset' -f command 2>/dev/null + 'command' -v javac + )" || : + + if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then + echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2 + return 1 + fi + fi +} + +# hash string like Java String::hashCode +hash_string() { + str="${1:-}" h=0 + while [ -n "$str" ]; do + char="${str%"${str#?}"}" + h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296)) + str="${str#?}" + done + printf %x\\n $h +} + +verbose() { :; } +[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; } + +die() { + printf %s\\n "$1" >&2 + exit 1 +} + +trim() { + # MWRAPPER-139: + # Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds. + # Needed for removing poorly interpreted newline sequences when running in more + # exotic environments such as mingw bash on Windows. + printf "%s" "${1}" | tr -d '[:space:]' +} + +scriptDir="$(dirname "$0")" +scriptName="$(basename "$0")" + +# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties +while IFS="=" read -r key value; do + case "${key-}" in + distributionUrl) distributionUrl=$(trim "${value-}") ;; + distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;; + esac +done <"$scriptDir/.mvn/wrapper/maven-wrapper.properties" +[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" + +case "${distributionUrl##*/}" in +maven-mvnd-*bin.*) + MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ + case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in + *AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;; + :Darwin*x86_64) distributionPlatform=darwin-amd64 ;; + :Darwin*arm64) distributionPlatform=darwin-aarch64 ;; + :Linux*x86_64*) distributionPlatform=linux-amd64 ;; + *) + echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2 + distributionPlatform=linux-amd64 + ;; + esac + distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip" + ;; +maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;; +*) MVN_CMD="mvn${scriptName#mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;; +esac + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +[ -z "${MVNW_REPOURL-}" ] || distributionUrl="$MVNW_REPOURL$_MVNW_REPO_PATTERN${distributionUrl#*"$_MVNW_REPO_PATTERN"}" +distributionUrlName="${distributionUrl##*/}" +distributionUrlNameMain="${distributionUrlName%.*}" +distributionUrlNameMain="${distributionUrlNameMain%-bin}" +MAVEN_USER_HOME="${MAVEN_USER_HOME:-${HOME}/.m2}" +MAVEN_HOME="${MAVEN_USER_HOME}/wrapper/dists/${distributionUrlNameMain-}/$(hash_string "$distributionUrl")" + +exec_maven() { + unset MVNW_VERBOSE MVNW_USERNAME MVNW_PASSWORD MVNW_REPOURL || : + exec "$MAVEN_HOME/bin/$MVN_CMD" "$@" || die "cannot exec $MAVEN_HOME/bin/$MVN_CMD" +} + +if [ -d "$MAVEN_HOME" ]; then + verbose "found existing MAVEN_HOME at $MAVEN_HOME" + exec_maven "$@" +fi + +case "${distributionUrl-}" in +*?-bin.zip | *?maven-mvnd-?*-?*.zip) ;; +*) die "distributionUrl is not valid, must match *-bin.zip or maven-mvnd-*.zip, but found '${distributionUrl-}'" ;; +esac + +# prepare tmp dir +if TMP_DOWNLOAD_DIR="$(mktemp -d)" && [ -d "$TMP_DOWNLOAD_DIR" ]; then + clean() { rm -rf -- "$TMP_DOWNLOAD_DIR"; } + trap clean HUP INT TERM EXIT +else + die "cannot create temp dir" +fi + +mkdir -p -- "${MAVEN_HOME%/*}" + +# Download and Install Apache Maven +verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +verbose "Downloading from: $distributionUrl" +verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +# select .zip or .tar.gz +if ! command -v unzip >/dev/null; then + distributionUrl="${distributionUrl%.zip}.tar.gz" + distributionUrlName="${distributionUrl##*/}" +fi + +# verbose opt +__MVNW_QUIET_WGET=--quiet __MVNW_QUIET_CURL=--silent __MVNW_QUIET_UNZIP=-q __MVNW_QUIET_TAR='' +[ "${MVNW_VERBOSE-}" != true ] || __MVNW_QUIET_WGET='' __MVNW_QUIET_CURL='' __MVNW_QUIET_UNZIP='' __MVNW_QUIET_TAR=v + +# normalize http auth +case "${MVNW_PASSWORD:+has-password}" in +'') MVNW_USERNAME='' MVNW_PASSWORD='' ;; +has-password) [ -n "${MVNW_USERNAME-}" ] || MVNW_USERNAME='' MVNW_PASSWORD='' ;; +esac + +if [ -z "${MVNW_USERNAME-}" ] && command -v wget >/dev/null; then + verbose "Found wget ... using wget" + wget ${__MVNW_QUIET_WGET:+"$__MVNW_QUIET_WGET"} "$distributionUrl" -O "$TMP_DOWNLOAD_DIR/$distributionUrlName" || die "wget: Failed to fetch $distributionUrl" +elif [ -z "${MVNW_USERNAME-}" ] && command -v curl >/dev/null; then + verbose "Found curl ... using curl" + curl ${__MVNW_QUIET_CURL:+"$__MVNW_QUIET_CURL"} -f -L -o "$TMP_DOWNLOAD_DIR/$distributionUrlName" "$distributionUrl" || die "curl: Failed to fetch $distributionUrl" +elif set_java_home; then + verbose "Falling back to use Java to download" + javaSource="$TMP_DOWNLOAD_DIR/Downloader.java" + targetZip="$TMP_DOWNLOAD_DIR/$distributionUrlName" + cat >"$javaSource" <<-END + public class Downloader extends java.net.Authenticator + { + protected java.net.PasswordAuthentication getPasswordAuthentication() + { + return new java.net.PasswordAuthentication( System.getenv( "MVNW_USERNAME" ), System.getenv( "MVNW_PASSWORD" ).toCharArray() ); + } + public static void main( String[] args ) throws Exception + { + setDefault( new Downloader() ); + java.nio.file.Files.copy( java.net.URI.create( args[0] ).toURL().openStream(), java.nio.file.Paths.get( args[1] ).toAbsolutePath().normalize() ); + } + } + END + # For Cygwin/MinGW, switch paths to Windows format before running javac and java + verbose " - Compiling Downloader.java ..." + "$(native_path "$JAVACCMD")" "$(native_path "$javaSource")" || die "Failed to compile Downloader.java" + verbose " - Running Downloader.java ..." + "$(native_path "$JAVACMD")" -cp "$(native_path "$TMP_DOWNLOAD_DIR")" Downloader "$distributionUrl" "$(native_path "$targetZip")" +fi + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +if [ -n "${distributionSha256Sum-}" ]; then + distributionSha256Result=false + if [ "$MVN_CMD" = mvnd.sh ]; then + echo "Checksum validation is not supported for maven-mvnd." >&2 + echo "Please disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + elif command -v sha256sum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | sha256sum -c - >/dev/null 2>&1; then + distributionSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$distributionSha256Sum $TMP_DOWNLOAD_DIR/$distributionUrlName" | shasum -a 256 -c >/dev/null 2>&1; then + distributionSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $distributionSha256Result = false ]; then + echo "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised." >&2 + echo "If you updated your Maven version, you need to update the specified distributionSha256Sum property." >&2 + exit 1 + fi +fi + +# unzip and move +if command -v unzip >/dev/null; then + unzip ${__MVNW_QUIET_UNZIP:+"$__MVNW_QUIET_UNZIP"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -d "$TMP_DOWNLOAD_DIR" || die "failed to unzip" +else + tar xzf${__MVNW_QUIET_TAR:+"$__MVNW_QUIET_TAR"} "$TMP_DOWNLOAD_DIR/$distributionUrlName" -C "$TMP_DOWNLOAD_DIR" || die "failed to untar" +fi + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +actualDistributionDir="" + +# First try the expected directory name (for regular distributions) +if [ -d "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" ]; then + if [ -f "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/bin/$MVN_CMD" ]; then + actualDistributionDir="$distributionUrlNameMain" + fi +fi + +# If not found, search for any directory with the Maven executable (for snapshots) +if [ -z "$actualDistributionDir" ]; then + # enable globbing to iterate over items + set +f + for dir in "$TMP_DOWNLOAD_DIR"/*; do + if [ -d "$dir" ]; then + if [ -f "$dir/bin/$MVN_CMD" ]; then + actualDistributionDir="$(basename "$dir")" + break + fi + fi + done + set -f +fi + +if [ -z "$actualDistributionDir" ]; then + verbose "Contents of $TMP_DOWNLOAD_DIR:" + verbose "$(ls -la "$TMP_DOWNLOAD_DIR")" + die "Could not find Maven distribution directory in extracted archive" +fi + +verbose "Found extracted Maven distribution directory: $actualDistributionDir" +printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$actualDistributionDir/mvnw.url" +mv -- "$TMP_DOWNLOAD_DIR/$actualDistributionDir" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME" + +clean || : +exec_maven "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100755 index 0000000..92450f9 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,189 @@ +<# : batch portion +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.4 +@REM +@REM Optional ENV vars +@REM MVNW_REPOURL - repo url base for downloading maven distribution +@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven +@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output +@REM ---------------------------------------------------------------------------- + +@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0) +@SET __MVNW_CMD__= +@SET __MVNW_ERROR__= +@SET __MVNW_PSMODULEP_SAVE=%PSModulePath% +@SET PSModulePath= +@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @( + IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B) +) +@SET PSModulePath=%__MVNW_PSMODULEP_SAVE% +@SET __MVNW_PSMODULEP_SAVE= +@SET __MVNW_ARG0_NAME__= +@SET MVNW_USERNAME= +@SET MVNW_PASSWORD= +@IF NOT "%__MVNW_CMD__%"=="" ("%__MVNW_CMD__%" %*) +@echo Cannot start maven from wrapper >&2 && exit /b 1 +@GOTO :EOF +: end batch / begin powershell #> + +$ErrorActionPreference = "Stop" +if ($env:MVNW_VERBOSE -eq "true") { + $VerbosePreference = "Continue" +} + +# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties +$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl +if (!$distributionUrl) { + Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties" +} + +switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) { + "maven-mvnd-*" { + $USE_MVND = $true + $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip" + $MVN_CMD = "mvnd.cmd" + break + } + default { + $USE_MVND = $false + $MVN_CMD = $script -replace '^mvnw','mvn' + break + } +} + +# apply MVNW_REPOURL and calculate MAVEN_HOME +# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/ +if ($env:MVNW_REPOURL) { + $MVNW_REPO_PATTERN = if ($USE_MVND -eq $False) { "/org/apache/maven/" } else { "/maven/mvnd/" } + $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace "^.*$MVNW_REPO_PATTERN",'')" +} +$distributionUrlName = $distributionUrl -replace '^.*/','' +$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$','' + +$MAVEN_M2_PATH = "$HOME/.m2" +if ($env:MAVEN_USER_HOME) { + $MAVEN_M2_PATH = "$env:MAVEN_USER_HOME" +} + +if (-not (Test-Path -Path $MAVEN_M2_PATH)) { + New-Item -Path $MAVEN_M2_PATH -ItemType Directory | Out-Null +} + +$MAVEN_WRAPPER_DISTS = $null +if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) { + $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists" +} else { + $MAVEN_WRAPPER_DISTS = (Get-Item $MAVEN_M2_PATH).Target[0] + "/wrapper/dists" +} + +$MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain" +$MAVEN_HOME_NAME = ([System.Security.Cryptography.SHA256]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join '' +$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME" + +if (Test-Path -Path "$MAVEN_HOME" -PathType Container) { + Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME" + Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" + exit $? +} + +if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) { + Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl" +} + +# prepare tmp dir +$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile +$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir" +$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null +trap { + if ($TMP_DOWNLOAD_DIR.Exists) { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } + } +} + +New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null + +# Download and Install Apache Maven +Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..." +Write-Verbose "Downloading from: $distributionUrl" +Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName" + +$webclient = New-Object System.Net.WebClient +if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) { + $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD) +} +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 +$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null + +# If specified, validate the SHA-256 sum of the Maven distribution zip file +$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum +if ($distributionSha256Sum) { + if ($USE_MVND) { + Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties." + } + Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash + if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) { + Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property." + } +} + +# unzip and move +Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null + +# Find the actual extracted directory name (handles snapshots where filename != directory name) +$actualDistributionDir = "" + +# First try the expected directory name (for regular distributions) +$expectedPath = Join-Path "$TMP_DOWNLOAD_DIR" "$distributionUrlNameMain" +$expectedMvnPath = Join-Path "$expectedPath" "bin/$MVN_CMD" +if ((Test-Path -Path $expectedPath -PathType Container) -and (Test-Path -Path $expectedMvnPath -PathType Leaf)) { + $actualDistributionDir = $distributionUrlNameMain +} + +# If not found, search for any directory with the Maven executable (for snapshots) +if (!$actualDistributionDir) { + Get-ChildItem -Path "$TMP_DOWNLOAD_DIR" -Directory | ForEach-Object { + $testPath = Join-Path $_.FullName "bin/$MVN_CMD" + if (Test-Path -Path $testPath -PathType Leaf) { + $actualDistributionDir = $_.Name + } + } +} + +if (!$actualDistributionDir) { + Write-Error "Could not find Maven distribution directory in extracted archive" +} + +Write-Verbose "Found extracted Maven distribution directory: $actualDistributionDir" +Rename-Item -Path "$TMP_DOWNLOAD_DIR/$actualDistributionDir" -NewName $MAVEN_HOME_NAME | Out-Null +try { + Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null +} catch { + if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) { + Write-Error "fail to move MAVEN_HOME" + } +} finally { + try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null } + catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" } +} + +Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD" diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..a677ca3 --- /dev/null +++ b/pom.xml @@ -0,0 +1,129 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 4.0.3 + + + com.example + demo + 0.0.1-SNAPSHOT + recipeDemo + Software engineering recipe project + + + + + + + + + + + + + + + 25 + + + + + + org.springframework.boot + spring-boot-starter-web + + + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + + org.springframework.boot + spring-boot-starter-security + + + + + org.springframework.boot + spring-boot-starter-validation + + + + + com.mysql + mysql-connector-j + runtime + + + + + org.projectlombok + lombok + true + + + + + org.springframework.boot + spring-boot-devtools + runtime + true + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + org.springframework.security + spring-security-test + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.projectlombok + lombok + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/src/main/java/com/example/demo/RecipeDemoApplication.java b/src/main/java/com/example/demo/RecipeDemoApplication.java new file mode 100644 index 0000000..de1e812 --- /dev/null +++ b/src/main/java/com/example/demo/RecipeDemoApplication.java @@ -0,0 +1,13 @@ +package com.example.demo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class RecipeDemoApplication { + + public static void main(String[] args) { + SpringApplication.run(RecipeDemoApplication.class, args); + } + +} diff --git a/src/main/java/com/example/demo/config/CorsConfig.java b/src/main/java/com/example/demo/config/CorsConfig.java new file mode 100644 index 0000000..2b81c0f --- /dev/null +++ b/src/main/java/com/example/demo/config/CorsConfig.java @@ -0,0 +1,37 @@ +package com.example.demo.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.cors.CorsConfigurationSource; + +import java.util.List; + +@Configuration +public class CorsConfig { + + @Bean + public CorsConfigurationSource corsConfigurationSource() { + + CorsConfiguration config = new CorsConfiguration(); + + // Allow your frontend origin (adjust if different) + config.setAllowedOrigins(List.of("http://localhost:8080/", + "http://localhost:5173")); + + // Allow common HTTP methods + config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); + + // Allow headers like Authorization (for JWT later) + config.setAllowedHeaders(List.of("*")); + + // Allow cookies if using sessions + config.setAllowCredentials(true); + + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", config); + + return source; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/config/SecurityConfig.java b/src/main/java/com/example/demo/config/SecurityConfig.java new file mode 100644 index 0000000..1f40ad5 --- /dev/null +++ b/src/main/java/com/example/demo/config/SecurityConfig.java @@ -0,0 +1,38 @@ +package com.example.demo.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.csrf.CsrfAuthenticationStrategy; + +@Configuration +public class SecurityConfig { + + @Bean + public PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } + + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + http + .csrf(csrf -> csrf.disable()) + .authorizeHttpRequests(auth -> auth + .requestMatchers("/login", "/register", "/css/**", "/images/**").permitAll() + .requestMatchers("/api/users").permitAll() + .requestMatchers("/api/admin/**").hasRole("ADMIN") + .anyRequest().authenticated() + ) + .formLogin(form -> form + .loginPage("/login") + .defaultSuccessUrl("/", true) + .permitAll() + ) + .logout(logout -> logout.permitAll()); + + return http.build(); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/controller/AdminController.java b/src/main/java/com/example/demo/controller/AdminController.java new file mode 100644 index 0000000..e3fabcf --- /dev/null +++ b/src/main/java/com/example/demo/controller/AdminController.java @@ -0,0 +1,39 @@ +package com.example.demo.controller; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import com.example.demo.dto.UserDto; +import com.example.demo.service.UserService; + +@RestController +@RequestMapping("/api/admin") +public class AdminController { + + private final UserService userService; + + public AdminController(UserService userService) { + this.userService = userService; + } + + @PostMapping("/users/{id}/ban") + public ResponseEntity banUser(@PathVariable Integer id) { + return new ResponseEntity<>(userService.banUser(id), HttpStatus.OK); + } + + @PostMapping("/users/{id}/unban") + public ResponseEntity unbanUser(@PathVariable Integer id) { + return new ResponseEntity<>(userService.unbanUser(id), HttpStatus.OK); + } + + @PostMapping("/users/{id}/make-admin") + public ResponseEntity makeAdmin(@PathVariable Integer id) { + return new ResponseEntity<>(userService.makeAdmin(id), HttpStatus.OK); + } + + @PostMapping("/users/{id}/make-user") + public ResponseEntity makeUser(@PathVariable Integer id) { + return new ResponseEntity<>(userService.makeUser(id), HttpStatus.OK); + } +} diff --git a/src/main/java/com/example/demo/controller/AuthController.java b/src/main/java/com/example/demo/controller/AuthController.java new file mode 100644 index 0000000..1fdce90 --- /dev/null +++ b/src/main/java/com/example/demo/controller/AuthController.java @@ -0,0 +1,5 @@ +package com.example.demo.controller; + +public class AuthController { + +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/controller/GlobalValidationHandler.java b/src/main/java/com/example/demo/controller/GlobalValidationHandler.java new file mode 100644 index 0000000..91a1abd --- /dev/null +++ b/src/main/java/com/example/demo/controller/GlobalValidationHandler.java @@ -0,0 +1,34 @@ +package com.example.demo.controller; + +import jakarta.validation.ConstraintViolationException; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.RestControllerAdvice; + +import java.util.HashMap; +import java.util.Map; + +@RestControllerAdvice +public class GlobalValidationHandler { + + @ExceptionHandler(ConstraintViolationException.class) + public ResponseEntity> handleConstraintViolation(ConstraintViolationException ex) { + Map errors = new HashMap<>(); + ex.getConstraintViolations().forEach(violation -> { + String fieldPath = violation.getPropertyPath().toString(); + errors.put(fieldPath, violation.getMessage()); + }); + return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST); + } + + @ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity> handleValidationExceptions(MethodArgumentNotValidException ex) { + Map errors = new HashMap<>(); + ex.getBindingResult().getFieldErrors().forEach(error -> { + errors.put(error.getField(), error.getDefaultMessage()); + }); + return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/controller/HealthController.java b/src/main/java/com/example/demo/controller/HealthController.java new file mode 100644 index 0000000..8d227bd --- /dev/null +++ b/src/main/java/com/example/demo/controller/HealthController.java @@ -0,0 +1,23 @@ +package com.example.demo.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.time.LocalDateTime; +import java.util.HashMap; +import java.util.Map; + +@RestController +public class HealthController { + + @GetMapping("/api/health") + public Map healthCheck() { + Map response = new HashMap<>(); + + response.put("status", "UP"); + response.put("timestamp", LocalDateTime.now()); + response.put("service", "Recipe Backend"); + + return response; + } +} diff --git a/src/main/java/com/example/demo/controller/RecipeController.java b/src/main/java/com/example/demo/controller/RecipeController.java new file mode 100644 index 0000000..360314c --- /dev/null +++ b/src/main/java/com/example/demo/controller/RecipeController.java @@ -0,0 +1,90 @@ +package com.example.demo.controller; + +import java.util.List; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.security.core.Authentication; + +import com.example.demo.dto.RecipeDto; +import com.example.demo.dto.UserDto; +import com.example.demo.entity.Recipe; +import com.example.demo.entity.User; +import com.example.demo.service.RecipeService; + +import jakarta.validation.Valid; + +@RestController +@RequestMapping("/api/recipes") +public class RecipeController { + + private RecipeService recipeService; + + public RecipeController(RecipeService recipeService) { + super(); + this.recipeService = recipeService; + } + + // build create recipe REST API + @PostMapping + public ResponseEntity saveRecipe(@RequestBody RecipeDto recipeDto, Authentication authentication) { + String currentUsername = authentication.getName(); + return new ResponseEntity<>(recipeService.saveRecipe(recipeDto, currentUsername), HttpStatus.CREATED); + } + + // build get all recipes REST API + @GetMapping + public List getAllRecipes() { + return recipeService.getAllRecipes(); + } + + // build get recipe by id REST API + // http://localhost:8080/api/recipes/(id number goes here) + @GetMapping("{id}") + public ResponseEntity getRecipeById(@PathVariable("id") Integer recipeId) { + return new ResponseEntity(recipeService.getRecipeById(recipeId), HttpStatus.OK); + } + + // build get recipe by name REST API + @GetMapping("/search") + public ResponseEntity> searchRecipes( + @RequestParam(required = false) String name, // by not adding a name all recipes will appear basically + @RequestParam(required = false) List tags // since users can choose no tags this isnt required + ) { + + + + List recipes = recipeService.getRecipes(name, tags); + return new ResponseEntity<>(recipes, HttpStatus.OK); + } + + // build update recipe REST API + // http://localhost:8080/api/recipes/(id number goes here) + @PutMapping("{id}") + public ResponseEntity updateRecipe( + @PathVariable("id") Integer recipeId, + @RequestBody RecipeDto recipeDto, + Authentication authentication) { + String currentUsername = authentication.getName(); + return new ResponseEntity<>(recipeService.updateRecipe(recipeDto, recipeId, currentUsername), HttpStatus.OK); + } + + // build delete recipe REST API + // http://localhost:8080/api/recipes/(id number goes here) + @DeleteMapping("{id}") + public ResponseEntity deleteRecipe(@PathVariable("id") Integer recipeId, Authentication authentication) { + String currentUsername = authentication.getName(); + recipeService.deleteRecipe(recipeId, currentUsername); + return new ResponseEntity<>("Recipe deleted successfully!", HttpStatus.OK); + } + +} diff --git a/src/main/java/com/example/demo/controller/SiteController.java b/src/main/java/com/example/demo/controller/SiteController.java new file mode 100644 index 0000000..8c4d0f8 --- /dev/null +++ b/src/main/java/com/example/demo/controller/SiteController.java @@ -0,0 +1,60 @@ +package com.example.demo.controller; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import com.example.demo.service.RecipeService; +import com.example.demo.dto.RecipeDto; +import com.example.demo.entity.Recipe; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + +@Controller +public class SiteController { + + private final RecipeService recipeService; + + public SiteController(RecipeService recipeService) { + this.recipeService = recipeService; + } + @GetMapping("/") + public String viewHomePage(Model model) { + //model.addAttribute("allemplist", employeeServiceImpl.getAllEmployee()); + List recipes = recipeService.getAllRecipes(); + model.addAttribute("recipes", recipes); + return "home"; + } + + @GetMapping("/login") + public String viewLoginPage(Model model) { + return "login"; + } + + @GetMapping("/register") + public String viewRegisterPage(Model model) { + return "create-account"; + } + + @GetMapping("/create") + public String viewCreatePage(Model model) { + return "create-recipe"; + } + + @GetMapping("/recipes/{id}") + public String viewRecipe(@PathVariable Integer id, Model model) { + RecipeDto recipe = recipeService.getRecipeById(id); + model.addAttribute("recipe", recipe); + return "view-recipe"; + } + + @GetMapping("/explore") + public String viewExplorePage(Model model) { + //model.addAttribute("allemplist", employeeServiceImpl.getAllEmployee()); + List recipes = recipeService.getAllRecipes(); + model.addAttribute("recipes", recipes); + return "explore"; + } + +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/controller/UserController.java b/src/main/java/com/example/demo/controller/UserController.java new file mode 100644 index 0000000..059a688 --- /dev/null +++ b/src/main/java/com/example/demo/controller/UserController.java @@ -0,0 +1,105 @@ +package com.example.demo.controller; + +import java.security.Principal; +import java.util.List; +import java.util.Optional; + +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.example.demo.dto.UserDto; +import com.example.demo.entity.User; +import com.example.demo.repository.UserRepo; +import com.example.demo.service.UserService; + +@RestController +@RequestMapping("/api/users") +public class UserController { + + private UserService userService; + private UserRepo userRepo; + + public UserController(UserService userService, UserRepo userRepo) { + super(); + this.userService = userService; + this.userRepo = userRepo; + } + + // build create user REST API + @PostMapping + public ResponseEntity saveUser(@RequestBody User user) { + + return new ResponseEntity(userService.saveUser(user), HttpStatus.CREATED); + } + + // build get all users REST API + @GetMapping + public List getAllUsers() { + return userService.getAllUsers(); + } + + // build get user by name REST API + @GetMapping("/search") + public ResponseEntity> getUsersByName(@RequestParam String name) { + List users = userService.getUsersByName(name); + return new ResponseEntity<>(users, HttpStatus.OK); + } + + // build get current user REST API + @GetMapping("/me") + public UserDto getLoggedInUser(Principal principal) { + if (principal == null) return null; + String username = principal.getName(); + User user = (userRepo.findByUsername(username)) + .orElse(null); + return userService.convertToDto(user); + } + + // build get user by id REST API + // http://localhost:8080/api/users/(id number goes here) + @GetMapping("{id}") + public ResponseEntity getUserById(@PathVariable("id") Integer userId) { + return new ResponseEntity(userService.getUserById(userId), HttpStatus.OK); + } + + // build create favorite REST API + @PostMapping("/{userId}/favorites/{recipeId}") + public ResponseEntity saveFavorite(@PathVariable Integer userId, @PathVariable Integer recipeId) { + + UserDto updatedUser = userService.saveFavorite(userId, recipeId); + + return new ResponseEntity<>(updatedUser, HttpStatus.OK); + } + + // build update user REST API + // http://localhost:8080/api/users/(id number goes here) + @PutMapping("{id}") + public ResponseEntity updateUser(@PathVariable("id") Integer userId, @RequestBody User user) { + return new ResponseEntity(userService.updateUser(user, userId), HttpStatus.OK); + } + + // build delete user REST API + @DeleteMapping("{id}") + public ResponseEntity deleteUser(@PathVariable("id") Integer userId) { + userService.deleteUser(userId); + return new ResponseEntity("User deleted succesfully!", HttpStatus.OK); + } + + // build delete favorite REST API + @DeleteMapping("/{userId}/favorites/{recipeId}") + public ResponseEntity deleteFavorite(@PathVariable Integer userId, @PathVariable Integer recipeId) { + + userService.deleteFavorite(userId, recipeId); + return new ResponseEntity("Favorite deleted succesfully!", HttpStatus.OK); + } + +} diff --git a/src/main/java/com/example/demo/dto/AuthResponse.java b/src/main/java/com/example/demo/dto/AuthResponse.java new file mode 100644 index 0000000..42f2539 --- /dev/null +++ b/src/main/java/com/example/demo/dto/AuthResponse.java @@ -0,0 +1,5 @@ +package com.example.demo.dto; + +public class AuthResponse { + +} diff --git a/src/main/java/com/example/demo/dto/ImageDto.java b/src/main/java/com/example/demo/dto/ImageDto.java new file mode 100644 index 0000000..42902d8 --- /dev/null +++ b/src/main/java/com/example/demo/dto/ImageDto.java @@ -0,0 +1,23 @@ +package com.example.demo.dto; + +public class ImageDto { + String imageUrl; + + public ImageDto() { + super(); + } + + public ImageDto(String imageUrl) { + super(); + this.imageUrl = imageUrl; + } + + public String getImageUrl() { + return imageUrl; + } + + public void setImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } + +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/dto/IngredientDto.java b/src/main/java/com/example/demo/dto/IngredientDto.java new file mode 100644 index 0000000..624e18d --- /dev/null +++ b/src/main/java/com/example/demo/dto/IngredientDto.java @@ -0,0 +1,26 @@ +package com.example.demo.dto; + +import java.math.BigDecimal; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.PositiveOrZero; + +public class IngredientDto { + + @NotBlank(message = "ingredientName is required") + private String ingredientName; + + @PositiveOrZero(message = "quantity must be 0 or greater") + private BigDecimal quantity; + + private String unit; + + public String getIngredientName() { return ingredientName; } + public void setIngredientName(String ingredientName) { this.ingredientName = ingredientName; } + + public @PositiveOrZero(message = "quantity must be 0 or greater") BigDecimal getQuantity() { return quantity; } + public void setQuantity(BigDecimal bigDecimal) { this.quantity = bigDecimal; } + + public String getUnit() { return unit; } + public void setUnit(String unit) { this.unit = unit; } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/dto/LoginRequest.java b/src/main/java/com/example/demo/dto/LoginRequest.java new file mode 100644 index 0000000..89d74f9 --- /dev/null +++ b/src/main/java/com/example/demo/dto/LoginRequest.java @@ -0,0 +1,5 @@ +package com.example.demo.dto; + +public class LoginRequest { + +} diff --git a/src/main/java/com/example/demo/dto/RecipeCreateRequest.java b/src/main/java/com/example/demo/dto/RecipeCreateRequest.java new file mode 100644 index 0000000..f45b179 --- /dev/null +++ b/src/main/java/com/example/demo/dto/RecipeCreateRequest.java @@ -0,0 +1,59 @@ +package com.example.demo.dto; + +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.PositiveOrZero; +import jakarta.validation.constraints.Size; + +import java.util.List; + +import com.example.demo.dto.StepDto; + +public class RecipeCreateRequest { + + @NotBlank(message = "title is required") + @Size(max = 100, message = "title must be 100 characters or less") + private String title; + + @Size(max = 1000, message = "description must be 1000 characters or less") + private String description; + + @PositiveOrZero(message = "prepTimeMinutes must be 0 or greater") + private int prepTimeMinutes; + + @PositiveOrZero(message = "cookTimeMinutes must be 0 or greater") + private int cookTimeMinutes; + + @PositiveOrZero(message = "servings must be 0 or greater") + private int servings; + + @NotNull(message = "ingredients list is required") + @Valid + private java.util.List ingredients; + + @NotNull(message = "steps list is required") + @Valid + private java.util.List steps; + + public String getTitle() { return title; } + public void setTitle(String title) { this.title = title; } + + public String getDescription() { return description; } + public void setDescription(String description) { this.description = description; } + + public int getPrepTimeMinutes() { return prepTimeMinutes; } + public void setPrepTimeMinutes(int prepTimeMinutes) { this.prepTimeMinutes = prepTimeMinutes; } + + public int getCookTimeMinutes() { return cookTimeMinutes; } + public void setCookTimeMinutes(int cookTimeMinutes) { this.cookTimeMinutes = cookTimeMinutes; } + + public int getServings() { return servings; } + public void setServings(int servings) { this.servings = servings; } + + public java.util.List getIngredients() { return ingredients; } + public void setIngredients(java.util.List ingredients) { this.ingredients = ingredients; } + + public java.util.List getSteps() { return steps; } + public void setSteps(java.util.List steps) { this.steps = steps; } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/dto/RecipeDto.java b/src/main/java/com/example/demo/dto/RecipeDto.java new file mode 100644 index 0000000..ff5cb80 --- /dev/null +++ b/src/main/java/com/example/demo/dto/RecipeDto.java @@ -0,0 +1,139 @@ +package com.example.demo.dto; + +import java.util.List; + +import com.example.demo.entity.Recipe; + +public class RecipeDto { + private String title; + private String description; + private Integer prepTimeMinutes; + private Integer cookTimeMinutes; + private Integer servings; + private UserDto userDto; + private String status; + private Integer id; + private List ingredients; + private List steps; + private List images; + private List tags; + + public RecipeDto() { + super(); + } + + public RecipeDto(String title, String description, Integer prepTimeMinutes, Integer cookTimeMinutes, + Integer servings, UserDto userDto, String status, List ingredients, + List steps, List images, List tags) { + super(); + this.title = title; + this.description = description; + this.prepTimeMinutes = prepTimeMinutes; + this.cookTimeMinutes = cookTimeMinutes; + this.servings = servings; + this.userDto = userDto; + this.status = status; + this.ingredients = ingredients; + this.steps = steps; + this.images = images; + this.tags = tags; + } + + // getters and setters + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Integer getPrepTimeMinutes() { + return prepTimeMinutes; + } + + public void setPrepTimeMinutes(Integer prepTimeMinutes) { + this.prepTimeMinutes = prepTimeMinutes; + } + + public Integer getCookTimeMinutes() { + return cookTimeMinutes; + } + + public void setCookTimeMinutes(Integer cookTimeMinutes) { + this.cookTimeMinutes = cookTimeMinutes; + } + + public Integer getServings() { + return servings; + } + + public void setServings(Integer servings) { + this.servings = servings; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public List getIngredients() { + return ingredients; + } + + public Integer getId() { + return id; + } + + public void setIngredients(List ingredients) { + this.ingredients = ingredients; + } + + public List getSteps() { + return steps; + } + + public void setSteps(List steps) { + this.steps = steps; + } + + public List getImages() { + return images; + } + + public void setImages(List images) { + this.images = images; + } + + public List getTags() { + return tags; + } + + public void setTags(List tags) { + this.tags = tags; + } + + public UserDto getUserDto() { + return userDto; + } + + public void setUserDto(UserDto userDto) { + this.userDto = userDto; + } + + public void setId(Integer id) { + this.id = id; + } +} diff --git a/src/main/java/com/example/demo/dto/RecipeIngredientDto.java b/src/main/java/com/example/demo/dto/RecipeIngredientDto.java new file mode 100644 index 0000000..f20e670 --- /dev/null +++ b/src/main/java/com/example/demo/dto/RecipeIngredientDto.java @@ -0,0 +1,56 @@ +package com.example.demo.dto; + +import java.math.BigDecimal; + +public class RecipeIngredientDto { + private String ingredientName; + private BigDecimal quantity; + private String unit; + private String notes; + + public RecipeIngredientDto() { + super(); + } + + public RecipeIngredientDto(String ingredientName, BigDecimal quantity, String unit, String notes) { + super(); + this.ingredientName = ingredientName; + this.quantity = quantity; + this.unit = unit; + this.notes = notes; + } + + // getters and setters + public String getIngredientName() { + return ingredientName; + } + + public void setIngredientName(String ingredientName) { + this.ingredientName = ingredientName; + } + + public BigDecimal getQuantity() { + return quantity; + } + + public void setQuantity(BigDecimal quantity) { + this.quantity = quantity; + } + + public String getUnit() { + return unit; + } + + public void setUnit(String unit) { + this.unit = unit; + } + + public String getNotes() { + return notes; + } + + public void setNotes(String notes) { + this.notes = notes; + } + +} diff --git a/src/main/java/com/example/demo/dto/RecipeResponse.java b/src/main/java/com/example/demo/dto/RecipeResponse.java new file mode 100644 index 0000000..659b213 --- /dev/null +++ b/src/main/java/com/example/demo/dto/RecipeResponse.java @@ -0,0 +1,53 @@ +package com.example.demo.dto; + +import java.time.LocalDateTime; +import java.util.List; + +import com.example.demo.dto.StepDto; + +public class RecipeResponse { + + private Long id; + private String title; + private String description; + + private int prepTimeMinutes; + private int cookTimeMinutes; + private int servings; + + private List ingredients; + private List steps; + + private LocalDateTime createdAt; + private LocalDateTime updatedAt; + + public Long getId() { return id; } + public void setId(Long id) { this.id = id; } + + public String getTitle() { return title; } + public void setTitle(String title) { this.title = title; } + + public String getDescription() { return description; } + public void setDescription(String description) { this.description = description; } + + public int getPrepTimeMinutes() { return prepTimeMinutes; } + public void setPrepTimeMinutes(int prepTimeMinutes) { this.prepTimeMinutes = prepTimeMinutes; } + + public int getCookTimeMinutes() { return cookTimeMinutes; } + public void setCookTimeMinutes(int cookTimeMinutes) { this.cookTimeMinutes = cookTimeMinutes; } + + public int getServings() { return servings; } + public void setServings(int servings) { this.servings = servings; } + + public List getIngredients() { return ingredients; } + public void setIngredients(List ingredients) { this.ingredients = ingredients; } + + public List getSteps() { return steps; } + public void setSteps(List steps) { this.steps = steps; } + + public LocalDateTime getCreatedAt() { return createdAt; } + public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; } + + public LocalDateTime getUpdatedAt() { return updatedAt; } + public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; } +} diff --git a/src/main/java/com/example/demo/dto/RecipeUpdateRequest.java b/src/main/java/com/example/demo/dto/RecipeUpdateRequest.java new file mode 100644 index 0000000..3482f03 --- /dev/null +++ b/src/main/java/com/example/demo/dto/RecipeUpdateRequest.java @@ -0,0 +1,59 @@ +package com.example.demo.dto; + +import jakarta.validation.Valid; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.PositiveOrZero; +import jakarta.validation.constraints.Size; + +import java.util.List; + +import com.example.demo.dto.StepDto; + +public class RecipeUpdateRequest { + + @NotBlank(message = "title is required") + @Size(max = 100, message = "title must be 100 characters or less") + private String title; + + @Size(max = 1000, message = "description must be 1000 characters or less") + private String description; + + @PositiveOrZero(message = "prepTimeMinutes must be 0 or greater") + private int prepTimeMinutes; + + @PositiveOrZero(message = "cookTimeMinutes must be 0 or greater") + private int cookTimeMinutes; + + @PositiveOrZero(message = "servings must be 0 or greater") + private int servings; + + @NotNull(message = "ingredients list is required") + @Valid + private List ingredients; + + @NotNull(message = "steps list is required") + @Valid + private List steps; + + public String getTitle() { return title; } + public void setTitle(String title) { this.title = title; } + + public String getDescription() { return description; } + public void setDescription(String description) { this.description = description; } + + public int getPrepTimeMinutes() { return prepTimeMinutes; } + public void setPrepTimeMinutes(int prepTimeMinutes) { this.prepTimeMinutes = prepTimeMinutes; } + + public int getCookTimeMinutes() { return cookTimeMinutes; } + public void setCookTimeMinutes(int cookTimeMinutes) { this.cookTimeMinutes = cookTimeMinutes; } + + public int getServings() { return servings; } + public void setServings(int servings) { this.servings = servings; } + + public List getIngredients() { return ingredients; } + public void setIngredients(List ingredients) { this.ingredients = ingredients; } + + public List getSteps() { return steps; } + public void setSteps(List steps) { this.steps = steps; } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/dto/RegisterRequest.java b/src/main/java/com/example/demo/dto/RegisterRequest.java new file mode 100644 index 0000000..3984882 --- /dev/null +++ b/src/main/java/com/example/demo/dto/RegisterRequest.java @@ -0,0 +1,5 @@ +package com.example.demo.dto; + +public class RegisterRequest { + +} diff --git a/src/main/java/com/example/demo/dto/StepDto.java b/src/main/java/com/example/demo/dto/StepDto.java new file mode 100644 index 0000000..47357bb --- /dev/null +++ b/src/main/java/com/example/demo/dto/StepDto.java @@ -0,0 +1,30 @@ +package com.example.demo.dto; + +public class StepDto { + private Integer stepNumber; + private String instruction; + + public StepDto() { + } + + public StepDto(Integer stepNumber, String instruction) { + this.stepNumber = stepNumber; + this.instruction = instruction; + } + + public Integer getStepNumber() { + return stepNumber; + } + + public void setStepNumber(Integer stepNumber) { + this.stepNumber = stepNumber; + } + + public String getInstruction() { + return instruction; + } + + public void setInstruction(String instruction) { + this.instruction = instruction; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/dto/TagDto.java b/src/main/java/com/example/demo/dto/TagDto.java new file mode 100644 index 0000000..9c90469 --- /dev/null +++ b/src/main/java/com/example/demo/dto/TagDto.java @@ -0,0 +1,22 @@ +package com.example.demo.dto; + +public class TagDto { + private String name; + + public TagDto() { + super(); + } + + public TagDto(String name) { + super(); + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/src/main/java/com/example/demo/dto/UserDto.java b/src/main/java/com/example/demo/dto/UserDto.java new file mode 100644 index 0000000..7b8a011 --- /dev/null +++ b/src/main/java/com/example/demo/dto/UserDto.java @@ -0,0 +1,41 @@ +package com.example.demo.dto; + +public class UserDto { + private Integer id; + private String username; + private String email; + + public UserDto() { + } + + public UserDto(Integer id, String username, String email) { + this.id = id; + this.username = username; + this.email = email; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + +} diff --git a/src/main/java/com/example/demo/entity/Favorite.java b/src/main/java/com/example/demo/entity/Favorite.java new file mode 100644 index 0000000..20e1e43 --- /dev/null +++ b/src/main/java/com/example/demo/entity/Favorite.java @@ -0,0 +1,29 @@ +package com.example.demo.entity; + +import jakarta.persistence.*; +import java.time.LocalDateTime; + +@Entity +@Table(name = "favorites") +public class Favorite { + + @EmbeddedId + private FavoriteId id; + + @Column(name = "created_at") + private LocalDateTime createdAt; + + public Favorite() {} + + public Favorite(Integer userId, Integer recipeId) { + this.id = new FavoriteId(userId, recipeId); + this.createdAt = LocalDateTime.now(); + } + + // Getters and setters + public FavoriteId getId() { return id; } + public void setId(FavoriteId id) { this.id = id; } + + public LocalDateTime getCreatedAt() { return createdAt; } + public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/entity/FavoriteId.java b/src/main/java/com/example/demo/entity/FavoriteId.java new file mode 100644 index 0000000..8b43d9d --- /dev/null +++ b/src/main/java/com/example/demo/entity/FavoriteId.java @@ -0,0 +1,42 @@ +package com.example.demo.entity; + +import jakarta.persistence.*; +import java.io.Serializable; +import java.util.Objects; + +@Embeddable +public class FavoriteId implements Serializable { + + private static final long serialVersionUID = 7241804509064720087L; + private Integer userId; + private Integer recipeId; + + public FavoriteId() {} + + public FavoriteId(Integer userId, Integer recipeId) { + this.userId = userId; + this.recipeId = recipeId; + } + + // Getters and setters + public Integer getUserId() { return userId; } + public void setUserId(Integer userId) { this.userId = userId; } + + public Integer getRecipeId() { return recipeId; } + public void setRecipeId(Integer recipeId) { this.recipeId = recipeId; } + + // equals and hashCode required for composite keys + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof FavoriteId)) return false; + FavoriteId that = (FavoriteId) o; + return Objects.equals(userId, that.userId) && + Objects.equals(recipeId, that.recipeId); + } + + @Override + public int hashCode() { + return Objects.hash(userId, recipeId); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/entity/Image.java b/src/main/java/com/example/demo/entity/Image.java new file mode 100644 index 0000000..e899a27 --- /dev/null +++ b/src/main/java/com/example/demo/entity/Image.java @@ -0,0 +1,68 @@ +package com.example.demo.entity; + +import jakarta.persistence.*; +import lombok.EqualsAndHashCode; + +import java.time.LocalDateTime; + +@Entity +@Table(name = "recipe_images") +public class Image { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "recipe_id", nullable = false) + @EqualsAndHashCode.Include + private Recipe recipe; + + @Column(name = "image_url", nullable = false) + private String imageUrl; + + @Column(name = "created_at") + private LocalDateTime createdAt; + + public Image() { + } + + public Image(Recipe recipe, String imageUrl) { + this.recipe = recipe; + this.imageUrl = imageUrl; + this.createdAt = LocalDateTime.now(); + } + + // Getters and setters + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Recipe getRecipe() { + return recipe; + } + + public void setRecipe(Recipe recipe) { + this.recipe = recipe; + } + + public String getImageUrl() { + return imageUrl; + } + + public void setImageUrl(String imageUrl) { + this.imageUrl = imageUrl; + } + + public LocalDateTime getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(LocalDateTime createdAt) { + this.createdAt = createdAt; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/entity/Ingredient.java b/src/main/java/com/example/demo/entity/Ingredient.java new file mode 100644 index 0000000..8666ba6 --- /dev/null +++ b/src/main/java/com/example/demo/entity/Ingredient.java @@ -0,0 +1,67 @@ +package com.example.demo.entity; + +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Table; +import jakarta.persistence.UniqueConstraint; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; +import jakarta.persistence.Id; +import jakarta.persistence.OneToMany; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; + +@Entity +@Table(name = "ingredients", uniqueConstraints = { @UniqueConstraint(columnNames = "name") }) +public class Ingredient { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @Column(nullable = false, unique = true,columnDefinition = "TEXT") + @NotBlank(message = "Please provide an ingredient name") + @Size(max = 128, message = "Name cannot be longer than 128 characters") + private String name; + + @OneToMany(mappedBy = "ingredient") + private Set recipeIngredients = new HashSet<>(); + + public Ingredient() { + } + + public Ingredient(String name) { + this.name = name; + } + + // Getters and setters + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Set getRecipeIngredients() { + return recipeIngredients; + } + + public void setRecipeIngredients(Set recipeIngredients) { + this.recipeIngredients = recipeIngredients; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/entity/Recipe.java b/src/main/java/com/example/demo/entity/Recipe.java new file mode 100644 index 0000000..616ed38 --- /dev/null +++ b/src/main/java/com/example/demo/entity/Recipe.java @@ -0,0 +1,211 @@ +package com.example.demo.entity; + +import jakarta.persistence.*; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Positive; +import lombok.EqualsAndHashCode; + +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.HashSet; +import java.util.Set; + +@Entity +@Table(name = "recipes") +public class Recipe { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @NotBlank(message = "Please provide a recipe title") + private String title; + + @Column(columnDefinition = "TEXT") + private String description; + + @NotNull(message = "Please Provide a prep time amount in mintutes") + @Positive(message = "This value cannot be negative") + private Integer prepTimeMinutes; + + @NotNull(message = "Please Provide a cook time amount in mintutes") + @Positive(message = "This value cannot be negative") + private Integer cookTimeMinutes; + + @NotNull(message = "Please Provide a serving amount") + @Positive(message = "This value cannot be negative") + private Integer servings; + + private String status; + + private LocalDateTime createdAt; + private LocalDateTime updatedAt; + + @NotNull(message = "Recipe must be associated with a user") + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false) + @EqualsAndHashCode.Include + private User user; + + // Recipe ingredients relationship + @OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) + @NotEmpty(message = "At least one ingredient is required") + private Set recipeIngredients = new HashSet<>(); + + // Recipe Steps relationship + @OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) + private Set steps = new HashSet<>(); + + // Recipe Images relationship + @OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) + private Set images = new HashSet<>(); + + // Recipe Tag relationship and also junction table + @ManyToMany(fetch = FetchType.LAZY) + @JoinTable(name = "recipe_tags", joinColumns = { @JoinColumn(name = "recipe_id") }, inverseJoinColumns = { + @JoinColumn(name = "tag_id") }) + private Set tags = new HashSet<>(); + + // User is the manager for this relationship + @ManyToMany(fetch = FetchType.LAZY, mappedBy = "FavRecipes") + private Set users = new HashSet<>(); + + public Recipe() { + } + + public Recipe(String title, String description, Integer prepTimeMinutes, Integer cookTimeMinutes, Integer servings, + User user, String status) { + this.title = title; + this.description = description; + this.prepTimeMinutes = prepTimeMinutes; + this.cookTimeMinutes = cookTimeMinutes; + this.servings = servings; + this.user = user; + this.status = status; + this.createdAt = LocalDateTime.now(); + this.updatedAt = LocalDateTime.now(); + } + + // Getters and setters + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Integer getPrepTimeMinutes() { + return prepTimeMinutes; + } + + public void setPrepTimeMinutes(Integer prepTimeMinutes) { + this.prepTimeMinutes = prepTimeMinutes; + } + + public Integer getCookTimeMinutes() { + return cookTimeMinutes; + } + + public void setCookTimeMinutes(Integer cookTimeMinutes) { + this.cookTimeMinutes = cookTimeMinutes; + } + + public Integer getServings() { + return servings; + } + + public void setServings(Integer servings) { + this.servings = servings; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public LocalDateTime getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(LocalDateTime createdAt) { + this.createdAt = createdAt; + } + + public LocalDateTime getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(LocalDateTime updatedAt) { + this.updatedAt = updatedAt; + } + + public Set getRecipeIngredients() { + return recipeIngredients; + } + + public void setRecipeIngredients(Set recipeIngredients) { + this.recipeIngredients = recipeIngredients; + } + + public Set getSteps() { + return steps; + } + + public void setSteps(Set steps) { + this.steps = steps; + } + + public Set getImages() { + return images; + } + + public void setImages(Set images) { + this.images = images; + } + + public Set getTags() { + return tags; + } + + public void setTags(Set tags) { + this.tags = tags; + } + + public Set getUsers() { + return users; + } + + public void setUsers(Set users) { + this.users = users; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/entity/RecipeIngredient.java b/src/main/java/com/example/demo/entity/RecipeIngredient.java new file mode 100644 index 0000000..6f6f98d --- /dev/null +++ b/src/main/java/com/example/demo/entity/RecipeIngredient.java @@ -0,0 +1,102 @@ +package com.example.demo.entity; + +import jakarta.persistence.*; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Positive; +import jakarta.validation.constraints.Size; + +import java.math.BigDecimal; +import lombok.EqualsAndHashCode; + +@Entity +@Table(name = "recipe_ingredient_junction", uniqueConstraints = { + @UniqueConstraint(columnNames = { "recipe_id", "ingredient_id" }) }) +@EqualsAndHashCode(onlyExplicitlyIncluded = true) +public class RecipeIngredient { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "recipe_id", nullable = false) + @EqualsAndHashCode.Include + private Recipe recipe; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "ingredient_id", nullable = false) + @EqualsAndHashCode.Include + private Ingredient ingredient; + + @NotNull(message = "Please Provide a Quantity") + @Positive(message = "Quantity cannot be negative") + private BigDecimal quantity; + + @Column(columnDefinition = "TEXT") + @Size(max = 32, message = "Unit cannot be longer than 32 characters") + private String unit; + + @Column(columnDefinition = "TEXT") + @Size(max = 128, message = "Note cannot be longer than 128 characters") + private String notes; + + public RecipeIngredient() { + } + + public RecipeIngredient(Recipe recipe, Ingredient ingredient, BigDecimal quantity, String unit, String notes) { + this.recipe = recipe; + this.ingredient = ingredient; + this.quantity = quantity; + this.unit = unit; + this.notes = notes; + } + + // Getters and setters + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Recipe getRecipe() { + return recipe; + } + + public void setRecipe(Recipe recipe) { + this.recipe = recipe; + } + + public Ingredient getIngredient() { + return ingredient; + } + + public void setIngredient(Ingredient ingredient) { + this.ingredient = ingredient; + } + + public BigDecimal getQuantity() { + return quantity; + } + + public void setQuantity(BigDecimal quantity) { + this.quantity = quantity; + } + + public String getUnit() { + return unit; + } + + public void setUnit(String unit) { + this.unit = unit; + } + + public String getNotes() { + return notes; + } + + public void setNotes(String notes) { + this.notes = notes; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/entity/RecipeTag.java b/src/main/java/com/example/demo/entity/RecipeTag.java new file mode 100644 index 0000000..02573a0 --- /dev/null +++ b/src/main/java/com/example/demo/entity/RecipeTag.java @@ -0,0 +1,53 @@ +package com.example.demo.entity; + +import jakarta.persistence.*; + +@Entity +@Table(name = "recipe_tags") +public class RecipeTag { + + @EmbeddedId + private RecipeTagId id; + + @ManyToOne + @MapsId("recipeId") + @JoinColumn(name = "recipe_id", nullable = false) + private Recipe recipe; + + @ManyToOne + @MapsId("tagId") + @JoinColumn(name = "tag_id", nullable = false) + private Tag tag; + + public RecipeTag() {} + + public RecipeTag(Recipe recipe, Tag tag) { + this.recipe = recipe; + this.tag = tag; + this.id = new RecipeTagId(recipe.getId(), tag.getId()); + } + + public RecipeTagId getId() { + return id; + } + + public void setId(RecipeTagId id) { + this.id = id; + } + + public Recipe getRecipe() { + return recipe; + } + + public Tag getTag() { + return tag; + } + + public void setRecipe(Recipe recipe) { + this.recipe = recipe; + } + + public void setTag(Tag tag) { + this.tag = tag; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/entity/RecipeTagId.java b/src/main/java/com/example/demo/entity/RecipeTagId.java new file mode 100644 index 0000000..d0890bf --- /dev/null +++ b/src/main/java/com/example/demo/entity/RecipeTagId.java @@ -0,0 +1,57 @@ +package com.example.demo.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Embeddable; +import java.io.Serializable; +import java.util.Objects; + +@Embeddable +public class RecipeTagId implements Serializable { + + private static final long serialVersionUID = 5272431101708393749L; + + @Column(name = "recipe_id") + private Integer recipeId; + + @Column(name = "tag_id") + private Integer tagId; + + public RecipeTagId() { + } + + public RecipeTagId(Integer recipeId, Integer tagId) { + this.recipeId = recipeId; + this.tagId = tagId; + } + + public Integer getRecipeId() { + return recipeId; + } + + public void setRecipeId(Integer recipeId) { + this.recipeId = recipeId; + } + + public Integer getTagId() { + return tagId; + } + + public void setTagId(Integer tagId) { + this.tagId = tagId; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (!(o instanceof RecipeTagId)) + return false; + RecipeTagId that = (RecipeTagId) o; + return Objects.equals(recipeId, that.recipeId) && Objects.equals(tagId, that.tagId); + } + + @Override + public int hashCode() { + return Objects.hash(recipeId, tagId); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/entity/Step.java b/src/main/java/com/example/demo/entity/Step.java new file mode 100644 index 0000000..14b4cd1 --- /dev/null +++ b/src/main/java/com/example/demo/entity/Step.java @@ -0,0 +1,68 @@ +package com.example.demo.entity; + +import jakarta.persistence.*; +import jakarta.validation.constraints.Size; +import lombok.EqualsAndHashCode; + +@Entity +@Table(name = "steps") +public class Step { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @Column(name = "step_number", nullable = false) + private Integer stepNumber; + + @Column(name = "instruction", nullable = false, columnDefinition = "TEXT") + @Size(max = 500, message = "Instruction cannot be longer than 500 characters") + private String instruction; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "recipe_id", nullable = false) + @EqualsAndHashCode.Include + private Recipe recipe; + + public Step() { + } + + public Step(Recipe recipe, Integer stepNumber, String instruction) { + this.recipe = recipe; + this.stepNumber = stepNumber; + this.instruction = instruction; + } + + // Getters and setters + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Recipe getRecipe() { + return recipe; + } + + public void setRecipe(Recipe recipe) { + this.recipe = recipe; + } + + public Integer getStepNumber() { + return stepNumber; + } + + public void setStepNumber(Integer stepNumber) { + this.stepNumber = stepNumber; + } + + public String getInstruction() { + return instruction; + } + + public void setInstruction(String instruction) { + this.instruction = instruction; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/entity/Tag.java b/src/main/java/com/example/demo/entity/Tag.java new file mode 100644 index 0000000..987771c --- /dev/null +++ b/src/main/java/com/example/demo/entity/Tag.java @@ -0,0 +1,55 @@ +package com.example.demo.entity; + +import java.util.HashSet; +import java.util.Set; + +import jakarta.persistence.*; + +@Entity +@Table(name = "tags") +public class Tag { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @Column(nullable = false, unique = true) + private String name; + + // Recipe is the manager for this relationship + @ManyToMany(fetch = FetchType.LAZY, mappedBy = "tags") + private Set recipes = new HashSet<>(); + + public Tag() { + } + + public Tag(String name) { + this.name = name; + } + + // Getters and setters + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Set getRecipes() { + return recipes; + } + + public void setRecipes(Set recipes) { + this.recipes = recipes; + } + +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/entity/User.java b/src/main/java/com/example/demo/entity/User.java new file mode 100644 index 0000000..f7b0a1d --- /dev/null +++ b/src/main/java/com/example/demo/entity/User.java @@ -0,0 +1,176 @@ +package com.example.demo.entity; + +import jakarta.persistence.CascadeType; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.JoinTable; +import jakarta.persistence.ManyToMany; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; + +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; + +import java.time.LocalDateTime; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +@Entity +@Table(name = "users") +public class User implements UserDetails { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @Column(nullable = false, unique = true) + private String username; + + @Column(nullable = false) + private String role; + + @Column(unique = true) + private String email; + + private String hashedpassword; + + @Column(name = "created_at") + private LocalDateTime createdAt; + + @Column(nullable = false) + private boolean banned = false; + + @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) + private Set recipes = new HashSet<>(); + + @ManyToMany(fetch = FetchType.LAZY) + @JoinTable( + name = "favorites", + joinColumns = { @JoinColumn(name = "userId") }, + inverseJoinColumns = { @JoinColumn(name = "recipeId") } + ) + private Set FavRecipes = new HashSet<>(); + + @Override + public Collection getAuthorities() { + return List.of(new SimpleGrantedAuthority(role)); + } + + @Override + public String getPassword() { + return hashedpassword; + } + + @Override + public String getUsername() { + return username; + } + + @Override + public boolean isAccountNonExpired() { + return true; + } + + @Override + public boolean isAccountNonLocked() { + return !banned; + } + + @Override + public boolean isCredentialsNonExpired() { + return true; + } + + @Override + public boolean isEnabled() { + return !banned; + } + + public User() { + } + + public User(String username, String role, String email, String hashedpassword, LocalDateTime createdAt) { + this.username = username; + this.role = role; + this.email = email; + this.hashedpassword = hashedpassword; + this.createdAt = createdAt; + this.banned = false; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getRole() { + return role; + } + + public void setRole(String role) { + this.role = role; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getHashedpassword() { + return hashedpassword; + } + + public void setHashedpassword(String hashedpassword) { + this.hashedpassword = hashedpassword; + } + + public LocalDateTime getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(LocalDateTime createdAt) { + this.createdAt = createdAt; + } + + public boolean isBanned() { + return banned; + } + + public void setBanned(boolean banned) { + this.banned = banned; + } + + public Set getRecipes() { + return recipes; + } + + public void setRecipes(Set recipes) { + this.recipes = recipes; + } + + public Set getFavRecipes() { + return FavRecipes; + } + + public void setFavRecipes(Set favRecipes) { + this.FavRecipes = favRecipes; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/exception/BadRequestException.java b/src/main/java/com/example/demo/exception/BadRequestException.java new file mode 100644 index 0000000..f96064c --- /dev/null +++ b/src/main/java/com/example/demo/exception/BadRequestException.java @@ -0,0 +1,5 @@ +package com.example.demo.exception; + +public class BadRequestException { + +} diff --git a/src/main/java/com/example/demo/exception/ErrorResponse.java b/src/main/java/com/example/demo/exception/ErrorResponse.java new file mode 100644 index 0000000..de0fe3a --- /dev/null +++ b/src/main/java/com/example/demo/exception/ErrorResponse.java @@ -0,0 +1,5 @@ +package com.example.demo.exception; + +public class ErrorResponse { + +} diff --git a/src/main/java/com/example/demo/exception/GlobalExceptionHandler.java b/src/main/java/com/example/demo/exception/GlobalExceptionHandler.java new file mode 100644 index 0000000..444e0cd --- /dev/null +++ b/src/main/java/com/example/demo/exception/GlobalExceptionHandler.java @@ -0,0 +1,5 @@ +package com.example.demo.exception; + +public class GlobalExceptionHandler { + +} diff --git a/src/main/java/com/example/demo/exception/NotFoundException.java b/src/main/java/com/example/demo/exception/NotFoundException.java new file mode 100644 index 0000000..66b3240 --- /dev/null +++ b/src/main/java/com/example/demo/exception/NotFoundException.java @@ -0,0 +1,32 @@ +package com.example.demo.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(value = HttpStatus.NOT_FOUND) +public class NotFoundException extends RuntimeException { + + private static final long serialVersionUID = 1l; + private String resourceName; + private String fieldName; + private Object fieldValue; + + public NotFoundException(String resourceName, String fieldName, Object fieldValue) { + super(String.format("%s not found with %s : %s", resourceName, fieldName, fieldValue)); + this.resourceName = resourceName; + this.fieldName = fieldName; + this.fieldValue = fieldValue; + } + + public String getResourceName() { + return resourceName; + } + + public String getFieldName() { + return fieldName; + } + + public Object getFieldValue() { + return fieldValue; + } +} diff --git a/src/main/java/com/example/demo/repository/FavoriteRepo.java b/src/main/java/com/example/demo/repository/FavoriteRepo.java new file mode 100644 index 0000000..678c97b --- /dev/null +++ b/src/main/java/com/example/demo/repository/FavoriteRepo.java @@ -0,0 +1,11 @@ +package com.example.demo.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import com.example.demo.entity.Favorite; +import com.example.demo.entity.FavoriteId; + +import java.util.List; + +public interface FavoriteRepo extends JpaRepository { + +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/repository/ImageRepo.java b/src/main/java/com/example/demo/repository/ImageRepo.java new file mode 100644 index 0000000..0e36e6e --- /dev/null +++ b/src/main/java/com/example/demo/repository/ImageRepo.java @@ -0,0 +1,10 @@ +package com.example.demo.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import com.example.demo.entity.Image; + +import java.util.List; + +public interface ImageRepo extends JpaRepository { + +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/repository/IngredientRepo.java b/src/main/java/com/example/demo/repository/IngredientRepo.java new file mode 100644 index 0000000..0420f12 --- /dev/null +++ b/src/main/java/com/example/demo/repository/IngredientRepo.java @@ -0,0 +1,10 @@ +package com.example.demo.repository; + +import java.util.Optional; + +import org.springframework.data.jpa.repository.JpaRepository; +import com.example.demo.entity.Ingredient; + +public interface IngredientRepo extends JpaRepository { + Optional findByNameIgnoreCase(String name); +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/repository/RecipeIngredientRepo.java b/src/main/java/com/example/demo/repository/RecipeIngredientRepo.java new file mode 100644 index 0000000..db21dd6 --- /dev/null +++ b/src/main/java/com/example/demo/repository/RecipeIngredientRepo.java @@ -0,0 +1,14 @@ +package com.example.demo.repository; + +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.example.demo.entity.Recipe; +import com.example.demo.entity.RecipeIngredient; + +public interface RecipeIngredientRepo extends JpaRepository { + // Custom query: find all ingredients for a recipe + List findByRecipeId(Integer recipeId); + void deleteByRecipe(Recipe recipe); +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/repository/RecipeRepo.java b/src/main/java/com/example/demo/repository/RecipeRepo.java new file mode 100644 index 0000000..979fe65 --- /dev/null +++ b/src/main/java/com/example/demo/repository/RecipeRepo.java @@ -0,0 +1,18 @@ +package com.example.demo.repository; + +import java.time.LocalDateTime; +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; +import com.example.demo.entity.Recipe; + +public interface RecipeRepo extends JpaRepository { + + List findByTitleContainingIgnoreCase(String name); + List findByTitleContainingIgnoreCaseAndTags_NameIn(String title, List tags); + + long countByUserIdAndCreatedAtAfter(Integer userId, LocalDateTime after); + + List findByUserId(Integer userId); + +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/repository/RecipeTagRepo.java b/src/main/java/com/example/demo/repository/RecipeTagRepo.java new file mode 100644 index 0000000..841230f --- /dev/null +++ b/src/main/java/com/example/demo/repository/RecipeTagRepo.java @@ -0,0 +1,11 @@ +package com.example.demo.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import com.example.demo.entity.RecipeTag; +import com.example.demo.entity.RecipeTagId; + +import java.util.List; + +public interface RecipeTagRepo extends JpaRepository { + +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/repository/StepRepo.java b/src/main/java/com/example/demo/repository/StepRepo.java new file mode 100644 index 0000000..7bc8ee4 --- /dev/null +++ b/src/main/java/com/example/demo/repository/StepRepo.java @@ -0,0 +1,11 @@ +package com.example.demo.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.example.demo.entity.Step; + +import java.util.List; + +public interface StepRepo extends JpaRepository { + +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/repository/TagRepo.java b/src/main/java/com/example/demo/repository/TagRepo.java new file mode 100644 index 0000000..647482b --- /dev/null +++ b/src/main/java/com/example/demo/repository/TagRepo.java @@ -0,0 +1,12 @@ +package com.example.demo.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.example.demo.entity.Ingredient; +import com.example.demo.entity.Tag; + +import java.util.Optional; + +public interface TagRepo extends JpaRepository { + Optional findByName(String name); +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/repository/UserRepo.java b/src/main/java/com/example/demo/repository/UserRepo.java new file mode 100644 index 0000000..669a759 --- /dev/null +++ b/src/main/java/com/example/demo/repository/UserRepo.java @@ -0,0 +1,16 @@ +package com.example.demo.repository; + +import org.springframework.data.jpa.repository.JpaRepository; + +import com.example.demo.entity.User; + +import java.util.List; +import java.util.Optional; + +public interface UserRepo extends JpaRepository { + + Optional findByUsername(String username); + + List findByUsernameContainingIgnoreCase(String name); + +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/service/AuthService.java b/src/main/java/com/example/demo/service/AuthService.java new file mode 100644 index 0000000..894c90e --- /dev/null +++ b/src/main/java/com/example/demo/service/AuthService.java @@ -0,0 +1,5 @@ +package com.example.demo.service; + +public class AuthService { + +} diff --git a/src/main/java/com/example/demo/service/CustomUserDetailsService.java b/src/main/java/com/example/demo/service/CustomUserDetailsService.java new file mode 100644 index 0000000..6ad9739 --- /dev/null +++ b/src/main/java/com/example/demo/service/CustomUserDetailsService.java @@ -0,0 +1,24 @@ +package com.example.demo.service; + +import com.example.demo.repository.UserRepo; +import org.jspecify.annotations.NonNull; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.stereotype.Service; + +@Service +public class CustomUserDetailsService implements UserDetailsService { + + private final UserRepo userRepo; + + public CustomUserDetailsService(UserRepo userRepo) { + this.userRepo = userRepo; + } + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + return userRepo.findByUsername(username) + .orElseThrow(() -> new UsernameNotFoundException("User not found: " + username)); + } +} diff --git a/src/main/java/com/example/demo/service/Impl/RecipeServiceImpl.java b/src/main/java/com/example/demo/service/Impl/RecipeServiceImpl.java new file mode 100644 index 0000000..da898cb --- /dev/null +++ b/src/main/java/com/example/demo/service/Impl/RecipeServiceImpl.java @@ -0,0 +1,399 @@ +package com.example.demo.service.Impl; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import org.springframework.security.access.AccessDeniedException; +import org.springframework.stereotype.Service; + +import com.example.demo.dto.RecipeDto; +import com.example.demo.dto.UserDto; +import com.example.demo.dto.StepDto; +import com.example.demo.dto.TagDto; +import com.example.demo.dto.ImageDto; +import com.example.demo.dto.RecipeIngredientDto; +import com.example.demo.entity.Image; +import com.example.demo.entity.Ingredient; +import com.example.demo.entity.Recipe; +import com.example.demo.entity.RecipeIngredient; +import com.example.demo.entity.Step; +import com.example.demo.entity.Tag; +import com.example.demo.entity.User; +import com.example.demo.exception.NotFoundException; +import com.example.demo.repository.ImageRepo; +import com.example.demo.repository.IngredientRepo; +import com.example.demo.repository.RecipeIngredientRepo; +import com.example.demo.repository.RecipeRepo; +import com.example.demo.repository.StepRepo; +import com.example.demo.repository.TagRepo; +import com.example.demo.repository.UserRepo; +import com.example.demo.service.RecipeService; + +import jakarta.transaction.Transactional; + +@Service +public class RecipeServiceImpl implements RecipeService { + + private RecipeRepo recipeRepository; + private IngredientRepo ingredientRepository; + private RecipeIngredientRepo recipeIngredientRepository; + private UserRepo userRepository; + private StepRepo stepRepository; + private ImageRepo imageRepository; + private TagRepo tagRepository; + + public RecipeServiceImpl(RecipeRepo recipeRepository, IngredientRepo ingredientRepository, + RecipeIngredientRepo recipeIngredientRepository, UserRepo userRepository, StepRepo stepRepository, + ImageRepo imageRepository, TagRepo tagRepository) { + super(); + this.recipeRepository = recipeRepository; + this.ingredientRepository = ingredientRepository; + this.recipeIngredientRepository = recipeIngredientRepository; + this.userRepository = userRepository; + this.stepRepository = stepRepository; + this.imageRepository = imageRepository; + this.tagRepository = tagRepository; + } + + @Override + public RecipeDto convertToDto(Recipe recipe) { + List ingredientDtos = recipe.getRecipeIngredients().stream() + .map(ri -> new RecipeIngredientDto(ri.getIngredient().getName(), ri.getQuantity(), ri.getUnit(), + ri.getNotes())) + .toList(); + + List stepDtos = recipe.getSteps().stream() + .map(ri -> new StepDto(ri.getStepNumber(), ri.getInstruction())).toList(); + + List imageDtos = recipe.getImages().stream().map(ri -> new ImageDto(ri.getImageUrl())).toList(); + + List tagDtos = recipe.getTags().stream().map(ri -> new TagDto(ri.getName())).toList(); + + UserDto userDto = new UserDto(recipe.getUser().getId(), recipe.getUser().getUsername(), + recipe.getUser().getEmail()); + + RecipeDto dto = new RecipeDto(recipe.getTitle(), recipe.getDescription(), recipe.getPrepTimeMinutes(), + recipe.getCookTimeMinutes(), recipe.getServings(), userDto, recipe.getStatus(), ingredientDtos, + stepDtos, imageDtos, tagDtos); + + dto.setId(recipe.getId()); + + return dto; + } + + private User getCurrentUser(String currentUsername) { + return userRepository.findByUsername(currentUsername) + .orElseThrow(() -> new NotFoundException("User", "username", currentUsername)); + } + + private boolean isAdmin(User user) { + return "ROLE_ADMIN".equals(user.getRole()); + } + + private void ensureUserNotBanned(User user) { + if (user.isBanned()) { + throw new AccessDeniedException("Banned users cannot perform this action."); + } + } + + private void enforceUploadLimit(User user) { + if (isAdmin(user)) { + return; + } + + LocalDateTime cutoff = LocalDateTime.now().minusHours(24); + long uploadsInLast24Hours = recipeRepository.countByUserIdAndCreatedAtAfter(user.getId(), cutoff); + + if (uploadsInLast24Hours >= 10) { + throw new AccessDeniedException("Upload limit reached. Maximum is 10 recipes per 24 hours."); + } + } + + private void enforceOwnerOrAdmin(User currentUser, Recipe recipe) { + if (isAdmin(currentUser)) { + return; + } + + if (!recipe.getUser().getId().equals(currentUser.getId())) { + throw new AccessDeniedException("You do not have permission to modify this recipe."); + } + } + + @Override + @Transactional + public RecipeDto saveRecipe(RecipeDto dto, String currentUsername) { + + User currentUser = getCurrentUser(currentUsername); + ensureUserNotBanned(currentUser); + enforceUploadLimit(currentUser); + + Recipe recipe = new Recipe(dto.getTitle(), dto.getDescription(), dto.getPrepTimeMinutes(), + dto.getCookTimeMinutes(), dto.getServings(), currentUser, dto.getStatus()); + + if (dto.getIngredients() != null) { + for (RecipeIngredientDto riDto : dto.getIngredients()) { + + Ingredient ingredient = ingredientRepository.findByNameIgnoreCase(riDto.getIngredientName()) + .orElseGet(() -> new Ingredient(riDto.getIngredientName())); + + if (ingredient.getId() == null) { + ingredientRepository.save(ingredient); + } + + RecipeIngredient ri = new RecipeIngredient(recipe, ingredient, riDto.getQuantity(), riDto.getUnit(), + riDto.getNotes()); + + recipe.getRecipeIngredients().add(ri); + } + } + + if (dto.getSteps() != null) { + for (StepDto stepDto : dto.getSteps()) { + Step step = new Step(recipe, stepDto.getStepNumber(), stepDto.getInstruction()); + recipe.getSteps().add(step); + } + } + + if (dto.getImages() != null) { + for (ImageDto imageDto : dto.getImages()) { + Image image = new Image(recipe, imageDto.getImageUrl()); + recipe.getImages().add(image); + } + } + + if (dto.getTags() != null) { + for (TagDto tDto : dto.getTags()) { + + Tag tag = tagRepository.findByName(tDto.getName()).orElseGet(() -> new Tag(tDto.getName())); + + if (tag.getId() == null) { + tagRepository.save(tag); + } + recipe.getTags().add(tag); + } + } + + Recipe saved = recipeRepository.save(recipe); + + return getRecipeById(saved.getId()); + } + + @Override + @Transactional + public List getAllRecipes() { + + List list = new ArrayList<>(); + for (Recipe recipe : recipeRepository.findAll()) { + RecipeDto recipeDto = convertToDto(recipe); + list.add(recipeDto); + } + + return list; + } + + @Override + @Transactional + public RecipeDto getRecipeById(Integer Id) { + return convertToDto(recipeRepository.findById(Id).orElseThrow(() -> new NotFoundException("Recipe", "id", Id))); + } + + @Override + @Transactional + public RecipeDto updateRecipe(RecipeDto recipeDto, Integer id, String currentUsername) { + User currentUser = getCurrentUser(currentUsername); + ensureUserNotBanned(currentUser); + + Recipe existingRecipe = recipeRepository.findById(id) + .orElseThrow(() -> new NotFoundException("Recipe", "id", id)); + + enforceOwnerOrAdmin(currentUser, existingRecipe); + + existingRecipe.setTitle(recipeDto.getTitle()); + existingRecipe.setDescription(recipeDto.getDescription()); + existingRecipe.setPrepTimeMinutes(recipeDto.getPrepTimeMinutes()); + existingRecipe.setCookTimeMinutes(recipeDto.getCookTimeMinutes()); + existingRecipe.setServings(recipeDto.getServings()); + existingRecipe.setStatus(recipeDto.getStatus()); + + List updatedIngredients = recipeDto.getIngredients(); + List ingredientsToRemove = new ArrayList<>(); + + List updatedSteps = recipeDto.getSteps(); + List stepsToRemove = new ArrayList<>(); + + List updatedImages = recipeDto.getImages(); + List imagesToRemove = new ArrayList<>(); + + List updatedTags = recipeDto.getTags(); + List tagsToRemove = new ArrayList<>(); + + for (RecipeIngredient ri : existingRecipe.getRecipeIngredients()) { + + boolean existsInUpdatedList = false; + for (RecipeIngredientDto dto : updatedIngredients) { + String updatedName = dto.getIngredientName(); + String existingName = ri.getIngredient().getName(); + + if (updatedName.equals(existingName)) { + existsInUpdatedList = true; + break; + } + } + + if (!existsInUpdatedList) { + ingredientsToRemove.add(ri); + } + } + + existingRecipe.getRecipeIngredients().removeAll(ingredientsToRemove); + + for (RecipeIngredientDto riDto : updatedIngredients) { + + RecipeIngredient existingRI = existingRecipe.getRecipeIngredients().stream() + .filter(ri -> ri.getIngredient().getName().equals(riDto.getIngredientName())).findFirst() + .orElse(null); + + if (existingRI != null) { + + existingRI.setQuantity(riDto.getQuantity()); + existingRI.setUnit(riDto.getUnit()); + existingRI.setNotes(riDto.getNotes()); + } + + else { + + Ingredient ingredient = ingredientRepository.findByNameIgnoreCase(riDto.getIngredientName()) + .orElseGet(() -> new Ingredient(riDto.getIngredientName())); + + if (ingredient.getId() == null) { + ingredientRepository.save(ingredient); + } + + RecipeIngredient newRI = new RecipeIngredient(existingRecipe, ingredient, riDto.getQuantity(), + riDto.getUnit(), riDto.getNotes()); + + existingRecipe.getRecipeIngredients().add(newRI); + } + } + + if (updatedSteps != null) { + for (Step step : existingRecipe.getSteps()) { + boolean existsInUpdatedList = updatedSteps.stream() + .anyMatch(dto -> dto.getStepNumber().equals(step.getStepNumber())); + + if (!existsInUpdatedList) + stepsToRemove.add(step); + } + existingRecipe.getSteps().removeAll(stepsToRemove); + + for (StepDto stepDto : updatedSteps) { + + Step existingStep = existingRecipe.getSteps().stream() + .filter(s -> s.getStepNumber().equals(stepDto.getStepNumber())).findFirst().orElse(null); + + if (existingStep != null) { + existingStep.setInstruction(stepDto.getInstruction()); + } + + else { + Step newStep = new Step(existingRecipe, stepDto.getStepNumber(), stepDto.getInstruction()); + existingRecipe.getSteps().add(newStep); + } + } + } + + if (updatedImages != null) { + for (Image image : existingRecipe.getImages()) { + boolean existsInUpdatedList = updatedImages.stream() + .anyMatch(dto -> dto.getImageUrl().equals(image.getImageUrl())); + if (!existsInUpdatedList) + imagesToRemove.add(image); + } + + existingRecipe.getImages().removeAll(imagesToRemove); + + for (ImageDto imageDto : updatedImages) { + Image existingImage = existingRecipe.getImages().stream() + .filter(img -> img.getImageUrl().equals(imageDto.getImageUrl())).findFirst().orElse(null); + + if (existingImage != null) { + existingImage.setImageUrl(imageDto.getImageUrl()); + } else { + Image newImage = new Image(existingRecipe, imageDto.getImageUrl()); + existingRecipe.getImages().add(newImage); + } + } + } + + if (updatedTags != null) { + for (Tag tag : existingRecipe.getTags()) { + boolean existsInUpdatedList = updatedTags.stream().anyMatch(dto -> dto.getName().equals(tag.getName())); + if (!existsInUpdatedList) + tagsToRemove.add(tag); + } + + existingRecipe.getTags().removeAll(tagsToRemove); + + for (TagDto tagDto : updatedTags) { + Tag existingTag = existingRecipe.getTags().stream() + .filter(tag -> tag.getName().equals(tagDto.getName())).findFirst().orElse(null); + + if (existingTag != null) { + existingTag.setName(tagDto.getName()); + } else { + Tag newTag = tagRepository.findByName(tagDto.getName()) + .orElseGet(() -> tagRepository.save(new Tag(tagDto.getName()))); + + existingRecipe.getTags().add(newTag); + } + } + } + recipeRepository.save(existingRecipe); + return convertToDto(existingRecipe); + } + + @Override + @Transactional + public void deleteRecipe(Integer id, String currentUsername) { + User currentUser = getCurrentUser(currentUsername); + ensureUserNotBanned(currentUser); + + Recipe recipe = recipeRepository.findById(id) + .orElseThrow(() -> new NotFoundException("Recipe", "id", id)); + + enforceOwnerOrAdmin(currentUser, recipe); + recipeRepository.delete(recipe); + } + + @Override + @Transactional + public List getRecipes(String name, List tags) { + + List recipes; + + if (!name.isBlank()) { + recipes = recipeRepository.findByTitleContainingIgnoreCase(name); + } + + else { + recipes = recipeRepository.findAll(); + } + + if (!tags.isEmpty() && !recipes.isEmpty()) { + recipes = recipes.stream() + .filter(recipe -> recipe.getTags().stream().anyMatch(tag -> tags.contains(tag.getName()))) + .collect(Collectors.toList()); + } + + List recipeList = new ArrayList<>(); + + for (Recipe recipe : recipes) { + RecipeDto dto = convertToDto(recipe); + recipeList.add(dto); + } + + return recipeList; + } +} \ No newline at end of file diff --git a/src/main/java/com/example/demo/service/Impl/UserServiceImpl.java b/src/main/java/com/example/demo/service/Impl/UserServiceImpl.java new file mode 100644 index 0000000..dd29369 --- /dev/null +++ b/src/main/java/com/example/demo/service/Impl/UserServiceImpl.java @@ -0,0 +1,167 @@ +package com.example.demo.service.Impl; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.springframework.stereotype.Service; + +import com.example.demo.dto.ImageDto; +import com.example.demo.dto.RecipeDto; +import com.example.demo.dto.RecipeIngredientDto; +import com.example.demo.dto.StepDto; +import com.example.demo.dto.TagDto; +import com.example.demo.dto.UserDto; +import com.example.demo.entity.Recipe; +import com.example.demo.entity.User; +import com.example.demo.exception.NotFoundException; +import com.example.demo.repository.RecipeRepo; +import com.example.demo.repository.UserRepo; +import com.example.demo.service.UserService; + +import jakarta.transaction.Transactional; + +@Service +public class UserServiceImpl implements UserService { + + private UserRepo userRepository; + private RecipeRepo recipeRepository; + + public UserServiceImpl(UserRepo userRepository, RecipeRepo recipeRepository) { + super(); + this.userRepository = userRepository; + this.recipeRepository = recipeRepository; + } + + public UserDto convertToDto(User user) { + return new UserDto(user.getId(), user.getUsername(), user.getEmail()); + } + + @Override + public User saveUser(User user) { + if (user.getRole() == null || user.getRole().isBlank()) { + user.setRole("ROLE_USER"); + } + user.setBanned(false); + return userRepository.save(user); + } + + @Override + public List getAllUsers() { + + List list = new ArrayList<>(); + for (User user : userRepository.findAll()) { + UserDto userDto = convertToDto(user); + list.add(userDto); + } + + return list; + } + + @Override + public UserDto getUserById(Integer Id) { + + return convertToDto(userRepository.findById(Id).orElseThrow(() -> new NotFoundException("User", "id", Id))); + } + + @Override + @Transactional + public UserDto saveFavorite(Integer userId, Integer recipeId) { + User existingUser = userRepository.findById(userId) + .orElseThrow(() -> new NotFoundException("User", "id", userId)); + + Recipe existingRecipe = recipeRepository.findById(recipeId) + .orElseThrow(() -> new NotFoundException("Recipe", "id", recipeId)); + + existingUser.getFavRecipes().add(existingRecipe); + userRepository.save(existingUser); + + return convertToDto(existingUser); + } + + @Override + public UserDto updateUser(User user, Integer Id) { + + User existingUser = userRepository.findById(Id).orElseThrow(() -> new NotFoundException("User", "id", Id)); + + existingUser.setUsername(user.getUsername()); + existingUser.setEmail(user.getEmail()); + + userRepository.save(existingUser); + + return convertToDto(existingUser); + } + + @Override + public void deleteUser(Integer Id) { + userRepository.findById(Id).orElseThrow(() -> new NotFoundException("User", "id", Id)); + userRepository.deleteById(Id); + } + + @Override + @Transactional + public void deleteFavorite(Integer userId, Integer recipeId) { + User existingUser = userRepository.findById(userId) + .orElseThrow(() -> new NotFoundException("User", "id", userId)); + + Recipe existingRecipe = recipeRepository.findById(recipeId) + .orElseThrow(() -> new NotFoundException("Recipe", "id", recipeId)); + userRepository.save(existingUser); + + existingUser.getFavRecipes().remove(existingRecipe); + + } + + @Override + public List getUsersByName(String name) { + List users = userRepository.findByUsernameContainingIgnoreCase(name); + + if (users.isEmpty()) { + throw new NotFoundException("User", "username containing", name); + } + + List userList = new ArrayList<>(); + + for (User user : users) { + UserDto dto = convertToDto(user); + userList.add(dto); + } + return userList; + } + + @Override + public UserDto banUser(Integer id) { + User user = userRepository.findById(id) + .orElseThrow(() -> new NotFoundException("User", "id", id)); + user.setBanned(true); + userRepository.save(user); + return convertToDto(user); + } + + @Override + public UserDto unbanUser(Integer id) { + User user = userRepository.findById(id) + .orElseThrow(() -> new NotFoundException("User", "id", id)); + user.setBanned(false); + userRepository.save(user); + return convertToDto(user); + } + + @Override + public UserDto makeAdmin(Integer id) { + User user = userRepository.findById(id) + .orElseThrow(() -> new NotFoundException("User", "id", id)); + user.setRole("ROLE_ADMIN"); + userRepository.save(user); + return convertToDto(user); + } + + @Override + public UserDto makeUser(Integer id) { + User user = userRepository.findById(id) + .orElseThrow(() -> new NotFoundException("User", "id", id)); + user.setRole("ROLE_USER"); + userRepository.save(user); + return convertToDto(user); + } +} diff --git a/src/main/java/com/example/demo/service/MapperService.java b/src/main/java/com/example/demo/service/MapperService.java new file mode 100644 index 0000000..d4405a5 --- /dev/null +++ b/src/main/java/com/example/demo/service/MapperService.java @@ -0,0 +1,5 @@ +package com.example.demo.service; + +public class MapperService { + +} diff --git a/src/main/java/com/example/demo/service/RecipeService.java b/src/main/java/com/example/demo/service/RecipeService.java new file mode 100644 index 0000000..623a07c --- /dev/null +++ b/src/main/java/com/example/demo/service/RecipeService.java @@ -0,0 +1,27 @@ +package com.example.demo.service; + +import java.util.List; + +import org.jspecify.annotations.Nullable; + +import com.example.demo.dto.RecipeDto; +import com.example.demo.entity.Recipe; +import com.example.demo.entity.User; + +public interface RecipeService { + RecipeDto convertToDto(Recipe recipe); + + RecipeDto saveRecipe(RecipeDto recipe, String currentUsername); + + List getAllRecipes(); + + RecipeDto getRecipeById(Integer recipeId); + + List getRecipes(String name, List tags); + + RecipeDto updateRecipe(RecipeDto recipedto, Integer Id, String currentUsername); + + void deleteRecipe(Integer Id, String currentUsername); + +} + diff --git a/src/main/java/com/example/demo/service/UserService.java b/src/main/java/com/example/demo/service/UserService.java new file mode 100644 index 0000000..cf315f5 --- /dev/null +++ b/src/main/java/com/example/demo/service/UserService.java @@ -0,0 +1,34 @@ +package com.example.demo.service; + +import java.util.List; + +import com.example.demo.dto.UserDto; +import com.example.demo.entity.User; + +public interface UserService { + UserDto convertToDto(User user); + + User saveUser(User user); + + List getAllUsers(); + + UserDto getUserById(Integer id); + + List getUsersByName(String name); + + UserDto saveFavorite(Integer userId, Integer recipeId); + + UserDto updateUser(User user, Integer id); + + void deleteUser(Integer id); + + void deleteFavorite(Integer userId, Integer recipeId); + + UserDto banUser(Integer id); + + UserDto unbanUser(Integer id); + + UserDto makeAdmin(Integer id); + + UserDto makeUser(Integer id); +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..8b61b06 --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,20 @@ +spring.application.name=demo + + + +spring.datasource.url=jdbc:mysql://localhost:3306/demo +spring.datasource.username=springuser +spring.datasource.password=E~zDmEYHd"5?]U%h_-~Y0uEm + +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver + +spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect +spring.jpa.hibernate.ddl-auto=update + +spring.jpa.show-sql=true +spring.jpa.properties.hibernate.format_sql=true + +spring.jpa.open-in-view=false +#spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect + +server.port=8080 diff --git a/src/main/resources/static/css/create-account.css b/src/main/resources/static/css/create-account.css new file mode 100644 index 0000000..df988e0 --- /dev/null +++ b/src/main/resources/static/css/create-account.css @@ -0,0 +1,141 @@ +:root { + --dusty-red: #D43F3F; + --dusty-red-hover: #C73636; + --dark-yellow: #FFD27F; + --pale-yellow: #FFECB3; + --peach: #F5A96E; + --dark: #850000; +} + +.delius { + font-family: 'Delius Swash Caps', cursive; + font-weight: 400; + font-style: normal; +} + +.mali-regular { + font-family: 'Mali', cursive; + font-weight: 400; + font-style: normal; +} + +/* login.css */ +body, html { + height: 100%; + margin: 0; + font-family: 'Mali', cursive; + background-color: var(--pale-yellow); +} + +.container { + display: flex; + height: 100vh; +} + +/* Header Styles */ +.top-header { + position: sticky; + top: 0; + display: flex; + align-items: center; + justify-content: center; + background-color: var(--dusty-red); + color: var(--dark-yellow); + padding: 10px 20px; + height: 60px; + gap: 40px; +} + +.top-header .swirl { + height: 40px; + width: auto; + margin: 0 20px; +} + +.site-name { + font-size: 2.5em; + font-weight: bold; + letter-spacing: 4px; + font-family: 'Delius Swash Caps', cursive; + } + + +/* Main Content */ +.main-content { + flex-grow: 0; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + margin-top: 40px;} + +/* Login Box */ +.login-box { + background-color: var(--peach); + padding: 45px; + border-radius: 20px; + width: 600px; + color: var(--dark); +} + +.login-box h2 { + font-size: 50px; + text-align: center; + font-weight: bold; + margin-bottom: 30px; + margin-top: 8px; + +} + +.login-box .rows { + display: flex; + gap: 10px; + align-items: center; + +} + +.login-box label { + font-size: 20px; + width: 30%; + margin: 0px; + font-weight: bold; + text-align: right; +} + +.login-box input { + flex: 1; + padding: 10px; + margin: auto; + margin-top: 5px; + margin-left: 20px; + border-radius: 10px; + border: 2.5px solid var(--dusty-red); + background-color: var(--pale-yellow); + font-size: 20px; + box-sizing: border-box; +} + +.login-box input.invalid { + border: 4px solid var(--dusty-red); +} + +.login-box button { + display: block; + margin: 0 auto; + width: 40%; + padding: 10px; + margin-top: 20px; + background-color: var(--dusty-red); + color: var(--dark-yellow); + font-weight: bold; + border: none; + border-radius: 10px; + cursor: pointer; + transition: background-color 0.1s ease; + transition: transform 0.2s ease; + } + +.login-box button:hover { + background-color: var(--dusty-red-hover); + transform: scale(1.05); +} diff --git a/src/main/resources/static/css/create-recipe.css b/src/main/resources/static/css/create-recipe.css new file mode 100644 index 0000000..35f384f --- /dev/null +++ b/src/main/resources/static/css/create-recipe.css @@ -0,0 +1,447 @@ +:root { + --dusty-red: #D43F3F; + --dusty-red-hover: #C73636; + --dark-yellow: #FFD27F; + --pale-yellow: #FFECB3; + --peach: #F5A96E; + --dark: #850000; +} + +.delius { + font-family: 'Delius Swash Caps', cursive; + font-weight: 400; + font-style: normal; +} + +.mali-regular { + font-family: 'Mali', cursive; + font-weight: 400; + font-style: normal; +} + +body, html { + height: 100%; + margin: 0; + font-family: 'Mali', cursive; + background-color: var(--pale-yellow); +} + +.container { + display: flex; + height: 100vh; +} + +/* Header Styles */ +.top-header { + position: sticky; + top: 0; + display: flex; + align-items: center; + justify-content: center; + background-color: var(--dusty-red); + color: var(--dark-yellow); + padding: 10px 20px; + height: 60px; + gap: 40px; +} + +.top-header .swirl { + height: 40px; + width: auto; + margin: 0 20px; +} + +.site-name { + font-size: 2.5em; + font-weight: bold; + letter-spacing: 4px; + font-family: 'Delius Swash Caps', cursive; +} + + +/* Main Content */ +.main-content { + flex-grow: 0; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + margin-top: 40px;} + +.form-wrap { + max-width: 800px; + margin: 0 auto; + padding: 1.5rem 1rem; +} + +/* commented out but i was trying to split it +.form-split { + width:100%; + display:flex; + flex: 1; +} +*/ + +.form-section { + background: var(--peach); + border-radius: 15px; + padding: 1.25rem 1.5rem; + margin-bottom: 1rem; +} + +.section-title { + font-size: 30px; + font-weight: 800; + color: var(--dark); + text-transform: uppercase; + letter-spacing: 0.06em; + margin-bottom: 1rem; +} + +.field { + color: var(--dusty-red); + margin-bottom: 1rem; +} + +.field:last-child { + margin-bottom: 0; +} + +label { + display: block; + font-size: 16px; + font-weight: 600; + color: var(--dark); + margin-bottom: 6px; +} + + +.required { + color: var(--dusty-red-hover); + margin-left: 3px; +} + +input[type="text"], +textarea, +select { + width: 100%; + box-sizing: border-box; + font-size: 16px; + padding: 0 10px; + height: 36px; + border: 1px; + border-radius: 6px; + outline: none; + font-family: inherit; + color: var(--dusty-red); + background: var(--pale-yellow); +} + +input[type="text"]:focus, +textarea:focus, +select:focus { + border-color: var(--dusty-red); +} + +textarea { + height: auto; + min-height: 80px; + padding: 8px 10px; + resize: vertical; +} + +::placeholder { + color: var(--dusty-red); + opacity: 1; +} + +.dynamic-row { + display: flex; + align-items: center; + gap: 8px; + margin-bottom: 8px; +} + +.dynamic-row input, +.dynamic-row textarea { + flex: 1; +} + +.dynamic-row textarea { + min-height: 30px; + resize: vertical; +} + +.step-bubble { + width: 26px; + height: 26px; + min-width: 26px; + background: transparent; + color: var(--dusty-red); + border-radius: 50%; + display: flex; + align-items: center; + justify-content: center; + font-size: 15px; + font-weight: 700; + align-self: flex-start; + margin-top: 8px; +} + +.btn-remove { + background: var(--dusty-red); + border: 1px; + border-radius: 6px; + width: 30px; + height: 30px; + min-width: 30px; + cursor: pointer; + font-size: 14px; + color: var(--dark-yellow); + display: flex; + align-items: center; + justify-content: center; + align-self: flex-start; + margin-top: 4px; +} + +.btn-remove:hover { + background: var(--dusty-red-hover); +} + +.btn-add { + width: 100%; + margin-top: 4px; + padding: 8px; + background: var(--dusty-red); + border: 1px; + border-radius: 8px; + font-family: 'Mali', cursive; + font-size: 13px; + color: var(--dark-yellow); + cursor: pointer; +} + +.btn-add:hover { + background: var(--dusty-red-hover); +} + +/* Image upload */ +.image-drop { + border: 1.5px dashed var(--dusty-red); + border-radius: 8px; + padding: 2rem; + text-align: center; + cursor: pointer; + background: var(--dark-yellow); +} + +.image-drop:hover { + border-color: var(--dusty-red-hover); + filter: brightness(99%); +} + +.image-drop .upload-icon { + font-size: 30px; + margin-bottom: 8px; +} + +.image-drop .upload-title { + font-weight: 600; + font-size: 16px; + color: var(--dusty-red); + margin: 0 0 4px; +} + +.image-drop .upload-sub { + font-size: 16px; + color: var(--dark); + margin: 0; +} + +.image-preview { + display: none; + border-radius: 8px; + overflow: hidden; + position: relative; +} + +.image-preview img { + width: 100%; + display: block; + max-height: 200px; + object-fit: cover; +} + +.remove-img { + position: absolute; + top: 8px; + right: 8px; + background: rgba(0,0,0,0.5); + color: white; + border: none; + border-radius: 4px; + padding: 3px 8px; + font-size: 12px; + cursor: pointer; +} + +/* Tags */ + +.tag-input-row { + display: flex; + flex-direction: row; + gap: 6px; +} + +.tag-wrap { + display: flex; + flex-wrap: wrap; + gap: 6px; + margin-top: 8px; +} + +.tag { + font-size: 12px; + background: var(--pale-yellow); + color: var(--dusty-red); + padding: 3px 10px; + border-radius: 99px; + display: flex; + align-items: center; + gap: 4px; +} + +.tag .remove-tag { + cursor: pointer; + opacity: 0.6; +} + +.tag .remove-tag:hover { + opacity: 1; +} + +/* Actions */ +.actions { + display: flex; + justify-content: center; + align-items: center; + margin-top: 1rem; +} + +.btn, +.btn-create { + background: var(--dusty-red); + color: var(--dark-yellow); + border: none; + border-radius: 8px; + padding: 0 20px; + height: 36px; + font-family: 'Mali', cursive; + font-size: 14px; + font-weight: 500; + cursor: pointer; +} + +.btn:hover, +.btn-create:hover { + background: var(--dusty-red-hover); +} + +.btn-create:hover { + transform: scale(1.03); +} + +.btn-create { + width: 50%; + font-size: 20px; + font-weight: 700; + border-radius: 10px; + padding: 0 20px; + height: 46px; + + transition: background-color 0.1s ease, transform 0.2s ease; +} + +/* small screens */ +@media (max-width: 600px) { + body { + font-size: 20px; + } + + .form-wrap { + max-width: 400px; + margin: 0 auto; + padding: 1.5rem 1rem; + } + + label { + font-size: 26px; + margin-bottom: 12px; + } + + input[type="text"], + textarea, + select { + font-size: 20px; + padding: 10px 14px; + height: 50px; + } + + textarea { + height: auto; + padding: 12px 14px; +} + + .field { + margin-bottom: 1.5rem; + } + + .form-section { + padding: 1.75rem 2rem; + margin-bottom: 1.25rem; + } + + .section-title { + font-size: 16px; + margin-bottom: 1.25rem; + } + + .dynamic-row { + gap: 12px; + margin-bottom: 12px; + } + + .btn-add { + padding: 14px; + font-size: 18px; + margin-top: 8px; + } + + ::placeholder { + font-size: 50px; + } + + .actions { + gap: 12px; + margin-top: 1.5rem; + } + .row { + grid-template-columns: 1fr; + } + + .btn, + .btn-create { + height: 44px; + font-size: 15px; + } + + .actions { + flex-direction: column-reverse; + gap: 10px; + } + + .actions button { + width: 100%; + } +} \ No newline at end of file diff --git a/src/main/resources/static/css/explore.css b/src/main/resources/static/css/explore.css new file mode 100644 index 0000000..8503a41 --- /dev/null +++ b/src/main/resources/static/css/explore.css @@ -0,0 +1,348 @@ +/* ========================= + Root Variables +========================= */ +:root { + --dusty-red: #D43F3F; + --dusty-red-hover: #C73636; + --dark-yellow: #FFD27F; + --pale-yellow: #FFECB3; + --peach: #F5A96E; + --dark: #850000; +} + +/* ========================= + Global Styles +========================= */ +.delius { + font-family: 'Delius Swash Caps', cursive; + font-weight: 400; + font-style: normal; +} + +.mali-regular { + font-family: 'Mali', cursive; + font-weight: 400; + font-style: normal; +} + +body, html { + height: 100vh; + margin: 0; + font-family: 'Mali', cursive; + background-color: var(--pale-yellow); + overflow: clip; +} + +/* ========================= + Layout Structure +========================= */ +.body { + display: flex; + flex-direction: row; + height: 100%; +} + +.body-left, .body-right { + position: sticky; + flex-grow: 0; + width: 400px; +} + +/* ========================= + Header Styles +========================= */ +.top-header { + display: flex; + align-items: center; + justify-content: center; + gap: 40px; + height: 60px; + padding: 10px 20px; + background-color: var(--dusty-red); + color: var(--dark-yellow); +} + +.top-header .swirl { + height: 40px; + width: auto; + margin: 0 20px; +} + +.site-name { + font-family: 'Delius Swash Caps', serif; + font-size: 2.5em; + font-weight: bold; + letter-spacing: 4px; + color: var(--dark-yellow); +} + +/* ========================= + Left Sidebar +========================= */ +.sidebar-left { + overflow: hidden; + margin: 25px; + border-radius: 20px; + z-index: 10; + background-color: var(--peach); + color: var(--dark); + padding: 6px; + font-size: 1.75em; + font-weight: 900; + letter-spacing: 1.5px; + display: flex; + flex-direction: column; + justify-content: space-between; + align-items: center; +} + +.sidebar-left ul { + list-style: none; + padding: 0; +} + +.sidebar-left li { + margin-bottom: 7px; +} + +.sidebar-left a { + color: var(--dark); + text-decoration: none; + transition: 0.1s ease; +} + +.sidebar-left a:hover { + color: var(--dusty-red); +} + +.sidebar-left .nav_icon { + background: none; + border: none; + padding: 0; + cursor: pointer; + height: 100px; + width: auto; + border-radius: 8px; + transition: transform 0.2s ease; +} + +.sidebar-left .nav_icon:hover { + transform: scale(1.05); +} + +/* ========================= + Floating Create Icon +========================= */ +.create_icon { + position: fixed; + bottom: 30px; + left: 55px; + z-index: 1000; + transition: transform 0.2s ease; +} + +.create_icon:hover { + transform: scale(1.02); +} + +.create_icon img { + width: 150px; + height: auto; + border-radius: 10%; +} + +/* ========================= + Right Sidebar +========================= */ +.sidebar-right { + display: flex; + flex-direction: column; + justify-content: space-between; + align-items: center; + margin: 25px; + padding: 5px; + height: 75%; + border-radius: 20px; + z-index: 10; + background-color: var(--peach); + color: var(--dusty-red); + font-size: 1.3em; + font-weight: 900; + letter-spacing: 1.3px; +} + +.sidebar-right ul { + list-style: none; + padding: 0; +} + +.sidebar-right li { + margin-bottom: 5px; +} + +.sidebar-right a { + color: var(--dusty-red); + text-decoration: none; +} + +/* ========================= + Main Content Area +========================= */ +.main-content { + width: 100%; + flex-grow: 1; + display: flex; + flex-direction: column; + justify-content: flex-start; + align-items: flex-start; + overflow: scroll; + scrollbar-color: var(--dusty-red) var(--pale-yellow); + height: 100%; +} + +/* safari and old browsers*/ +::-webkit-scrollbar-track { + background: var(--pale-yellow); +} +::-webkit-scrollbar-thumb { + background: var(--dusty-red); +} + +/* ========================= + Search Bar +========================= */ +.search-bar, input[type="search"] { + width: 90%; + margin: 10px; + flex-grow: 1; + display: flex; + flex-direction: column; + align-items: stretch; + color: var(--dark-yellow); + border: none; + border-radius: 10px; + padding: 0 10px; + height: 50px; + font-size: 20px; + font-family: 'Mali', cursive; + font-weight: 600; + justify-content: flex-start; +} + +.search-btn { +display: flex; + flex-direction: row; + gap: 6px; + } + +input[type="search"] { + background: var(--dusty-red); +} + +input[type="search"]::placeholder { + color: var(--dark-yellow); +} + +.search-bar:focus { + outline: none; +} + +.search-bar button[type="submit"] { + background: var(--dusty-red); + color: var(--dark-yellow); + font-size: 1.3em; + border: none; + border-radius: 10px; + padding: 0 10px; + height: 50px; + width: 50px; + margin: 10px; +} + +.search-bar label { display: none; } + +input[type="search"]::-webkit-search-cancel-button { + filter: invert(1) sepia(1) saturate(2) hue-rotate(3deg); +} + + +/* ========================= + Recipe Cards Layout +========================= */ +.recipe-card { + margin-top: 35px; + width: 99.5%; + display: flex; + flex-wrap: wrap; + gap: 35px; + justify-content: flex-start; + flex-direction: row; + height: fit-content; + padding-right: 10px; +} + +a { + text-decoration: none; + color: var(--dark); +} + +/* ========================= + Individual Card (Folder Style) +========================= */ +.card { + position: relative; /* needed for tab */ + display: flex; + align-items: center; + gap: 10px; + flex: 1 1 260px; + max-width: 400px; + max-height: 200px; + padding: 25px 20px 20px; /* extra space for tab */ + border-radius: 12px; + background: var(--peach); +} + +/* Folder Tab */ +.card::before { + content: ""; + position: absolute; + top: -16px; + left: 0px; + width: 100px; + height: 28px; + background: var(--peach); + border-radius: 6px 6px 0 0; +} + +/* ========================= + Card Content +========================= */ +.card .card-text { + height: 100%; + overflow: hidden; /* the scroll bars were difficult to look at, the user can just view the recipe*/ + color: var(--dark); + transition: 0.1s ease; +} + +.card .card-text:hover{ + color: var(--dusty-red-hover); +} + +/* ========================= + Card Image +========================= */ +.card img { + width: 100%; + height: 100px; + object-fit: cover; + border-radius: 8px; +} + +/* ========================= + Card Columns +========================= */ +.card-left, +.card-right { + flex-shrink: 0; + width: 50%; +} diff --git a/src/main/resources/static/css/home.css b/src/main/resources/static/css/home.css new file mode 100644 index 0000000..bc41372 --- /dev/null +++ b/src/main/resources/static/css/home.css @@ -0,0 +1,288 @@ +/* ========================= + Root Variables +========================= */ +:root { + --dusty-red: #D43F3F; + --dusty-red-hover: #C73636; + --dark-yellow: #FFD27F; + --pale-yellow: #FFECB3; + --peach: #F5A96E; + --dark: #850000; +} + +/* ========================= + Global Styles +========================= */ +.delius { + font-family: 'Delius Swash Caps', cursive; + font-weight: 400; + font-style: normal; +} + +.mali-regular { + font-family: 'Mali', cursive; + font-weight: 400; + font-style: normal; +} + +body, html { + height: 100vh; + margin: 0; + font-family: 'Mali', cursive; + background-color: var(--pale-yellow); + overflow: clip; +} + +/* ========================= + Layout Structure +========================= */ +.body { + display: flex; + flex-direction: row; + height: 100%; +} + +.body-left, .body-right { + position: sticky; + flex-grow: 0; + width: 400px; +} + +/* ========================= + Header Styles +========================= */ +.top-header { + display: flex; + align-items: center; + justify-content: center; + gap: 40px; + height: 60px; + padding: 10px 20px; + background-color: var(--dusty-red); + color: var(--dark-yellow); +} + +.top-header .swirl { + height: 40px; + width: auto; + margin: 0 20px; +} + +.site-name { + font-family: 'Delius Swash Caps', serif; + font-size: clamp(1.1em, 5vw, 2.5em); + font-weight: bold; + letter-spacing: 4px; + color: var(--dark-yellow); +} + +/* ========================= + Left Sidebar +========================= */ +.sidebar-left { + overflow: hidden; + margin: 25px; + border-radius: 20px; + z-index: 10; + background-color: var(--peach); + color: var(--dark); + padding: 6px; + font-size: 1.75em; + font-weight: 900; + letter-spacing: 1.5px; + display: flex; + flex-direction: column; + justify-content: space-between; + align-items: center; +} + +.sidebar-left ul { + list-style: none; + padding: 0; +} + +.sidebar-left li { + margin-bottom: 7px; +} + +.sidebar-left a { + color: var(--dark); + text-decoration: none; + transition: 0.1s ease; +} + +.sidebar-left a:hover { + color: var(--dusty-red-hover); +} + +.sidebar-left .nav_icon { + background: none; + border: none; + padding: 0; + cursor: pointer; + height: 100px; + width: auto; + border-radius: 8px; + transition: transform 0.2s ease; +} + +.sidebar-left .nav_icon:hover { + transform: scale(1.05); +} + +/* ========================= + Floating Create Icon +========================= */ +.create_icon { + position: fixed; + bottom: 30px; + left: 55px; + z-index: 1000; + transition: transform 0.2s ease; +} + +.create_icon:hover { + transform: scale(1.02); +} + +.create_icon img { + width: 150px; + height: auto; + border-radius: 10%; +} + +/* ========================= + Right Sidebar +========================= */ +.sidebar-right { + display: flex; + flex-direction: column; + justify-content: space-between; + align-items: center; + margin: 25px; + padding: 5px; + height: 75%; + border-radius: 20px; + z-index: 10; + background-color: var(--peach); + color: var(--dusty-red); + font-size: 1.6em; + font-weight: 900; + letter-spacing: 1.5px; +} + +.sidebar-right ul { + list-style: none; + padding: 0; +} + +.sidebar-right li { + margin-bottom: 5px; +} + +.sidebar-right a { + color: var(--dusty-red); + text-decoration: none; +} + +/* ========================= + Main Content Area +========================= */ +.main-content { + width: 100%; + flex-grow: 1; + display: flex; + justify-content: center; + align-items: flex-start; + overflow: scroll; + scrollbar-color: var(--dusty-red) var(--pale-yellow); + height: 100%; +} + +/* safari and old browsers*/ +::-webkit-scrollbar-track { + background: var(--pale-yellow); +} +::-webkit-scrollbar-thumb { + background: var(--dusty-red); +} + +/* ========================= + Recipe Cards Layout +========================= */ +.recipe-card { + margin-top: 35px; + width: 99%; + display: flex; + flex-wrap: wrap; + gap: 35px; + justify-content: flex-start; + flex-direction: row; + height: fit-content; +} + +a { + text-decoration: none; + color: var(--dark); +} + +/* ========================= + Individual Card (Folder Style) +========================= */ +.card { + position: relative; /* needed for tab */ + display: flex; + align-items: center; + gap: 10px; + flex: 1 1 260px; + max-width: 400px; + max-height: 200px; + padding: 25px 20px 20px; /* extra space for tab */ + border-radius: 12px; + background: var(--peach); +} + +/* Folder Tab */ +.card::before { + content: ""; + position: absolute; + top: -16px; + left: 0px; + width: 100px; + height: 28px; + background: var(--peach); + border-radius: 6px 6px 0 0; +} + +/* ========================= + Card Content +========================= */ +.card .card-text { + height: 100%; + overflow: hidden; /* the scroll bars were difficult to look at, the user can just view the recipe*/ + color: var(--dark); + transition: 0.1s ease; +} + +.card .card-text:hover{ + color: var(--dusty-red-hover); +} + +/* ========================= + Card Image +========================= */ +.card img { + width: 100%; + height: 100px; + object-fit: cover; + border-radius: 8px; +} + +/* ========================= + Card Columns +========================= */ +.card-left, +.card-right { + flex-shrink: 0; + width: 50%; +} diff --git a/src/main/resources/static/css/login.css b/src/main/resources/static/css/login.css new file mode 100644 index 0000000..e5aaa30 --- /dev/null +++ b/src/main/resources/static/css/login.css @@ -0,0 +1,178 @@ +/* ========================= + Root Variables +========================= */ +:root { + --dusty-red: #D43F3F; + --dusty-red-hover: #C73636; + --dark-yellow: #FFD27F; + --pale-yellow: #FFECB3; + --peach: #F5A96E; + --dark: #850000; +} + +/* ========================= + Global Styles +========================= */ +.delius { + font-family: 'Delius Swash Caps', cursive; + font-weight: 400; + font-style: normal; +} + +.mali-regular { + font-family: 'Mali', cursive; + font-weight: 400; + font-style: normal; +} + +body, +html { + height: 100%; + margin: 0; + font-family: 'Mali', cursive; + background-color: var(--pale-yellow); +} + +/* ========================= + Layout Container +========================= */ +.container { + display: flex; + height: 100vh; +} + +/* ========================= + Header Styles +========================= */ +.top-header { + position: sticky; + top: 0; + display: flex; + align-items: center; + justify-content: center; + gap: 40px; + + height: 60px; + padding: 10px 20px; + + background-color: var(--dusty-red); + color: var(--dark-yellow); +} + +.top-header .swirl { + height: 40px; + width: auto; + margin: 0 20px; +} + +.site-name { + font-family: 'Delius Swash Caps', cursive; + font-size: 2.5em; + font-weight: bold; + letter-spacing: 4px; +} + +/* ========================= + Main Content Area +========================= */ +.main-content { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + + flex-grow: 0; + margin-top: 40px; +} + +/* ========================= + Login Box +========================= */ +.login-box { + width: 400px; + padding: 45px; + border-radius: 20px; + + background-color: var(--peach); + color: var(--dark); +} + +.login-box h2 { + margin: 8px 0 30px; + + font-size: 50px; + font-weight: bold; + text-align: center; +} + +/* Form Labels */ +.login-box label { + display: block; + width: 90%; + margin: 10px; + + font-size: 20px; + font-weight: bold; +} + +/* Form Inputs */ +.login-box input { + display: block; + width: 90%; + margin: 5px auto 0; + padding: 10px; + + font-size: 20px; + border-radius: 10px; + border: 2.5px solid var(--dusty-red); + background-color: var(--pale-yellow); + box-sizing: border-box; +} + +.alert { + color: var(--dusty-red); +} + +/* ========================= + Button Styles +========================= */ +.login-box button { + display: block; + width: 40%; + margin: 20px auto 0; + padding: 10px; + + font-family: 'Mali', cursive; + font-weight: bold; + color: var(--dark-yellow); + background-color: var(--dusty-red); + + border: none; + border-radius: 10px; + cursor: pointer; + + transition: background-color 0.1s ease, transform 0.2s ease; +} + +.login-box button:hover { + background-color: var(--dusty-red-hover); + transform: scale(1.05); +} + +/* ========================= + Sign Up Section +========================= */ +.sign_up { + color: var(--dusty-red); +} + +.sign_up a { + display: inline-block; + color: var(--dark); + text-decoration: none; + transition: transform 0.2s ease; +} + +.sign_up a:hover { + transform: scale(1.03); +} \ No newline at end of file diff --git a/src/main/resources/static/css/view-recipe.css b/src/main/resources/static/css/view-recipe.css new file mode 100644 index 0000000..a425b1c --- /dev/null +++ b/src/main/resources/static/css/view-recipe.css @@ -0,0 +1,275 @@ +/* ========================= + Root Variables +========================= */ +:root { + --dusty-red: #D43F3F; + --dusty-red-hover: #C73636; + --dark-yellow: #FFD27F; + --pale-yellow: #FFECB3; + --peach: #F5A96E; + --dark: #850000; +} + +/* ========================= + Global Styles +========================= */ +.delius { + font-family: 'Delius Swash Caps', cursive; + font-weight: 400; + font-style: normal; +} + +.mali-regular { + font-family: 'Mali', cursive; + font-weight: 400; + font-style: normal; +} + +body, html { + height: 100vh; + margin: 0; + font-family: 'Mali', cursive; + background-color: var(--pale-yellow); + overflow: clip; +} + +/* ========================= + Layout Structure +========================= */ +.body { + display: flex; + flex-direction: row; + height: 100%; +} + +.body-left, .body-right { + position: sticky; + flex-grow: 0; + width: 400px; +} + +/* ========================= + Header Styles +========================= */ +.top-header { + display: flex; + align-items: center; + justify-content: center; + gap: 40px; + height: 60px; + padding: 10px 20px; + background-color: var(--dusty-red); + color: var(--dark-yellow); +} + +.top-header .swirl { + height: 40px; + width: auto; + margin: 0 20px; +} + +.site-name { + font-family: 'Delius Swash Caps', serif; + font-size: 2.5em; + font-weight: bold; + letter-spacing: 4px; + color: var(--dark-yellow); +} + +/* ========================= + Left Sidebar +========================= */ +.sidebar-left { + overflow: hidden; + margin: 25px; + border-radius: 20px; + z-index: 10; + background-color: var(--peach); + color: var(--dark); + padding: 6px; + font-size: 1.75em; + font-weight: 900; + letter-spacing: 1.5px; + display: flex; + flex-direction: column; + justify-content: space-between; + align-items: center; +} + +.sidebar-left ul { + list-style: none; + padding: 0; +} + +.sidebar-left li { + margin-bottom: 7px; +} + +.sidebar-left a { + color: var(--dark); + text-decoration: none; + transition: 0.1s ease; +} + +.sidebar-left a:hover { + color: var(--dusty-red); +} + +.sidebar-left .nav_icon { + background: none; + border: none; + padding: 0; + cursor: pointer; + height: 100px; + width: auto; + border-radius: 8px; + transition: transform 0.2s ease; +} + +.sidebar-left .nav_icon:hover { + transform: scale(1.05); +} + +/* ========================= + Floating Create Icon +========================= */ +.create_icon { + position: fixed; + bottom: 30px; + left: 55px; + z-index: 1000; + transition: transform 0.2s ease; +} + +.create_icon:hover { + transform: scale(1.02); +} + +.create_icon img { + width: 150px; + height: auto; + border-radius: 10%; +} + +/* ========================= + Right Sidebar +========================= */ +.sidebar-right { + display: flex; + flex-direction: column; + justify-content: space-between; + align-items: center; + margin: 25px; + padding: 5px; + height: 75%; + border-radius: 20px; + z-index: 10; + background-color: var(--peach); + color: var(--dusty-red); + font-size: 1.6em; + font-weight: 900; + letter-spacing: 1.5px; +} + +.sidebar-right ul { + list-style: none; + padding: 0; +} + +.sidebar-right li { + margin-bottom: 5px; +} + +.sidebar-right a { + color: var(--dusty-red); + text-decoration: none; +} + +/* ========================= + Main Content Area +========================= */ +.main-content { + width: 100%; + flex-grow: 1; + display: flex; + justify-content: center; + align-items: flex-start; + overflow: scroll; + height: 100%; +} + +/* ========================= + Recipe Cards Layout +========================= */ +.recipe-card { + margin-top: 35px; + width: 100%; + display: flex; + flex-wrap: wrap; + gap: 35px; + justify-content: flex-start; + flex-direction: row; + height: fit-content; +} + +a { + text-decoration: none; + color: var(--dark); +} + +/* ========================= + Individual Card (Folder Style) +========================= */ +.card { + position: relative; /* needed for tab */ + display: flex; + align-items: center; + gap: 10px; + flex: 1 1 260px; + max-width: 400px; + max-height: 200px; + padding: 25px 20px 20px; /* extra space for tab */ + border-radius: 12px; + background: var(--peach); +} + +/* Folder Tab */ +.card::before { + content: ""; + position: absolute; + top: -16px; + left: 0px; + width: 100px; + height: 28px; + background: var(--peach); + border-radius: 6px 6px 0 0; +} + +/* ========================= + Card Content +========================= */ +.card .card-text { + height: 100%; + overflow: hidden; /* the scroll bars were difficult to look at, the user can just view the recipe*/ + font-family: 'Roboto', sans-serif; + color: var(--dark); +} + +/* ========================= + Card Image +========================= */ +.card img { + width: 100%; + height: 100px; + object-fit: cover; + border-radius: 8px; +} + +/* ========================= + Card Columns +========================= */ +.card-left, +.card-right { + flex-shrink: 0; + width: 50%; +} diff --git a/src/main/resources/static/images/create_icon.png b/src/main/resources/static/images/create_icon.png new file mode 100644 index 0000000..42a734c Binary files /dev/null and b/src/main/resources/static/images/create_icon.png differ diff --git a/src/main/resources/static/images/create_icon_lineless.png b/src/main/resources/static/images/create_icon_lineless.png new file mode 100644 index 0000000..dedd549 Binary files /dev/null and b/src/main/resources/static/images/create_icon_lineless.png differ diff --git a/src/main/resources/static/images/decor_left.png b/src/main/resources/static/images/decor_left.png new file mode 100644 index 0000000..a000b29 Binary files /dev/null and b/src/main/resources/static/images/decor_left.png differ diff --git a/src/main/resources/static/images/decor_right.png b/src/main/resources/static/images/decor_right.png new file mode 100644 index 0000000..61cdff8 Binary files /dev/null and b/src/main/resources/static/images/decor_right.png differ diff --git a/src/main/resources/static/images/header_left.png b/src/main/resources/static/images/header_left.png new file mode 100644 index 0000000..ac2c403 Binary files /dev/null and b/src/main/resources/static/images/header_left.png differ diff --git a/src/main/resources/static/images/header_right.png b/src/main/resources/static/images/header_right.png new file mode 100644 index 0000000..cefe7f0 Binary files /dev/null and b/src/main/resources/static/images/header_right.png differ diff --git a/src/main/resources/static/images/logout_icon.png b/src/main/resources/static/images/logout_icon.png new file mode 100644 index 0000000..9ec9506 Binary files /dev/null and b/src/main/resources/static/images/logout_icon.png differ diff --git a/src/main/resources/templates/create-account.html b/src/main/resources/templates/create-account.html new file mode 100644 index 0000000..4a37b9c --- /dev/null +++ b/src/main/resources/templates/create-account.html @@ -0,0 +1,101 @@ + + + + + Create Thyme Crunch Account + + + + + +
+ Violin f-hole shape to the left of header. +

Thyme Crunch

+ Violin f-hole shape to the right of header. +
+ + +
+ +
+ + + + \ No newline at end of file diff --git a/src/main/resources/templates/create-recipe.html b/src/main/resources/templates/create-recipe.html new file mode 100644 index 0000000..583dc74 --- /dev/null +++ b/src/main/resources/templates/create-recipe.html @@ -0,0 +1,344 @@ + + + + + + + Create Thyme Crunch Recipe + + + + + +
+ Violin f-hole shape to the left of header. +

Thyme Crunch

+ Violin f-hole shape to the right of header. +
+ +
+
+ + +
+
New Recipe
+ +
+ + +
+ +
+ + +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ + +
+
+
+

Click to upload or drag and drop an image.

+
+
+ Cover preview + +
+ +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+
+ + +
+ +
+ +
+ + +
+
+
+
+ +
+ +
+ +
+ + + + \ No newline at end of file diff --git a/src/main/resources/templates/explore.html b/src/main/resources/templates/explore.html new file mode 100644 index 0000000..27cb15c --- /dev/null +++ b/src/main/resources/templates/explore.html @@ -0,0 +1,75 @@ + + + + + Thyme Crunch Home + + + + + + +
+ Violin f-hole shape to the left of header. +

Thyme Crunch

+ Violin f-hole shape to the right of header. +
+ +
+ +
+ + + Create New Recipe Icon (Red mixing bowl with a spoon and yellow addition symbol. + +
+ + + +
+ + +
+ + +
+ +
+
+ + diff --git a/src/main/resources/templates/home.html b/src/main/resources/templates/home.html new file mode 100644 index 0000000..619f36c --- /dev/null +++ b/src/main/resources/templates/home.html @@ -0,0 +1,65 @@ + + + + + Thyme Crunch Home + + + + + +
+ Violin f-hole shape to the left of header. +

Thyme Crunch

+ Violin f-hole shape to the right of header. +
+ +
+ +
+ + + Create New Recipe Icon (Red mixing bowl with a spoon and yellow addition symbol. + +
+ + + +
+ +
+ + +
+ +
+
+ + diff --git a/src/main/resources/templates/login.html b/src/main/resources/templates/login.html new file mode 100644 index 0000000..91c114c --- /dev/null +++ b/src/main/resources/templates/login.html @@ -0,0 +1,41 @@ + + + + + Thyme Crunch Login + + + + + +
+ Violin f-hole shape to the left of header. +

Thyme Crunch

+ Violin f-hole shape to the right of header. + +
+ + +
+ + +
+ + diff --git a/src/main/resources/templates/view-recipe.html b/src/main/resources/templates/view-recipe.html new file mode 100644 index 0000000..6c8e81f --- /dev/null +++ b/src/main/resources/templates/view-recipe.html @@ -0,0 +1,64 @@ + + + + + Thyme Crunch View Recipe + + + + + +
+ Violin f-hole shape to the left of header. +

Thyme Crunch

+ Violin f-hole shape to the right of header. +
+ +
+ +
+ + + Description of the icon + +
+ + + +
+
+

+

+ +
+
Ingredients
+
    +
  • +
+
+ +
+
Instructions
+
    +
  1. +
+
+
+ +
+ + diff --git a/src/test/java/com/example/demo/RecipeDemoApplicationTests.java b/src/test/java/com/example/demo/RecipeDemoApplicationTests.java new file mode 100644 index 0000000..a4a0e40 --- /dev/null +++ b/src/test/java/com/example/demo/RecipeDemoApplicationTests.java @@ -0,0 +1,13 @@ +package com.example.demo; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class RecipeDemoApplicationTests { + + @Test + void contextLoads() { + } + +}