The Unpopular Decision
@@ -0,0 +1,2 @@
|
||||
/mvnw text eol=lf
|
||||
*.cmd text eol=crlf
|
||||
@@ -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/
|
||||
@@ -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
|
||||
@@ -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"]
|
||||
@@ -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-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
||||
[ -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 "$@"
|
||||
@@ -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-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
||||
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"
|
||||
@@ -0,0 +1,129 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>4.0.3</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>demo</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>recipeDemo</name>
|
||||
<description>Software engineering recipe project</description>
|
||||
<url/>
|
||||
<licenses>
|
||||
<license/>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer/>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection/>
|
||||
<developerConnection/>
|
||||
<tag/>
|
||||
<url/>
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>25</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
|
||||
<!-- Web + MVC + Embedded Tomcat -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Thymeleaf Template Engine -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Database -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Security -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Input Validation -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- MySQL Driver -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- Dev Tools (auto reload) -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<scope>runtime</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- Testing -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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<UserDto> banUser(@PathVariable Integer id) {
|
||||
return new ResponseEntity<>(userService.banUser(id), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/users/{id}/unban")
|
||||
public ResponseEntity<UserDto> unbanUser(@PathVariable Integer id) {
|
||||
return new ResponseEntity<>(userService.unbanUser(id), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/users/{id}/make-admin")
|
||||
public ResponseEntity<UserDto> makeAdmin(@PathVariable Integer id) {
|
||||
return new ResponseEntity<>(userService.makeAdmin(id), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/users/{id}/make-user")
|
||||
public ResponseEntity<UserDto> makeUser(@PathVariable Integer id) {
|
||||
return new ResponseEntity<>(userService.makeUser(id), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
public class AuthController {
|
||||
|
||||
}
|
||||
@@ -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<Map<String, String>> handleConstraintViolation(ConstraintViolationException ex) {
|
||||
Map<String, String> 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<Map<String, String>> handleValidationExceptions(MethodArgumentNotValidException ex) {
|
||||
Map<String, String> errors = new HashMap<>();
|
||||
ex.getBindingResult().getFieldErrors().forEach(error -> {
|
||||
errors.put(error.getField(), error.getDefaultMessage());
|
||||
});
|
||||
return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
@@ -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<String, Object> healthCheck() {
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
|
||||
response.put("status", "UP");
|
||||
response.put("timestamp", LocalDateTime.now());
|
||||
response.put("service", "Recipe Backend");
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -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<RecipeDto> 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<RecipeDto> getAllRecipes() {
|
||||
return recipeService.getAllRecipes();
|
||||
}
|
||||
|
||||
// build get recipe by id REST API
|
||||
// http://localhost:8080/api/recipes/(id number goes here)
|
||||
@GetMapping("{id}")
|
||||
public ResponseEntity<RecipeDto> getRecipeById(@PathVariable("id") Integer recipeId) {
|
||||
return new ResponseEntity<RecipeDto>(recipeService.getRecipeById(recipeId), HttpStatus.OK);
|
||||
}
|
||||
|
||||
// build get recipe by name REST API
|
||||
@GetMapping("/search")
|
||||
public ResponseEntity<List<RecipeDto>> searchRecipes(
|
||||
@RequestParam(required = false) String name, // by not adding a name all recipes will appear basically
|
||||
@RequestParam(required = false) List<String> tags // since users can choose no tags this isnt required
|
||||
) {
|
||||
|
||||
|
||||
|
||||
List<RecipeDto> 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<RecipeDto> 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<String> deleteRecipe(@PathVariable("id") Integer recipeId, Authentication authentication) {
|
||||
String currentUsername = authentication.getName();
|
||||
recipeService.deleteRecipe(recipeId, currentUsername);
|
||||
return new ResponseEntity<>("Recipe deleted successfully!", HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<RecipeDto> 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<RecipeDto> recipes = recipeService.getAllRecipes();
|
||||
model.addAttribute("recipes", recipes);
|
||||
return "explore";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<User> saveUser(@RequestBody User user) {
|
||||
|
||||
return new ResponseEntity<User>(userService.saveUser(user), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
// build get all users REST API
|
||||
@GetMapping
|
||||
public List<UserDto> getAllUsers() {
|
||||
return userService.getAllUsers();
|
||||
}
|
||||
|
||||
// build get user by name REST API
|
||||
@GetMapping("/search")
|
||||
public ResponseEntity<List<UserDto>> getUsersByName(@RequestParam String name) {
|
||||
List<UserDto> 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<UserDto> getUserById(@PathVariable("id") Integer userId) {
|
||||
return new ResponseEntity<UserDto>(userService.getUserById(userId), HttpStatus.OK);
|
||||
}
|
||||
|
||||
// build create favorite REST API
|
||||
@PostMapping("/{userId}/favorites/{recipeId}")
|
||||
public ResponseEntity<UserDto> 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<UserDto> updateUser(@PathVariable("id") Integer userId, @RequestBody User user) {
|
||||
return new ResponseEntity<UserDto>(userService.updateUser(user, userId), HttpStatus.OK);
|
||||
}
|
||||
|
||||
// build delete user REST API
|
||||
@DeleteMapping("{id}")
|
||||
public ResponseEntity<String> deleteUser(@PathVariable("id") Integer userId) {
|
||||
userService.deleteUser(userId);
|
||||
return new ResponseEntity<String>("User deleted succesfully!", HttpStatus.OK);
|
||||
}
|
||||
|
||||
// build delete favorite REST API
|
||||
@DeleteMapping("/{userId}/favorites/{recipeId}")
|
||||
public ResponseEntity<String> deleteFavorite(@PathVariable Integer userId, @PathVariable Integer recipeId) {
|
||||
|
||||
userService.deleteFavorite(userId, recipeId);
|
||||
return new ResponseEntity<String>("Favorite deleted succesfully!", HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.example.demo.dto;
|
||||
|
||||
public class AuthResponse {
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.example.demo.dto;
|
||||
|
||||
public class LoginRequest {
|
||||
|
||||
}
|
||||
@@ -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<IngredientDto> ingredients;
|
||||
|
||||
@NotNull(message = "steps list is required")
|
||||
@Valid
|
||||
private java.util.List<StepDto> 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<IngredientDto> getIngredients() { return ingredients; }
|
||||
public void setIngredients(java.util.List<IngredientDto> ingredients) { this.ingredients = ingredients; }
|
||||
|
||||
public java.util.List<StepDto> getSteps() { return steps; }
|
||||
public void setSteps(java.util.List<StepDto> steps) { this.steps = steps; }
|
||||
}
|
||||
@@ -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<RecipeIngredientDto> ingredients;
|
||||
private List<StepDto> steps;
|
||||
private List<ImageDto> images;
|
||||
private List<TagDto> tags;
|
||||
|
||||
public RecipeDto() {
|
||||
super();
|
||||
}
|
||||
|
||||
public RecipeDto(String title, String description, Integer prepTimeMinutes, Integer cookTimeMinutes,
|
||||
Integer servings, UserDto userDto, String status, List<RecipeIngredientDto> ingredients,
|
||||
List<StepDto> steps, List<ImageDto> images, List<TagDto> 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<RecipeIngredientDto> getIngredients() {
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setIngredients(List<RecipeIngredientDto> ingredients) {
|
||||
this.ingredients = ingredients;
|
||||
}
|
||||
|
||||
public List<StepDto> getSteps() {
|
||||
return steps;
|
||||
}
|
||||
|
||||
public void setSteps(List<StepDto> steps) {
|
||||
this.steps = steps;
|
||||
}
|
||||
|
||||
public List<ImageDto> getImages() {
|
||||
return images;
|
||||
}
|
||||
|
||||
public void setImages(List<ImageDto> images) {
|
||||
this.images = images;
|
||||
}
|
||||
|
||||
public List<TagDto> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(List<TagDto> 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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<IngredientDto> ingredients;
|
||||
private List<StepDto> 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<IngredientDto> getIngredients() { return ingredients; }
|
||||
public void setIngredients(List<IngredientDto> ingredients) { this.ingredients = ingredients; }
|
||||
|
||||
public List<StepDto> getSteps() { return steps; }
|
||||
public void setSteps(List<StepDto> 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; }
|
||||
}
|
||||
@@ -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<IngredientDto> ingredients;
|
||||
|
||||
@NotNull(message = "steps list is required")
|
||||
@Valid
|
||||
private List<StepDto> 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<IngredientDto> getIngredients() { return ingredients; }
|
||||
public void setIngredients(List<IngredientDto> ingredients) { this.ingredients = ingredients; }
|
||||
|
||||
public List<StepDto> getSteps() { return steps; }
|
||||
public void setSteps(List<StepDto> steps) { this.steps = steps; }
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.example.demo.dto;
|
||||
|
||||
public class RegisterRequest {
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<RecipeIngredient> 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<RecipeIngredient> getRecipeIngredients() {
|
||||
return recipeIngredients;
|
||||
}
|
||||
|
||||
public void setRecipeIngredients(Set<RecipeIngredient> recipeIngredients) {
|
||||
this.recipeIngredients = recipeIngredients;
|
||||
}
|
||||
}
|
||||
@@ -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<RecipeIngredient> recipeIngredients = new HashSet<>();
|
||||
|
||||
// Recipe Steps relationship
|
||||
@OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
||||
private Set<Step> steps = new HashSet<>();
|
||||
|
||||
// Recipe Images relationship
|
||||
@OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
||||
private Set<Image> 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<Tag> tags = new HashSet<>();
|
||||
|
||||
// User is the manager for this relationship
|
||||
@ManyToMany(fetch = FetchType.LAZY, mappedBy = "FavRecipes")
|
||||
private Set<User> 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<RecipeIngredient> getRecipeIngredients() {
|
||||
return recipeIngredients;
|
||||
}
|
||||
|
||||
public void setRecipeIngredients(Set<RecipeIngredient> recipeIngredients) {
|
||||
this.recipeIngredients = recipeIngredients;
|
||||
}
|
||||
|
||||
public Set<Step> getSteps() {
|
||||
return steps;
|
||||
}
|
||||
|
||||
public void setSteps(Set<Step> steps) {
|
||||
this.steps = steps;
|
||||
}
|
||||
|
||||
public Set<Image> getImages() {
|
||||
return images;
|
||||
}
|
||||
|
||||
public void setImages(Set<Image> images) {
|
||||
this.images = images;
|
||||
}
|
||||
|
||||
public Set<Tag> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(Set<Tag> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
public Set<User> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
public void setUsers(Set<User> users) {
|
||||
this.users = users;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<Recipe> 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<Recipe> getRecipes() {
|
||||
return recipes;
|
||||
}
|
||||
|
||||
public void setRecipes(Set<Recipe> recipes) {
|
||||
this.recipes = recipes;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<Recipe> recipes = new HashSet<>();
|
||||
|
||||
@ManyToMany(fetch = FetchType.LAZY)
|
||||
@JoinTable(
|
||||
name = "favorites",
|
||||
joinColumns = { @JoinColumn(name = "userId") },
|
||||
inverseJoinColumns = { @JoinColumn(name = "recipeId") }
|
||||
)
|
||||
private Set<Recipe> FavRecipes = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> 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<Recipe> getRecipes() {
|
||||
return recipes;
|
||||
}
|
||||
|
||||
public void setRecipes(Set<Recipe> recipes) {
|
||||
this.recipes = recipes;
|
||||
}
|
||||
|
||||
public Set<Recipe> getFavRecipes() {
|
||||
return FavRecipes;
|
||||
}
|
||||
|
||||
public void setFavRecipes(Set<Recipe> favRecipes) {
|
||||
this.FavRecipes = favRecipes;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.example.demo.exception;
|
||||
|
||||
public class BadRequestException {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.example.demo.exception;
|
||||
|
||||
public class ErrorResponse {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.example.demo.exception;
|
||||
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<Favorite, FavoriteId> {
|
||||
|
||||
}
|
||||
@@ -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<Image, Integer> {
|
||||
|
||||
}
|
||||
@@ -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<Ingredient, Integer> {
|
||||
Optional<Ingredient> findByNameIgnoreCase(String name);
|
||||
}
|
||||
@@ -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<RecipeIngredient, Integer> {
|
||||
// Custom query: find all ingredients for a recipe
|
||||
List<RecipeIngredient> findByRecipeId(Integer recipeId);
|
||||
void deleteByRecipe(Recipe recipe);
|
||||
}
|
||||
@@ -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<Recipe, Integer> {
|
||||
|
||||
List<Recipe> findByTitleContainingIgnoreCase(String name);
|
||||
List<Recipe> findByTitleContainingIgnoreCaseAndTags_NameIn(String title, List<String> tags);
|
||||
|
||||
long countByUserIdAndCreatedAtAfter(Integer userId, LocalDateTime after);
|
||||
|
||||
List<Recipe> findByUserId(Integer userId);
|
||||
|
||||
}
|
||||
@@ -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<RecipeTag, RecipeTagId> {
|
||||
|
||||
}
|
||||
@@ -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<Step, Integer> {
|
||||
|
||||
}
|
||||
@@ -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<Tag, Integer> {
|
||||
Optional<Tag> findByName(String name);
|
||||
}
|
||||
@@ -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<User, Integer> {
|
||||
|
||||
Optional<User> findByUsername(String username);
|
||||
|
||||
List<User> findByUsernameContainingIgnoreCase(String name);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
public class AuthService {
|
||||
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
@@ -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<RecipeIngredientDto> ingredientDtos = recipe.getRecipeIngredients().stream()
|
||||
.map(ri -> new RecipeIngredientDto(ri.getIngredient().getName(), ri.getQuantity(), ri.getUnit(),
|
||||
ri.getNotes()))
|
||||
.toList();
|
||||
|
||||
List<StepDto> stepDtos = recipe.getSteps().stream()
|
||||
.map(ri -> new StepDto(ri.getStepNumber(), ri.getInstruction())).toList();
|
||||
|
||||
List<ImageDto> imageDtos = recipe.getImages().stream().map(ri -> new ImageDto(ri.getImageUrl())).toList();
|
||||
|
||||
List<TagDto> 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<RecipeDto> getAllRecipes() {
|
||||
|
||||
List<RecipeDto> 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<RecipeIngredientDto> updatedIngredients = recipeDto.getIngredients();
|
||||
List<RecipeIngredient> ingredientsToRemove = new ArrayList<>();
|
||||
|
||||
List<StepDto> updatedSteps = recipeDto.getSteps();
|
||||
List<Step> stepsToRemove = new ArrayList<>();
|
||||
|
||||
List<ImageDto> updatedImages = recipeDto.getImages();
|
||||
List<Image> imagesToRemove = new ArrayList<>();
|
||||
|
||||
List<TagDto> updatedTags = recipeDto.getTags();
|
||||
List<Tag> 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<RecipeDto> getRecipes(String name, List<String> tags) {
|
||||
|
||||
List<Recipe> 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<RecipeDto> recipeList = new ArrayList<>();
|
||||
|
||||
for (Recipe recipe : recipes) {
|
||||
RecipeDto dto = convertToDto(recipe);
|
||||
recipeList.add(dto);
|
||||
}
|
||||
|
||||
return recipeList;
|
||||
}
|
||||
}
|
||||
@@ -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<UserDto> getAllUsers() {
|
||||
|
||||
List<UserDto> 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<UserDto> getUsersByName(String name) {
|
||||
List<User> users = userRepository.findByUsernameContainingIgnoreCase(name);
|
||||
|
||||
if (users.isEmpty()) {
|
||||
throw new NotFoundException("User", "username containing", name);
|
||||
}
|
||||
|
||||
List<UserDto> 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
public class MapperService {
|
||||
|
||||
}
|
||||
@@ -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<RecipeDto> getAllRecipes();
|
||||
|
||||
RecipeDto getRecipeById(Integer recipeId);
|
||||
|
||||
List<RecipeDto> getRecipes(String name, List<String> tags);
|
||||
|
||||
RecipeDto updateRecipe(RecipeDto recipedto, Integer Id, String currentUsername);
|
||||
|
||||
void deleteRecipe(Integer Id, String currentUsername);
|
||||
|
||||
}
|
||||
|
||||
@@ -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<UserDto> getAllUsers();
|
||||
|
||||
UserDto getUserById(Integer id);
|
||||
|
||||
List<UserDto> 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);
|
||||
}
|
||||
@@ -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
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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%;
|
||||
}
|
||||
}
|
||||
@@ -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%;
|
||||
}
|
||||
@@ -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%;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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%;
|
||||
}
|
||||
|
After Width: | Height: | Size: 124 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 55 KiB |
|
After Width: | Height: | Size: 53 KiB |
|
After Width: | Height: | Size: 140 KiB |
|
After Width: | Height: | Size: 140 KiB |
|
After Width: | Height: | Size: 28 KiB |
@@ -0,0 +1,101 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Create Thyme Crunch Account</title>
|
||||
<link rel="stylesheet" th:href="@{css/create-account.css}">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Delius+Swash+Caps&family=Mali:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;1,200;1,300;1,400;1,500;1,600;1,700" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header class="top-header">
|
||||
<img th:src="@{images/header_left.png}" alt="Violin f-hole shape to the left of header." class="swirl">
|
||||
<h1 class="site-name">Thyme Crunch</h1>
|
||||
<img th:src="@{images/header_right.png}" alt="Violin f-hole shape to the right of header." class="swirl">
|
||||
</header>
|
||||
|
||||
<!-- Main Content -->
|
||||
<main class="main-content">
|
||||
<div class="login-box">
|
||||
<h2>Create Account</h2>
|
||||
|
||||
<form id="createUserForm">
|
||||
<div class="rows">
|
||||
<label for="username">Username</label>
|
||||
<input type="text" id="username" required>
|
||||
</div>
|
||||
<div class="rows">
|
||||
<label for="email">Email</label>
|
||||
<input type="email" id="email" required>
|
||||
</div>
|
||||
<div class="rows">
|
||||
<label for="password">Password</label>
|
||||
<input type="password" id="password" required>
|
||||
</div>
|
||||
<div class="rows">
|
||||
<label for="confirmPassword">Confirm Password</label>
|
||||
<input type="password" id="confirmPassword" required>
|
||||
</div>
|
||||
<p id="passwordError"></p>
|
||||
|
||||
<button type="submit">Create</button>
|
||||
</form>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
|
||||
const passwordField = document.getElementById("password");
|
||||
const confirmPasswordField = document.getElementById("confirmPassword");
|
||||
|
||||
function checkPasswords() {
|
||||
|
||||
if (confirmPasswordField.value === "") {
|
||||
confirmPasswordField.classList.remove("invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
if (passwordField.value !== confirmPasswordField.value) {
|
||||
confirmPasswordField.classList.add("invalid");
|
||||
} else {
|
||||
confirmPasswordField.classList.remove("invalid");
|
||||
}
|
||||
}
|
||||
|
||||
passwordField.addEventListener("input", checkPasswords);
|
||||
confirmPasswordField.addEventListener("input", checkPasswords);
|
||||
|
||||
document.getElementById("createUserForm").addEventListener("submit", function(e) {
|
||||
|
||||
const password = passwordField.value;
|
||||
const confirmPassword = confirmPasswordField.value;
|
||||
|
||||
if (password !== confirmPassword) {
|
||||
e.preventDefault();
|
||||
confirmPasswordField.classList.add("invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
const userData = {
|
||||
username: document.getElementById("username").value,
|
||||
email: document.getElementById("email").value,
|
||||
hashedpassword: password,
|
||||
role: "USER"
|
||||
};
|
||||
|
||||
fetch("http://localhost:8080/api/users", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify(userData)
|
||||
});
|
||||
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,344 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="_csrf_header" th:content="${_csrf.headerName}"/>
|
||||
<meta name="_csrf" th:content="${_csrf.token}"/>
|
||||
<title>Create Thyme Crunch Recipe</title>
|
||||
<link rel="stylesheet" th:href="@{css/create-recipe.css}">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Delius+Swash+Caps&family=Mali:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;1,200;1,300;1,400;1,500;1,600;1,700" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header class="top-header">
|
||||
<img th:src="@{images/header_left.png}" alt="Violin f-hole shape to the left of header." class="swirl">
|
||||
<h1 class="site-name">Thyme Crunch</h1>
|
||||
<img th:src="@{images/header_right.png}" alt="Violin f-hole shape to the right of header." class="swirl">
|
||||
</header>
|
||||
|
||||
<div class="form-wrap">
|
||||
<div class="form-split">
|
||||
|
||||
<!-- Main Content -->
|
||||
<div class="form-section">
|
||||
<div class="section-title">New Recipe</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="title">Title <span class="required">*</span></label>
|
||||
<input type="text" id="title" placeholder="Your recipe title...">
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="desc">Description <span class="required">*</span></label>
|
||||
<textarea id="desc" rows="3" placeholder="Briefly describe your recipe. Who or where is it from?"></textarea>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label>Ingredients <span class="required">*</span></label>
|
||||
<div id="ingredients-container"></div>
|
||||
<button class="btn-add" id="add-ingredient-btn">+ Add ingredient</button>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label>Instructions <span class="required">*</span></label>
|
||||
<div id="steps-container"></div>
|
||||
<button class="btn-add" id="add-step-btn">+ Add step</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- Cover image / Right -->
|
||||
<div class="form-section">
|
||||
<div class="field">
|
||||
<div class="image-drop" id="drop-zone">
|
||||
<p class="upload-title">Click to upload or drag and drop an image.</p>
|
||||
</div>
|
||||
<div class="image-preview" id="preview">
|
||||
<img id="preview-img" src="" alt="Cover preview">
|
||||
<button class="remove-img" id="remove-img-btn">Remove</button>
|
||||
</div>
|
||||
<input type="file" id="img-input" accept="image/*" style="display: none;">
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="prep">Preparation Time: <span class="required">*</span></label>
|
||||
<input type="text" id="prep" placeholder="0">
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="cooking">Cooking Time: <span class="required">*</span></label>
|
||||
<input type="text" id="cooking" placeholder="0">
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="servings">Servings: <span class="required">*</span></label>
|
||||
<input type="text" id="servings" placeholder="0">
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label for="cost">Estimated Cost: <span class="required">*</span></label>
|
||||
<input type="text" id="cost" placeholder="0">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tags -->
|
||||
<div class="form-section">
|
||||
|
||||
<div class="field">
|
||||
<label>Tags</label>
|
||||
<div class="tag-input-row">
|
||||
<input type="text" id="tag-input" placeholder="Type in a tag and click Add">
|
||||
<button class="btn" id="add-tag-btn">Add</button>
|
||||
</div>
|
||||
<div class="tag-wrap" id="tag-wrap"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<button class="btn-create" id="publish-btn">CREATE</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
// ---- Ingredients ----
|
||||
const ingredientContainer = document.getElementById('ingredients-container');
|
||||
document.getElementById('add-ingredient-btn').addEventListener('click', addIngredient);
|
||||
addIngredient(); // start with one
|
||||
|
||||
function addIngredient() {
|
||||
const row = document.createElement('div');
|
||||
row.className = 'dynamic-row';
|
||||
row.innerHTML = `
|
||||
<input type="text" class="ing-name" placeholder="Ingredient (e.g. Sugar)">
|
||||
<input type="text" class="ing-qty" placeholder="Qty (e.g. 3)">
|
||||
<input type="text" class="ing-unit" placeholder="Unit (e.g. tbsp)">
|
||||
<input type="text" class="ing-notes" placeholder="Notes (optional)">
|
||||
<button class="btn-remove" title="Remove">✕</button>`;
|
||||
row.querySelector('.btn-remove').addEventListener('click', () => {
|
||||
row.remove();
|
||||
});
|
||||
ingredientContainer.appendChild(row);
|
||||
}
|
||||
|
||||
// ---- Steps ----
|
||||
const stepsContainer = document.getElementById('steps-container');
|
||||
document.getElementById('add-step-btn').addEventListener('click', addStep);
|
||||
addStep(); // start with one
|
||||
|
||||
function addStep() {
|
||||
const row = document.createElement('div');
|
||||
row.className = 'dynamic-row';
|
||||
row.innerHTML = `
|
||||
<div class="step-bubble">?</div>
|
||||
<textarea placeholder="Describe this step..."></textarea>
|
||||
<button class="btn-remove" title="Remove">✕</button>
|
||||
`;
|
||||
row.querySelector('.btn-remove').addEventListener('click', () => {
|
||||
row.remove();
|
||||
renumberSteps();
|
||||
});
|
||||
stepsContainer.appendChild(row);
|
||||
renumberSteps();
|
||||
}
|
||||
|
||||
function renumberSteps() {
|
||||
stepsContainer.querySelectorAll('.step-bubble').forEach((bubble, i) => {
|
||||
bubble.textContent = i + 1;
|
||||
});
|
||||
}
|
||||
|
||||
// ---- Collecting on submit ----
|
||||
// Call this wherever you build your POST payload:
|
||||
function getIngredients() {
|
||||
return [...ingredientContainer.querySelectorAll('.dynamic-row')].map(row => {
|
||||
qtyValue = row.querySelector('.ing-qty').value.trim(); // quantity should be a number NOT A STRING
|
||||
return {
|
||||
ingredient: {
|
||||
name: row.querySelector('.ing-name').value.trim()
|
||||
},
|
||||
quantity: Number(qtyValue),
|
||||
unit: row.querySelector('.ing-unit').value.trim(),
|
||||
notes: row.querySelector('.ing-notes').value.trim()
|
||||
};
|
||||
}).filter(item => item.ingredient.name);
|
||||
}
|
||||
|
||||
|
||||
function getSteps() {
|
||||
return [...stepsContainer.querySelectorAll('textarea')]
|
||||
.map((el, i) => ({ step_number: i + 1, instruction: el.value.trim() }))
|
||||
.filter(item => item.instruction);
|
||||
}
|
||||
|
||||
// --- Image upload ---
|
||||
const dropZone = document.getElementById('drop-zone');
|
||||
const imgInput = document.getElementById('img-input');
|
||||
|
||||
dropZone.addEventListener('click', () => imgInput.click());
|
||||
|
||||
imgInput.addEventListener('change', function () {
|
||||
if (!this.files || !this.files[0]) return;
|
||||
const url = URL.createObjectURL(this.files[0]);
|
||||
document.getElementById('preview-img').src = url;
|
||||
dropZone.style.display = 'none';
|
||||
document.getElementById('preview').style.display = 'block';
|
||||
});
|
||||
|
||||
document.getElementById('remove-img-btn').addEventListener('click', function () {
|
||||
imgInput.value = '';
|
||||
document.getElementById('preview').style.display = 'none';
|
||||
dropZone.style.display = 'block';
|
||||
});
|
||||
|
||||
// --- Tags ---
|
||||
const tags = [];
|
||||
|
||||
document.getElementById('tag-input').addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
addTag();
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById('add-tag-btn').addEventListener('click', addTag);
|
||||
|
||||
function addTag() {
|
||||
const input = document.getElementById('tag-input');
|
||||
const val = input.value.trim().toLowerCase().replace(/\s+/g, '-');
|
||||
if (!val || tags.includes(val)) { input.value = ''; return; }
|
||||
tags.push(val);
|
||||
input.value = '';
|
||||
renderTags();
|
||||
}
|
||||
|
||||
function removeTag(t) {
|
||||
tags.splice(tags.indexOf(t), 1);
|
||||
renderTags();
|
||||
}
|
||||
|
||||
function renderTags() {
|
||||
document.getElementById('tag-wrap').innerHTML = tags
|
||||
.map(t => `<div class="tag">${t} <span class="remove-tag" data-tag="${t}">✕</span></div>`)
|
||||
.join('');
|
||||
|
||||
document.querySelectorAll('.remove-tag').forEach(btn => {
|
||||
btn.addEventListener('click', () => removeTag(btn.dataset.tag));
|
||||
});
|
||||
}
|
||||
|
||||
async function getLoggedInUser() {
|
||||
try {
|
||||
const res = await fetch('http://localhost:8080/api/users/me', {
|
||||
credentials: 'include'
|
||||
});
|
||||
if (!res.ok) throw new Error('Failed to get logged-in user');
|
||||
return await res.json();
|
||||
} catch (err) {
|
||||
console.error('Error fetching user:', err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function buildRecipeJSON(user) {
|
||||
const title = document.getElementById('title').value.trim();
|
||||
const description = document.getElementById('desc').value.trim();
|
||||
const prepTimeMinutes = Number(document.getElementById('prep').value);
|
||||
const cookTimeMinutes = Number(document.getElementById('cooking').value);
|
||||
const servings = Number(document.getElementById('servings').value);
|
||||
const status = "DRAFT";
|
||||
|
||||
// Ingredients
|
||||
const recipeIngredients = [...document.querySelectorAll('#ingredients-container .dynamic-row')]
|
||||
.map(row => {
|
||||
const qtyValue = Number(row.querySelector('.ing-qty').value.trim());
|
||||
return {
|
||||
ingredient: { name: row.querySelector('.ing-name').value.trim() },
|
||||
quantity: qtyValue,
|
||||
unit: row.querySelector('.ing-unit').value.trim(),
|
||||
notes: row.querySelector('.ing-notes').value.trim()
|
||||
};
|
||||
})
|
||||
.filter(item => item.ingredient.name);
|
||||
|
||||
// Steps
|
||||
const steps = [...document.querySelectorAll('#steps-container textarea')]
|
||||
.map((el, i) => ({ stepNumber: i + 1, instruction: el.value.trim() }))
|
||||
.filter(item => item.instruction);
|
||||
|
||||
// Images
|
||||
|
||||
|
||||
// Tags
|
||||
const tagsInput = tags;
|
||||
const tagsArray = tagsInput.map(t => ({ name: t }));
|
||||
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
prepTimeMinutes,
|
||||
cookTimeMinutes,
|
||||
servings,
|
||||
status,
|
||||
user,
|
||||
recipeIngredients,
|
||||
steps,
|
||||
//images,
|
||||
tags: tagsArray
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
document.getElementById('publish-btn').addEventListener('click', async function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const user = await getLoggedInUser();
|
||||
if (!user) {
|
||||
alert("Unable to fetch logged-in user. Please refresh and try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("Logged-in user:", user);
|
||||
const recipeJSON = buildRecipeJSON(user);
|
||||
console.log("Recipe JSON to submit:", JSON.stringify(recipeJSON, null, 2));
|
||||
|
||||
try {
|
||||
|
||||
const csrfToken = document.querySelector('meta[name="_csrf"]').getAttribute('content');
|
||||
const csrfHeader = document.querySelector('meta[name="_csrf_header"]').getAttribute('content');
|
||||
|
||||
|
||||
|
||||
const res = await fetch('http://localhost:8080/api/recipes', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
[csrfHeader]: csrfToken,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(recipeJSON),
|
||||
credentials: 'include'
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
console.log("Recipe created:", data);
|
||||
alert("Recipe created successfully!");
|
||||
} else {
|
||||
const errorData = await res.json();
|
||||
console.error("Validation errors:", errorData);
|
||||
|
||||
|
||||
const firstError = Object.values(errorData)[0];
|
||||
alert(firstError);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Network error:", err);
|
||||
alert("Network error. Check console for details.");
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,75 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Thyme Crunch Home</title>
|
||||
<link rel="stylesheet" th:href="@{css/explore.css}">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Delius+Swash+Caps&family=Mali:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;1,200;1,300;1,400;1,500;1,600;1,700" rel="stylesheet">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header class="top-header">
|
||||
<img th:src="@{images/header_left.png}" alt="Violin f-hole shape to the left of header." class="swirl">
|
||||
<h1 class="site-name">Thyme Crunch</h1>
|
||||
<img th:src="@{images/header_right.png}" alt="Violin f-hole shape to the right of header." class="swirl">
|
||||
</header>
|
||||
|
||||
<div class="body">
|
||||
<!--Navigation Bar -->
|
||||
<div class="body-left">
|
||||
<nav class="sidebar-left">
|
||||
<ul>
|
||||
<li><a href="/">Home</a></li>
|
||||
<li><a href="#">Explore</a></li>
|
||||
<li><a href="#">Profile</a></li>
|
||||
<li><a href="#">Saved</a></li>
|
||||
<li>
|
||||
<form th:action="@{/logout}" method="post">
|
||||
<input type="image" th:src="@{images/logout_icon.png}" alt="Logout button" class="nav_icon"/>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
<a th:href="@{/create}" target="_blank" class="create_icon">
|
||||
<img th:src="@{images/create_icon.png}" alt="Create New Recipe Icon (Red mixing bowl with a spoon and yellow addition symbol.">
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Main Content -->
|
||||
<main class="main-content">
|
||||
<div class="search-bar">
|
||||
<form action="/search" method="get">
|
||||
<label for="site-search">Search:</label>
|
||||
<div class="search-btn">
|
||||
<input type="search" id="site-search" name="q" placeholder="Search for recipes...">
|
||||
<button type="submit"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="recipe-card">
|
||||
|
||||
<a th:href="@{/recipes/{id}(id=${recipe.id})}" class="card" th:each="recipe : ${recipes}">
|
||||
<div class="card-text">
|
||||
<h2 th:text="${recipe.title}"></h2>
|
||||
<p th:text="${recipe.description}"></p>
|
||||
</div>
|
||||
<div class="card-right">
|
||||
<div th:each="img : ${recipe.images}">
|
||||
<img th:src="${img.imageUrl}" alt="Recipe Image"/>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<!--Filter -->
|
||||
<div class="body-right">
|
||||
<div class="sidebar-right">
|
||||
<h1> FILTER </h1>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,65 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Thyme Crunch Home</title>
|
||||
<link rel="stylesheet" th:href="@{css/home.css}">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Delius+Swash+Caps&family=Mali:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;1,200;1,300;1,400;1,500;1,600;1,700" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header class="top-header">
|
||||
<img th:src="@{images/header_left.png}" alt="Violin f-hole shape to the left of header." class="swirl">
|
||||
<h1 class="site-name">Thyme Crunch</h1>
|
||||
<img th:src="@{images/header_right.png}" alt="Violin f-hole shape to the right of header." class="swirl">
|
||||
</header>
|
||||
|
||||
<div class="body">
|
||||
<!--Navigation Bar -->
|
||||
<div class="body-left">
|
||||
<nav class="sidebar-left">
|
||||
<ul>
|
||||
<li><a href="/">Home</a></li>
|
||||
<li><a th:href="@{/explore}">Explore</a></li>
|
||||
<li><a href="#">Profile</a></li>
|
||||
<li><a href="#">Saved</a></li>
|
||||
<li>
|
||||
<form th:action="@{/logout}" method="post">
|
||||
<input type="image" th:src="@{images/logout_icon.png}" alt="Logout button" class="nav_icon"/>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
<a th:href="@{/create}" target="_blank" class="create_icon">
|
||||
<img th:src="@{images/create_icon.png}" alt="Create New Recipe Icon (Red mixing bowl with a spoon and yellow addition symbol.">
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Main Content -->
|
||||
<main class="main-content">
|
||||
<div class="recipe-card">
|
||||
|
||||
<a th:href="@{/recipes/{id}(id=${recipe.id})}" class="card" th:each="recipe : ${recipes}">
|
||||
<div class="card-text">
|
||||
<h2 th:text="${recipe.title}"></h2>
|
||||
<p th:text="${recipe.description}"></p>
|
||||
</div>
|
||||
<div class="card-right">
|
||||
<div th:each="img : ${recipe.images}">
|
||||
<img th:src="${img.imageUrl}" alt="Recipe Image"/>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<!--New Bar -->
|
||||
<div class="body-right">
|
||||
<div class="sidebar-right">
|
||||
<h1> NEW </h1>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,41 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Thyme Crunch Login</title>
|
||||
<link rel="stylesheet" th:href="@{css/login.css}">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Delius+Swash+Caps&family=Mali:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;1,200;1,300;1,400;1,500;1,600;1,700" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header class="top-header">
|
||||
<img th:src="@{images/header_left.png}" alt="Violin f-hole shape to the left of header." class="swirl">
|
||||
<h1 class="site-name">Thyme Crunch</h1>
|
||||
<img th:src="@{images/header_right.png}" alt="Violin f-hole shape to the right of header." class="swirl">
|
||||
|
||||
</header>
|
||||
|
||||
<!-- Main Content -->
|
||||
<main class="main-content">
|
||||
<div class="login-box">
|
||||
<h2>Log In</h2>
|
||||
<div th:if="${param.error}" class="alert">
|
||||
Invalid username and password.</div>
|
||||
<div th:if="${param.logout}" class="alert">
|
||||
You have been logged out.</div>
|
||||
<form th:action="@{/login}" method="post">
|
||||
<label for="username">Username</label>
|
||||
<input type="text" id="username" name="username" required>
|
||||
|
||||
<label for="password">Password</label>
|
||||
<input type="password" id="password" name="password" required>
|
||||
|
||||
<button type="submit">Enter</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="sign_up">
|
||||
<h3> OR <a th:href="@{/register}"><b>SIGN UP</b></a> FOR AN ACCOUNT </h3>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,64 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Thyme Crunch View Recipe</title>
|
||||
<link rel="stylesheet" th:href="@{/css/view-recipe.css}">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Delius+Swash+Caps&family=Mali:ital,wght@0,200;0,300;0,400;0,500;0,600;0,700;1,200;1,300;1,400;1,500;1,600;1,700" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<header class="top-header">
|
||||
<img th:src="@{images/header_left.png}" alt="Violin f-hole shape to the left of header." class="swirl">
|
||||
<h1 class="site-name">Thyme Crunch</h1>
|
||||
<img th:src="@{images/header_right.png}" alt="Violin f-hole shape to the right of header." class="swirl">
|
||||
</header>
|
||||
|
||||
<div class="body">
|
||||
<!--Navigation Bar -->
|
||||
<div class="body-left">
|
||||
<nav class="sidebar-left">
|
||||
<ul>
|
||||
<li><a href="#">Home</a></li>
|
||||
<li><a href="#">Explore</a></li>
|
||||
<li><a href="#">Profile</a></li>
|
||||
<li><a href="#">Saved</a></li>
|
||||
<li>
|
||||
<form th:action="@{/logout}" method="post">
|
||||
<input type="image" th:src="@{images/logout_icon.png}" alt="Logout button" class="nav_icon"/>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
<a th:href="@{/create}" target="_blank" class="create_icon">
|
||||
<img th:src="@{images/create_icon.png}" alt="Description of the icon">
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Main Content -->
|
||||
<main class="main-content">
|
||||
<div class="form-wrap">
|
||||
<h1 th:text="${recipe.title}"></h1>
|
||||
<p th:text="${recipe.description}"></p>
|
||||
|
||||
<div class="form-section">
|
||||
<div class="section-title">Ingredients</div>
|
||||
<ul>
|
||||
<li th:each="ingredient : ${recipe.ingredients}"
|
||||
th:text="${ingredient.name}"></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="form-section">
|
||||
<div class="section-title">Instructions</div>
|
||||
<ol class="step-list">
|
||||
<li th:each="step : ${#lists.sort(recipe.steps, comparingInt(step -> step.stepNumber))}">
|
||||
</ol
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -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() {
|
||||
}
|
||||
|
||||
}
|
||||