fullstack
This commit is contained in:
commit
2cba766357
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
6
.idea/misc.xml
generated
Normal file
6
.idea/misc.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Hangry_Fullstack.iml" filepath="$PROJECT_DIR$/Hangry_Fullstack.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
4
.idea/vcs.xml
generated
Normal file
4
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings" defaultProject="true" />
|
||||
</project>
|
11
Hangry_Fullstack.iml
Normal file
11
Hangry_Fullstack.iml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="GENERAL_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/backend/src/main/java" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="17" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
2
backend/.gitattributes
vendored
Normal file
2
backend/.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/mvnw text eol=lf
|
||||
*.cmd text eol=crlf
|
33
backend/.gitignore
vendored
Normal file
33
backend/.gitignore
vendored
Normal file
@ -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/
|
19
backend/.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
19
backend/.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
wrapperVersion=3.3.2
|
||||
distributionType=only-script
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
|
259
backend/mvnw
vendored
Normal file
259
backend/mvnw
vendored
Normal file
@ -0,0 +1,259 @@
|
||||
#!/bin/sh
|
||||
# ----------------------------------------------------------------------------
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
# ----------------------------------------------------------------------------
|
||||
# Apache Maven Wrapper startup batch script, version 3.3.2
|
||||
#
|
||||
# Optional ENV vars
|
||||
# -----------------
|
||||
# JAVA_HOME - location of a JDK home dir, required when download maven via java source
|
||||
# MVNW_REPOURL - repo url base for downloading maven distribution
|
||||
# MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
|
||||
# MVNW_VERBOSE - true: enable verbose log; debug: trace the mvnw script; others: silence the output
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
set -euf
|
||||
[ "${MVNW_VERBOSE-}" != debug ] || set -x
|
||||
|
||||
# OS specific support.
|
||||
native_path() { printf %s\\n "$1"; }
|
||||
case "$(uname)" in
|
||||
CYGWIN* | MINGW*)
|
||||
[ -z "${JAVA_HOME-}" ] || JAVA_HOME="$(cygpath --unix "$JAVA_HOME")"
|
||||
native_path() { cygpath --path --windows "$1"; }
|
||||
;;
|
||||
esac
|
||||
|
||||
# set JAVACMD and JAVACCMD
|
||||
set_java_home() {
|
||||
# For Cygwin and MinGW, ensure paths are in Unix format before anything is touched
|
||||
if [ -n "${JAVA_HOME-}" ]; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ]; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
JAVACCMD="$JAVA_HOME/jre/sh/javac"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
JAVACCMD="$JAVA_HOME/bin/javac"
|
||||
|
||||
if [ ! -x "$JAVACMD" ] || [ ! -x "$JAVACCMD" ]; then
|
||||
echo "The JAVA_HOME environment variable is not defined correctly, so mvnw cannot run." >&2
|
||||
echo "JAVA_HOME is set to \"$JAVA_HOME\", but \"\$JAVA_HOME/bin/java\" or \"\$JAVA_HOME/bin/javac\" does not exist." >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
JAVACMD="$(
|
||||
'set' +e
|
||||
'unset' -f command 2>/dev/null
|
||||
'command' -v java
|
||||
)" || :
|
||||
JAVACCMD="$(
|
||||
'set' +e
|
||||
'unset' -f command 2>/dev/null
|
||||
'command' -v javac
|
||||
)" || :
|
||||
|
||||
if [ ! -x "${JAVACMD-}" ] || [ ! -x "${JAVACCMD-}" ]; then
|
||||
echo "The java/javac command does not exist in PATH nor is JAVA_HOME set, so mvnw cannot run." >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# hash string like Java String::hashCode
|
||||
hash_string() {
|
||||
str="${1:-}" h=0
|
||||
while [ -n "$str" ]; do
|
||||
char="${str%"${str#?}"}"
|
||||
h=$(((h * 31 + $(LC_CTYPE=C printf %d "'$char")) % 4294967296))
|
||||
str="${str#?}"
|
||||
done
|
||||
printf %x\\n $h
|
||||
}
|
||||
|
||||
verbose() { :; }
|
||||
[ "${MVNW_VERBOSE-}" != true ] || verbose() { printf %s\\n "${1-}"; }
|
||||
|
||||
die() {
|
||||
printf %s\\n "$1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
trim() {
|
||||
# MWRAPPER-139:
|
||||
# Trims trailing and leading whitespace, carriage returns, tabs, and linefeeds.
|
||||
# Needed for removing poorly interpreted newline sequences when running in more
|
||||
# exotic environments such as mingw bash on Windows.
|
||||
printf "%s" "${1}" | tr -d '[:space:]'
|
||||
}
|
||||
|
||||
# parse distributionUrl and optional distributionSha256Sum, requires .mvn/wrapper/maven-wrapper.properties
|
||||
while IFS="=" read -r key value; do
|
||||
case "${key-}" in
|
||||
distributionUrl) distributionUrl=$(trim "${value-}") ;;
|
||||
distributionSha256Sum) distributionSha256Sum=$(trim "${value-}") ;;
|
||||
esac
|
||||
done <"${0%/*}/.mvn/wrapper/maven-wrapper.properties"
|
||||
[ -n "${distributionUrl-}" ] || die "cannot read distributionUrl property in ${0%/*}/.mvn/wrapper/maven-wrapper.properties"
|
||||
|
||||
case "${distributionUrl##*/}" in
|
||||
maven-mvnd-*bin.*)
|
||||
MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/
|
||||
case "${PROCESSOR_ARCHITECTURE-}${PROCESSOR_ARCHITEW6432-}:$(uname -a)" in
|
||||
*AMD64:CYGWIN* | *AMD64:MINGW*) distributionPlatform=windows-amd64 ;;
|
||||
:Darwin*x86_64) distributionPlatform=darwin-amd64 ;;
|
||||
:Darwin*arm64) distributionPlatform=darwin-aarch64 ;;
|
||||
:Linux*x86_64*) distributionPlatform=linux-amd64 ;;
|
||||
*)
|
||||
echo "Cannot detect native platform for mvnd on $(uname)-$(uname -m), use pure java version" >&2
|
||||
distributionPlatform=linux-amd64
|
||||
;;
|
||||
esac
|
||||
distributionUrl="${distributionUrl%-bin.*}-$distributionPlatform.zip"
|
||||
;;
|
||||
maven-mvnd-*) MVN_CMD=mvnd.sh _MVNW_REPO_PATTERN=/maven/mvnd/ ;;
|
||||
*) MVN_CMD="mvn${0##*/mvnw}" _MVNW_REPO_PATTERN=/org/apache/maven/ ;;
|
||||
esac
|
||||
|
||||
# apply MVNW_REPOURL and calculate MAVEN_HOME
|
||||
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<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
|
||||
printf %s\\n "$distributionUrl" >"$TMP_DOWNLOAD_DIR/$distributionUrlNameMain/mvnw.url"
|
||||
mv -- "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" "$MAVEN_HOME" || [ -d "$MAVEN_HOME" ] || die "fail to move MAVEN_HOME"
|
||||
|
||||
clean || :
|
||||
exec_maven "$@"
|
149
backend/mvnw.cmd
vendored
Normal file
149
backend/mvnw.cmd
vendored
Normal file
@ -0,0 +1,149 @@
|
||||
<# : batch portion
|
||||
@REM ----------------------------------------------------------------------------
|
||||
@REM Licensed to the Apache Software Foundation (ASF) under one
|
||||
@REM or more contributor license agreements. See the NOTICE file
|
||||
@REM distributed with this work for additional information
|
||||
@REM regarding copyright ownership. The ASF licenses this file
|
||||
@REM to you under the Apache License, Version 2.0 (the
|
||||
@REM "License"); you may not use this file except in compliance
|
||||
@REM with the License. You may obtain a copy of the License at
|
||||
@REM
|
||||
@REM http://www.apache.org/licenses/LICENSE-2.0
|
||||
@REM
|
||||
@REM Unless required by applicable law or agreed to in writing,
|
||||
@REM software distributed under the License is distributed on an
|
||||
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
@REM KIND, either express or implied. See the License for the
|
||||
@REM specific language governing permissions and limitations
|
||||
@REM under the License.
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@REM ----------------------------------------------------------------------------
|
||||
@REM Apache Maven Wrapper startup batch script, version 3.3.2
|
||||
@REM
|
||||
@REM Optional ENV vars
|
||||
@REM MVNW_REPOURL - repo url base for downloading maven distribution
|
||||
@REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
|
||||
@REM MVNW_VERBOSE - true: enable verbose log; others: silence the output
|
||||
@REM ----------------------------------------------------------------------------
|
||||
|
||||
@IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0)
|
||||
@SET __MVNW_CMD__=
|
||||
@SET __MVNW_ERROR__=
|
||||
@SET __MVNW_PSMODULEP_SAVE=%PSModulePath%
|
||||
@SET PSModulePath=
|
||||
@FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @(
|
||||
IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B)
|
||||
)
|
||||
@SET PSModulePath=%__MVNW_PSMODULEP_SAVE%
|
||||
@SET __MVNW_PSMODULEP_SAVE=
|
||||
@SET __MVNW_ARG0_NAME__=
|
||||
@SET MVNW_USERNAME=
|
||||
@SET MVNW_PASSWORD=
|
||||
@IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*)
|
||||
@echo Cannot start maven from wrapper >&2 && exit /b 1
|
||||
@GOTO :EOF
|
||||
: end batch / begin powershell #>
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
if ($env:MVNW_VERBOSE -eq "true") {
|
||||
$VerbosePreference = "Continue"
|
||||
}
|
||||
|
||||
# calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties
|
||||
$distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl
|
||||
if (!$distributionUrl) {
|
||||
Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
|
||||
}
|
||||
|
||||
switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) {
|
||||
"maven-mvnd-*" {
|
||||
$USE_MVND = $true
|
||||
$distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip"
|
||||
$MVN_CMD = "mvnd.cmd"
|
||||
break
|
||||
}
|
||||
default {
|
||||
$USE_MVND = $false
|
||||
$MVN_CMD = $script -replace '^mvnw','mvn'
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
# apply MVNW_REPOURL and calculate MAVEN_HOME
|
||||
# maven home pattern: ~/.m2/wrapper/dists/{apache-maven-<version>,maven-mvnd-<version>-<platform>}/<hash>
|
||||
if ($env:MVNW_REPOURL) {
|
||||
$MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" }
|
||||
$distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')"
|
||||
}
|
||||
$distributionUrlName = $distributionUrl -replace '^.*/',''
|
||||
$distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$',''
|
||||
$MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain"
|
||||
if ($env:MAVEN_USER_HOME) {
|
||||
$MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain"
|
||||
}
|
||||
$MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
|
||||
$MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
|
||||
|
||||
if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
|
||||
Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
|
||||
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
|
||||
exit $?
|
||||
}
|
||||
|
||||
if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
|
||||
Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
|
||||
}
|
||||
|
||||
# prepare tmp dir
|
||||
$TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
|
||||
$TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
|
||||
$TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
|
||||
trap {
|
||||
if ($TMP_DOWNLOAD_DIR.Exists) {
|
||||
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
|
||||
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
|
||||
}
|
||||
}
|
||||
|
||||
New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
|
||||
|
||||
# Download and Install Apache Maven
|
||||
Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
|
||||
Write-Verbose "Downloading from: $distributionUrl"
|
||||
Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
|
||||
|
||||
$webclient = New-Object System.Net.WebClient
|
||||
if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
|
||||
$webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
|
||||
}
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
$webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
|
||||
|
||||
# If specified, validate the SHA-256 sum of the Maven distribution zip file
|
||||
$distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
|
||||
if ($distributionSha256Sum) {
|
||||
if ($USE_MVND) {
|
||||
Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
|
||||
}
|
||||
Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash
|
||||
if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
|
||||
Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property."
|
||||
}
|
||||
}
|
||||
|
||||
# unzip and move
|
||||
Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
|
||||
Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null
|
||||
try {
|
||||
Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
|
||||
} catch {
|
||||
if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
|
||||
Write-Error "fail to move MAVEN_HOME"
|
||||
}
|
||||
} finally {
|
||||
try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
|
||||
catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
|
||||
}
|
||||
|
||||
Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
|
114
backend/pom.xml
Normal file
114
backend/pom.xml
Normal file
@ -0,0 +1,114 @@
|
||||
<?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>3.4.2</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>hangry</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>hangry</name>
|
||||
<description>Hangry project for Spring Boot</description>
|
||||
<url/>
|
||||
<licenses>
|
||||
<license/>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer/>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection/>
|
||||
<developerConnection/>
|
||||
<tag/>
|
||||
<url/>
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<scope>runtime</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- Spring Security für Passwort-Hashing -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- JJWT API -->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-api</artifactId>
|
||||
<version>0.11.5</version>
|
||||
</dependency>
|
||||
|
||||
<!-- JJWT Implementierung (zur Laufzeit) -->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-impl</artifactId>
|
||||
<version>0.11.5</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- JJWT Jackson für JSON-Verarbeitung (zur Laufzeit) -->
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-jackson</artifactId>
|
||||
<version>0.11.5</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot Validation für Request-Validierung -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Lombok (Optional, aber erleichtert die Code-Generierung) -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,13 @@
|
||||
package com.example.backend;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class BackendApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(BackendApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
78
backend/src/main/java/com/example/backend/Group.java
Normal file
78
backend/src/main/java/com/example/backend/Group.java
Normal file
@ -0,0 +1,78 @@
|
||||
package com.example.backend;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Entity
|
||||
@Table(name = "`group`")
|
||||
public class Group {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(
|
||||
name = "group_users",
|
||||
joinColumns = @JoinColumn(name = "group_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "user_id")
|
||||
)
|
||||
private Set<User> members = new HashSet<>();
|
||||
|
||||
@OneToMany(mappedBy = "group", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private Set<GroupRecipe> sharedRecipes = new HashSet<>();
|
||||
|
||||
public Group() {}
|
||||
|
||||
public Group(String name, String description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
// Getter und Setter
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public Set<User> getMembers() {
|
||||
return members;
|
||||
}
|
||||
|
||||
public Set<GroupRecipe> getSharedRecipes() {
|
||||
return sharedRecipes;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public void setMembers(Set<User> members) {
|
||||
this.members = members;
|
||||
}
|
||||
|
||||
public void setSharedRecipes(Set<GroupRecipe> sharedRecipes) {
|
||||
this.sharedRecipes = sharedRecipes;
|
||||
}
|
||||
}
|
51
backend/src/main/java/com/example/backend/GroupRecipe.java
Normal file
51
backend/src/main/java/com/example/backend/GroupRecipe.java
Normal file
@ -0,0 +1,51 @@
|
||||
package com.example.backend;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
public class GroupRecipe {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "group_id", nullable = false)
|
||||
private Group group;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "recipe_id", nullable = false)
|
||||
private Recipe recipe;
|
||||
|
||||
public GroupRecipe() {}
|
||||
|
||||
public GroupRecipe(Group group, Recipe recipe) {
|
||||
this.group = group;
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
// Getter und Setter
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Group getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public Recipe getRecipe() {
|
||||
return recipe;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setGroup(Group group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public void setRecipe(Recipe recipe) {
|
||||
this.recipe = recipe;
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.example.backend;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface GroupRecipeRepository extends JpaRepository<GroupRecipe, Long> {
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.example.backend;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface GroupRepository extends JpaRepository<Group, Long> {
|
||||
}
|
60
backend/src/main/java/com/example/backend/Ingredient.java
Normal file
60
backend/src/main/java/com/example/backend/Ingredient.java
Normal file
@ -0,0 +1,60 @@
|
||||
package com.example.backend;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
public class Ingredient {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private String name; // Name der Zutat
|
||||
|
||||
private boolean isGlobal; // Flag, ob die Zutat global ist (true) oder benutzerspezifisch (false)
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "user_id") // Verknüpft mit der 'User'-Tabelle
|
||||
private User user; // Hinzufügen einer 'user'-Beziehung
|
||||
|
||||
public Ingredient() {
|
||||
}
|
||||
|
||||
public Ingredient(String name, boolean isGlobal) {
|
||||
this.name = name;
|
||||
this.isGlobal = isGlobal;
|
||||
}
|
||||
|
||||
// Getter und Setter
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public boolean isGlobal() {
|
||||
return isGlobal;
|
||||
}
|
||||
|
||||
public void setGlobal(boolean global) {
|
||||
isGlobal = global;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.example.backend;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface IngredientRepository extends JpaRepository<Ingredient, Long> {
|
||||
|
||||
// 1. Alle globalen Zutaten abrufen
|
||||
List<Ingredient> findByIsGlobal(boolean isGlobal);
|
||||
|
||||
// 2. Zutaten, die einem bestimmten Benutzer gehören, abrufen
|
||||
List<Ingredient> findByUserId(Long userId);
|
||||
|
||||
// 3. Zutaten suchen, die global und/oder benutzerdefiniert nach Name passen
|
||||
List<Ingredient> findByNameContainingIgnoreCase(String name);
|
||||
|
||||
// 4. Benutzerdefinierte Zutat für einen bestimmten Benutzer nach Namen abrufen
|
||||
List<Ingredient> findByNameAndUserId(String name, Long userId);
|
||||
|
||||
// 5. Überprüfen, ob eine Zutat global existiert
|
||||
boolean existsByNameAndIsGlobal(String name, boolean isGlobal);
|
||||
}
|
||||
|
66
backend/src/main/java/com/example/backend/Like.java
Normal file
66
backend/src/main/java/com/example/backend/Like.java
Normal file
@ -0,0 +1,66 @@
|
||||
package com.example.backend;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
@Entity
|
||||
@Table(name = "`likes`")
|
||||
public class Like {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "user_id", nullable = false)
|
||||
private User user;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "recipe_id", nullable = false)
|
||||
private Recipe recipe;
|
||||
|
||||
private LocalDateTime createdAt = LocalDateTime.now();
|
||||
|
||||
// Konstruktoren, Getter & Setter#
|
||||
|
||||
public Like(){}
|
||||
public Like( User user, Recipe recipe) {
|
||||
this.user = user;
|
||||
this.recipe = recipe;
|
||||
this.createdAt=LocalDateTime.now();
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public Recipe getRecipe() {
|
||||
return recipe;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public void setRecipe(Recipe recipe) {
|
||||
this.recipe = recipe;
|
||||
}
|
||||
|
||||
public void setCreatedAt(LocalDateTime createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
package com.example.backend;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface LikeRepository extends JpaRepository<Like, Long> {
|
||||
boolean existsByUserAndRecipe(User user, Recipe recipe);
|
||||
|
||||
long countByRecipe(Recipe recipe);
|
||||
|
||||
List<Like> findAllByUser(User user);
|
||||
|
||||
void deleteByUserAndRecipe(User user, Recipe recipe);
|
||||
|
||||
}
|
||||
|
57
backend/src/main/java/com/example/backend/Recipe.java
Normal file
57
backend/src/main/java/com/example/backend/Recipe.java
Normal file
@ -0,0 +1,57 @@
|
||||
package com.example.backend;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
public class Recipe {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
private String category;
|
||||
private String imageUrl;
|
||||
|
||||
@OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private List<RecipeIngredient> recipeIngredients;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "user_id", nullable = false) // Hier verbinden wir Recipe mit User
|
||||
private User user;
|
||||
|
||||
public Recipe() {}
|
||||
|
||||
public Recipe(String name, String description, String category, String imageUrl, User user) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.category = category;
|
||||
this.imageUrl = imageUrl;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
// Getter und Setter
|
||||
public Long getId() { return id; }
|
||||
public void setId(Long id) { this.id = id; }
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public String getCategory() { return category; }
|
||||
public void setCategory(String category) { this.category = category; }
|
||||
|
||||
public String getImageUrl() { return imageUrl; }
|
||||
public void setImageUrl(String imageUrl) { this.imageUrl = imageUrl; }
|
||||
|
||||
public List<RecipeIngredient> getRecipeIngredients() { return recipeIngredients; }
|
||||
public void setRecipeIngredients(List<RecipeIngredient> recipeIngredients) { this.recipeIngredients = recipeIngredients; }
|
||||
|
||||
public User getUser() { return user; }
|
||||
public void setUser(User user) { this.user = user; }
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package com.example.backend;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
public class RecipeIngredient {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "recipe_id", nullable = false)
|
||||
private Recipe recipe;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "ingredient_id", nullable = false)
|
||||
private Ingredient ingredient;
|
||||
|
||||
private String amount; // Menge, z. B. "200 g"
|
||||
private String unit; // Einheit, z. B. "g", "ml", "Stück"
|
||||
|
||||
public RecipeIngredient() {
|
||||
}
|
||||
|
||||
public RecipeIngredient(Recipe recipe, Ingredient ingredient, String amount, String unit) {
|
||||
this.recipe = recipe;
|
||||
this.ingredient = ingredient;
|
||||
this.amount = amount;
|
||||
this.unit = unit;
|
||||
}
|
||||
|
||||
// Getter und Setter
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long 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 String getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public void setAmount(String amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
public String getUnit() {
|
||||
return unit;
|
||||
}
|
||||
|
||||
public void setUnit(String unit) {
|
||||
this.unit = unit;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.example.backend;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface RecipeRepository extends JpaRepository<Recipe, Long> {
|
||||
// Filtert Rezepte nach Kategorie (z. B. vegan, vegetarisch, einfach)
|
||||
Page<Recipe> findByCategoryIgnoreCase(String category, Pageable pageable);
|
||||
|
||||
Page<Recipe> findByUser_Id(long userID, Pageable pageable);
|
||||
List<Recipe> findByUser_Id(long userID);
|
||||
|
||||
// Sucht nach Rezepten, die eine bestimmte Zutat enthalten
|
||||
@Query("SELECT r FROM Recipe r JOIN r.recipeIngredients i WHERE LOWER(i.ingredient.name) LIKE LOWER(CONCAT('%', :ingredient, '%'))")
|
||||
Page<Recipe> findByIngredient(@Param("ingredient") String ingredient, Pageable pageable);
|
||||
|
||||
}
|
106
backend/src/main/java/com/example/backend/User.java
Normal file
106
backend/src/main/java/com/example/backend/User.java
Normal file
@ -0,0 +1,106 @@
|
||||
package com.example.backend;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
public class User {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(unique = true, nullable = false)
|
||||
private String username;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String password; // Hier solltest du sicherstellen, dass das Passwort verschlüsselt wird
|
||||
|
||||
@Column(unique = true, nullable = false)
|
||||
private String email;
|
||||
|
||||
private String role; // Für Rollen wie "ADMIN", "USER", etc.
|
||||
|
||||
// Many-to-Many Beziehung zu Ingredients
|
||||
@ManyToMany
|
||||
@JoinTable(
|
||||
name = "user_ingredients",
|
||||
joinColumns = @JoinColumn(name = "user_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "ingredient_id")
|
||||
)
|
||||
private List<Ingredient> ingredients = new ArrayList<>();
|
||||
|
||||
// No-Args-Konstruktor (wichtig für JPA)
|
||||
public User() {
|
||||
}
|
||||
|
||||
// All-Args-Konstruktor
|
||||
public User(Long id, String username, String password, String email, String role) {
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.email = email;
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
// Getter und Setter
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public List<Ingredient> getIngredients() {
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
public void setIngredients(List<Ingredient> ingredients) {
|
||||
this.ingredients = ingredients;
|
||||
}
|
||||
|
||||
// Methode, um eine Zutat zu einem User hinzuzufügen
|
||||
public void addIngredient(Ingredient ingredient) {
|
||||
this.ingredients.add(ingredient);
|
||||
}
|
||||
|
||||
// Methode, um eine Zutat aus der Liste zu entfernen
|
||||
public void removeIngredient(Ingredient ingredient) {
|
||||
this.ingredients.remove(ingredient);
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.example.backend;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface UserRepository extends JpaRepository<User, Long> {
|
||||
|
||||
// Benutzerdefinierte Abfrage: Benutzer nach Benutzernamen finden
|
||||
Optional<User> findByUsername(String username);
|
||||
|
||||
// Benutzerdefinierte Abfrage: Benutzer nach E-Mail finden
|
||||
Optional<User> findByEmail(String email);
|
||||
}
|
||||
|
@ -0,0 +1,46 @@
|
||||
package com.example.backend.controller;
|
||||
|
||||
import com.example.backend.User;
|
||||
import com.example.backend.services.JwtService;
|
||||
import com.example.backend.services.UserService;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
|
||||
@CrossOrigin (origins = "*")
|
||||
@RestController
|
||||
@RequestMapping("/api/auth")
|
||||
public class AuthController {
|
||||
|
||||
private final UserService userService;
|
||||
private final JwtService jwtService;
|
||||
|
||||
public AuthController(UserService userService, JwtService jwtService) {
|
||||
this.userService = userService;
|
||||
this.jwtService = jwtService;
|
||||
}
|
||||
|
||||
@PostMapping("/register")
|
||||
public ResponseEntity<?> register(@RequestBody User user) {
|
||||
if (userService.getUserByEmail(user.getEmail()) != null) {
|
||||
return ResponseEntity.badRequest().body("Email bereits vergeben!");
|
||||
}
|
||||
if (userService.getUserByUsername(user.getUsername()) != null) {
|
||||
return ResponseEntity.badRequest().body("Username bereits vergeben!");
|
||||
}
|
||||
User newUser = userService.createUser(user);
|
||||
return ResponseEntity.ok(newUser);
|
||||
}
|
||||
|
||||
@PostMapping("/login")
|
||||
public ResponseEntity<?> login(@RequestBody User loginRequest) {
|
||||
User user = userService.getUserByEmail(loginRequest.getEmail());
|
||||
if (user != null && userService.checkPassword(loginRequest.getPassword(), user.getPassword())) {
|
||||
String token = jwtService.generateToken(user); // JWT erstellen
|
||||
return ResponseEntity.ok(Collections.singletonMap("token",token)); // Token zurückgeben
|
||||
}
|
||||
return ResponseEntity.status(401).body(Collections.singletonMap("error","Login Fehlgeschlagen!"));
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.example.backend.controller;
|
||||
|
||||
import com.example.backend.Group;
|
||||
import com.example.backend.User;
|
||||
import com.example.backend.services.GroupService;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Set;
|
||||
@RestController
|
||||
@RequestMapping("/api/groups")
|
||||
@CrossOrigin(origins = "*")
|
||||
public class GroupController {
|
||||
|
||||
private final GroupService groupService;
|
||||
|
||||
public GroupController(GroupService groupService) {
|
||||
this.groupService = groupService;
|
||||
}
|
||||
|
||||
// Neue Gruppe erstellen
|
||||
@PostMapping
|
||||
public ResponseEntity<Group> createGroup(@RequestParam String name, @RequestParam String description) {
|
||||
return ResponseEntity.ok(groupService.createGroup(name, description));
|
||||
}
|
||||
|
||||
// Gruppe beitreten
|
||||
@PostMapping("/{groupId}/join/{userId}")
|
||||
public ResponseEntity<String> joinGroup(@PathVariable Long groupId, @PathVariable Long userId) {
|
||||
boolean joined = groupService.joinGroup(userId, groupId);
|
||||
return joined ? ResponseEntity.ok("Gruppe beigetreten") : ResponseEntity.badRequest().body("Bereits Mitglied");
|
||||
}
|
||||
|
||||
// Gruppe verlassen
|
||||
@PostMapping("/{groupId}/leave/{userId}")
|
||||
public ResponseEntity<String> leaveGroup(@PathVariable Long groupId, @PathVariable Long userId) {
|
||||
boolean left = groupService.leaveGroup(userId, groupId);
|
||||
return left ? ResponseEntity.ok("Gruppe verlassen") : ResponseEntity.badRequest().body("Nicht in der Gruppe");
|
||||
}
|
||||
|
||||
// Mitglieder einer Gruppe abrufen
|
||||
@GetMapping("/{groupId}/members")
|
||||
public ResponseEntity<Set<User>> getGroupMembers(@PathVariable Long groupId) {
|
||||
return ResponseEntity.ok(groupService.getGroupMembers(groupId));
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.example.backend.controller;
|
||||
|
||||
|
||||
import com.example.backend.Recipe;
|
||||
import com.example.backend.services.GroupRecipeService;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/group-recipes")
|
||||
@CrossOrigin(origins = "*")
|
||||
public class GroupRecipeController {
|
||||
|
||||
private final GroupRecipeService groupRecipeService;
|
||||
|
||||
public GroupRecipeController(GroupRecipeService groupRecipeService) {
|
||||
this.groupRecipeService = groupRecipeService;
|
||||
}
|
||||
|
||||
@PostMapping("/{groupId}/share/{recipeId}")
|
||||
public ResponseEntity<String> shareRecipe(@PathVariable Long groupId, @PathVariable Long recipeId) {
|
||||
boolean shared = groupRecipeService.shareRecipeWithGroup(groupId, recipeId);
|
||||
return shared ? ResponseEntity.ok("Rezept geteilt") : ResponseEntity.badRequest().body("Fehler beim Teilen");
|
||||
}
|
||||
|
||||
@GetMapping("/{groupId}")
|
||||
public ResponseEntity<Set<Recipe>> getGroupRecipes(@PathVariable Long groupId) {
|
||||
return ResponseEntity.ok(groupRecipeService.getGroupRecipes(groupId));
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.example.backend.controller;
|
||||
|
||||
import com.example.backend.Ingredient;
|
||||
import com.example.backend.services.IngredientService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/ingredients")
|
||||
public class IngredientController {
|
||||
|
||||
@Autowired
|
||||
private IngredientService ingredientService;
|
||||
|
||||
// Globale Zutaten abrufen
|
||||
@GetMapping("/global")
|
||||
public List<Ingredient> getGlobalIngredients() {
|
||||
return ingredientService.getGlobalIngredients();
|
||||
}
|
||||
|
||||
// Benutzerspezifische Zutaten abrufen
|
||||
@GetMapping("/user/{userId}")
|
||||
public List<Ingredient> getUserIngredients(@PathVariable Long userId) {
|
||||
return ingredientService.getUserIngredients(userId);
|
||||
}
|
||||
|
||||
// Neue globale Zutat hinzufügen
|
||||
@PostMapping("/global")
|
||||
public Ingredient addGlobalIngredient(@RequestBody Ingredient ingredient) {
|
||||
return ingredientService.addGlobalIngredient(ingredient);
|
||||
}
|
||||
|
||||
// Neue benutzerspezifische Zutat hinzufügen
|
||||
@PostMapping("/user/{userId}")
|
||||
public ResponseEntity<Ingredient> addUserIngredient(@PathVariable Long userId, @RequestBody Ingredient ingredient) {
|
||||
try {
|
||||
Ingredient newIngredient = ingredientService.addUserIngredient(userId, ingredient);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(newIngredient);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Falls die Zutat bereits global existiert
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.example.backend.controller;
|
||||
|
||||
import com.example.backend.Recipe;
|
||||
import com.example.backend.services.LikeService;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
@RestController
|
||||
@RequestMapping("/api/likes")
|
||||
@CrossOrigin(origins = "*")
|
||||
public class LikeController {
|
||||
|
||||
private final LikeService likeService;
|
||||
|
||||
public LikeController(LikeService likeService) {
|
||||
this.likeService = likeService;
|
||||
}
|
||||
|
||||
// Rezept liken
|
||||
@PostMapping("/{userId}/{recipeId}")
|
||||
public ResponseEntity<String> likeRecipe(@PathVariable Long userId, @PathVariable Long recipeId) {
|
||||
boolean liked = likeService.likeRecipe(userId, recipeId);
|
||||
return liked ? ResponseEntity.ok("Rezept geliked") : ResponseEntity.badRequest().body("Bereits geliked");
|
||||
}
|
||||
|
||||
// Rezept entliken
|
||||
@DeleteMapping("/{userId}/{recipeId}")
|
||||
public ResponseEntity<String> unlikeRecipe(@PathVariable Long userId, @PathVariable Long recipeId) {
|
||||
boolean unliked = likeService.unlikeRecipe(userId, recipeId);
|
||||
return unliked ? ResponseEntity.ok("Like entfernt") : ResponseEntity.badRequest().body("Like existiert nicht");
|
||||
}
|
||||
|
||||
// Anzahl der Likes für ein Rezept abrufen
|
||||
@GetMapping("/count/{recipeId}")
|
||||
public ResponseEntity<Long> getLikeCount(@PathVariable Long recipeId) {
|
||||
return ResponseEntity.ok(likeService.getLikeCount(recipeId));
|
||||
}
|
||||
|
||||
// Alle geliketen Rezepte eines Users abrufen
|
||||
@GetMapping("/user/{userId}")
|
||||
public ResponseEntity<List<Recipe>> getLikedRecipes(@PathVariable Long userId) {
|
||||
return ResponseEntity.ok(likeService.getLikedRecipes(userId));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,76 @@
|
||||
package com.example.backend.controller;
|
||||
|
||||
import com.example.backend.Recipe;
|
||||
import com.example.backend.services.RecipeService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Optional;
|
||||
@RestController
|
||||
@RequestMapping("/api/recipes")
|
||||
@CrossOrigin(origins = "*") // Erlaubt CORS für alle Domains, kann angepasst werden
|
||||
public class RecipeController {
|
||||
|
||||
private final RecipeService recipeService;
|
||||
|
||||
public RecipeController(RecipeService recipeService) {
|
||||
this.recipeService = recipeService;
|
||||
}
|
||||
|
||||
// Alle Rezepte mit Pagination abrufen
|
||||
@GetMapping
|
||||
public Page<Recipe> getAllRecipes(Pageable pageable) {
|
||||
return recipeService.getAllRecipes(pageable);
|
||||
}
|
||||
|
||||
// Einzelnes Rezept nach ID abrufen
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<Recipe> getRecipeById(@PathVariable Long id) {
|
||||
Optional<Recipe> recipe = recipeService.getRecipeById(id);
|
||||
return recipe.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
|
||||
}
|
||||
// Endpunkt: Eigene Rezepte abrufen
|
||||
@GetMapping("/user/{userId}")
|
||||
public Page<Recipe> getRecipesByUser(@PathVariable Long userId, Pageable pageable) {
|
||||
return recipeService.getRecipesByUser(userId, pageable);
|
||||
}
|
||||
|
||||
|
||||
// Neues Rezept erstellen
|
||||
@PostMapping
|
||||
public ResponseEntity<Recipe> createRecipe(@RequestBody Recipe recipe) {
|
||||
Recipe savedRecipe = recipeService.createRecipe(recipe);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(savedRecipe);
|
||||
}
|
||||
|
||||
// Rezept aktualisieren
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<Recipe> updateRecipe(@PathVariable Long id, @RequestBody Recipe recipe) {
|
||||
Optional<Recipe> updatedRecipe = recipeService.updateRecipe(id, recipe);
|
||||
return updatedRecipe.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build());
|
||||
}
|
||||
|
||||
// Rezept löschen
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteRecipe(@PathVariable Long id) {
|
||||
if (recipeService.deleteRecipe(id)) {
|
||||
return ResponseEntity.noContent().build();
|
||||
} else {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
//Endpunkt: Filter nach Kategorie (z. B. "/api/recipes/filter/category?category=vegan")
|
||||
@GetMapping("/filter/category")
|
||||
public Page<Recipe> getRecipesByCategory(@RequestParam String category, Pageable pageable) {
|
||||
return recipeService.getRecipesByCategory(category, pageable);
|
||||
}
|
||||
|
||||
// Endpunkt: Filter nach Zutat (z. B. "/api/recipes/filter/ingredient?ingredient=tomate")
|
||||
@GetMapping("/filter/ingredient")
|
||||
public Page<Recipe> getRecipesByIngredient(@RequestParam String ingredient, Pageable pageable) {
|
||||
return recipeService.getRecipesByIngredient(ingredient, pageable);
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.example.backend.controller;
|
||||
|
||||
import com.example.backend.User;
|
||||
import com.example.backend.services.UserService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/users")
|
||||
public class UserController {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
public UserController(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
// Endpunkt: Benutzer erstellen
|
||||
@PostMapping
|
||||
public User createUser(@RequestBody User user) {
|
||||
return userService.createUser(user);
|
||||
}
|
||||
|
||||
// Endpunkt: Benutzer nach Benutzername abrufen
|
||||
@GetMapping("/username/{username}")
|
||||
public User getUserByUsername(@PathVariable String username) {
|
||||
return userService.getUserByUsername(username);
|
||||
}
|
||||
|
||||
// Endpunkt: Benutzer nach E-Mail abrufen
|
||||
@GetMapping("/email/{email}")
|
||||
public User getUserByEmail(@PathVariable String email) {
|
||||
return userService.getUserByEmail(email);
|
||||
}
|
||||
|
||||
//Endpunkt: Benutzer aktualisieren
|
||||
@PutMapping("/update/email/{email}")
|
||||
public User updateUser(@PathVariable String email, @RequestBody User updatedUser) {
|
||||
return userService.updateUser(email, updatedUser);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,27 @@
|
||||
package com.example.backend.exceptions;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
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 GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(UserNotFoundException.class)
|
||||
public ResponseEntity<Map<String, String>> handleUserNotFoundException(UserNotFoundException ex) {
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("error", ex.getMessage());
|
||||
return new ResponseEntity<>(response, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ResponseEntity<Map<String, String>> handleGeneralException(Exception ex) {
|
||||
Map<String, String> response = new HashMap<>();
|
||||
response.put("error", "Ein unerwarteter Fehler ist aufgetreten.");
|
||||
return new ResponseEntity<>(response, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.example.backend.exceptions;
|
||||
|
||||
public class UserNotFoundException extends RuntimeException {
|
||||
public UserNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.example.backend.security;
|
||||
|
||||
import com.example.backend.User;
|
||||
import com.example.backend.UserRepository;
|
||||
import com.example.backend.exceptions.UserNotFoundException;
|
||||
import com.example.backend.services.JwtService;
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
@Component
|
||||
public class JwtAuthenticationFilter extends OncePerRequestFilter {
|
||||
|
||||
|
||||
private final JwtService jwtService;
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public JwtAuthenticationFilter(JwtService jwtService, UserRepository userRepository) {
|
||||
this.jwtService = jwtService;
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
|
||||
throws ServletException, IOException {
|
||||
String authHeader = request.getHeader("Authorization");
|
||||
if (authHeader != null && authHeader.startsWith("Bearer ")) {
|
||||
String token = authHeader.substring(7);
|
||||
String email = jwtService.extractEmail(token);
|
||||
if (email != null && SecurityContextHolder.getContext().getAuthentication() == null) {
|
||||
User user = userRepository.findByEmail(email).orElseThrow(() -> new UserNotFoundException("User not found"));
|
||||
if (user != null && jwtService.validateToken(token, user)) {
|
||||
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(user, null, new ArrayList<>());
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
}
|
||||
}
|
||||
}
|
||||
filterChain.doFilter(request, response);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.example.backend.security;
|
||||
|
||||
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.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity // Aktiviert Spring Security
|
||||
public class SecurityConfig {
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain securityFilterChain(HttpSecurity http, JwtAuthenticationFilter jwtAuthenticationFilter) throws Exception {
|
||||
http
|
||||
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class)
|
||||
.csrf(AbstractHttpConfigurer::disable) // Neue Syntax für CSRF-Disable
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
.requestMatchers("/api/auth/register", "/api/auth/login").permitAll() // Registrierung & Login erlauben
|
||||
.anyRequest().authenticated() // Alles andere erfordert Authentifizierung
|
||||
)
|
||||
.sessionManagement(sess -> sess.sessionCreationPolicy(SessionCreationPolicy.STATELESS)); // JWT: Keine Session
|
||||
|
||||
return http.build();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
package com.example.backend.services;
|
||||
|
||||
import com.example.backend.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@Service
|
||||
public class GroupRecipeService {
|
||||
|
||||
private final GroupRepository groupRepository;
|
||||
private final RecipeRepository recipeRepository;
|
||||
private final GroupRecipeRepository groupRecipeRepository;
|
||||
|
||||
public GroupRecipeService(GroupRepository groupRepository, RecipeRepository recipeRepository, GroupRecipeRepository groupRecipeRepository) {
|
||||
this.groupRepository = groupRepository;
|
||||
this.recipeRepository = recipeRepository;
|
||||
this.groupRecipeRepository = groupRecipeRepository;
|
||||
}
|
||||
|
||||
// Rezept mit Gruppe teilen
|
||||
public boolean shareRecipeWithGroup(Long groupId, Long recipeId) {
|
||||
Group group = groupRepository.findById(groupId)
|
||||
.orElseThrow(() -> new RuntimeException("Gruppe nicht gefunden"));
|
||||
Recipe recipe = recipeRepository.findById(recipeId)
|
||||
.orElseThrow(() -> new RuntimeException("Rezept nicht gefunden"));
|
||||
|
||||
GroupRecipe groupRecipe = new GroupRecipe(group, recipe);
|
||||
groupRecipeRepository.save(groupRecipe);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Alle Rezepte einer Gruppe abrufen
|
||||
public Set<Recipe> getGroupRecipes(Long groupId) {
|
||||
Group group = groupRepository.findById(groupId)
|
||||
.orElseThrow(() -> new RuntimeException("Gruppe nicht gefunden"));
|
||||
return group.getSharedRecipes().stream().map(GroupRecipe::getRecipe).collect(Collectors.toSet());
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package com.example.backend.services;
|
||||
|
||||
import com.example.backend.Group;
|
||||
import com.example.backend.GroupRepository;
|
||||
import com.example.backend.User;
|
||||
import com.example.backend.UserRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Set;
|
||||
@Service
|
||||
public class GroupService {
|
||||
|
||||
private final GroupRepository groupRepository;
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public GroupService(GroupRepository groupRepository, UserRepository userRepository) {
|
||||
this.groupRepository = groupRepository;
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
// Gruppe erstellen
|
||||
public Group createGroup(String name, String description) {
|
||||
Group group = new Group(name, description);
|
||||
return groupRepository.save(group);
|
||||
}
|
||||
|
||||
// Gruppe beitreten
|
||||
public boolean joinGroup(Long userId, Long groupId) {
|
||||
User user = userRepository.findById(userId)
|
||||
.orElseThrow(() -> new RuntimeException("User nicht gefunden"));
|
||||
Group group = groupRepository.findById(groupId)
|
||||
.orElseThrow(() -> new RuntimeException("Gruppe nicht gefunden"));
|
||||
|
||||
if (!group.getMembers().contains(user)) {
|
||||
group.getMembers().add(user);
|
||||
groupRepository.save(group);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Gruppe verlassen
|
||||
public boolean leaveGroup(Long userId, Long groupId) {
|
||||
User user = userRepository.findById(userId)
|
||||
.orElseThrow(() -> new RuntimeException("User nicht gefunden"));
|
||||
Group group = groupRepository.findById(groupId)
|
||||
.orElseThrow(() -> new RuntimeException("Gruppe nicht gefunden"));
|
||||
|
||||
if (group.getMembers().contains(user)) {
|
||||
group.getMembers().remove(user);
|
||||
groupRepository.save(group);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Alle Mitglieder einer Gruppe abrufen
|
||||
public Set<User> getGroupMembers(Long groupId) {
|
||||
Group group = groupRepository.findById(groupId)
|
||||
.orElseThrow(() -> new RuntimeException("Gruppe nicht gefunden"));
|
||||
return group.getMembers();
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.example.backend.services;
|
||||
|
||||
import com.example.backend.Ingredient;
|
||||
import com.example.backend.IngredientRepository;
|
||||
import com.example.backend.User;
|
||||
import com.example.backend.UserRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@Service
|
||||
public class IngredientService {
|
||||
|
||||
@Autowired
|
||||
private IngredientRepository ingredientRepository;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
// Globale Zutaten abrufen
|
||||
public List<Ingredient> getGlobalIngredients() {
|
||||
return ingredientRepository.findByIsGlobal(true);
|
||||
}
|
||||
|
||||
// Benutzerspezifische Zutaten abrufen
|
||||
public List<Ingredient> getUserIngredients(Long userId) {
|
||||
Optional<User> user = userRepository.findById(userId);
|
||||
if (user.isPresent()) {
|
||||
return ingredientRepository.findByUserId(userId);
|
||||
} else {
|
||||
throw new IllegalArgumentException("User not found with ID: " + userId);
|
||||
}
|
||||
}
|
||||
|
||||
// Globale Zutat hinzufügen
|
||||
public Ingredient addGlobalIngredient(Ingredient ingredient) {
|
||||
ingredient.setGlobal(true); // Zutat als global markieren
|
||||
return ingredientRepository.save(ingredient);
|
||||
}
|
||||
|
||||
// Benutzerdefinierte Zutat hinzufügen, nur wenn sie nicht global existiert
|
||||
public Ingredient addUserIngredient(Long userId, Ingredient ingredient) {
|
||||
// Zuerst prüfen, ob diese Zutat bereits global existiert
|
||||
boolean isGlobalIngredientExists = ingredientRepository.existsByNameAndIsGlobal(ingredient.getName(), true);
|
||||
|
||||
if (isGlobalIngredientExists) {
|
||||
throw new IllegalArgumentException("Zutat existiert bereits als globale Zutat.");
|
||||
}
|
||||
|
||||
Optional<User> user = userRepository.findById(userId);
|
||||
if (user.isPresent()) {
|
||||
ingredient.setGlobal(false); // Zutat als benutzerspezifisch markieren
|
||||
ingredient.setUser(user.get()); // Zutat dem Benutzer zuweisen
|
||||
return ingredientRepository.save(ingredient);
|
||||
} else {
|
||||
throw new IllegalArgumentException("User not found with ID: " + userId);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.example.backend.services;
|
||||
|
||||
import com.example.backend.User;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import io.jsonwebtoken.security.Keys;
|
||||
import org.springframework.cglib.core.internal.Function;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.security.Key;
|
||||
import java.util.Date;
|
||||
|
||||
@Service
|
||||
public class JwtService {
|
||||
|
||||
private static final String SECRET_KEY = Keys.secretKeyFor(SignatureAlgorithm.HS256).toString();
|
||||
private static final long EXPIRATION_TIME = 1000 * 60 * 60 * 24; // 24 Stunden
|
||||
|
||||
public String generateToken(User user) {
|
||||
return Jwts.builder()
|
||||
.setSubject(user.getEmail())
|
||||
.setIssuedAt(new Date())
|
||||
.setExpiration(new Date(System.currentTimeMillis() + EXPIRATION_TIME))
|
||||
.signWith(getSigningKey(), SignatureAlgorithm.HS256)
|
||||
.compact();
|
||||
}
|
||||
|
||||
public <T> T extractClaim(String token, Function<Claims, T> claimsResolver) {
|
||||
final Claims claims = extractAllClaims(token);
|
||||
return claimsResolver.apply(claims);
|
||||
}
|
||||
|
||||
private Claims extractAllClaims(String token) {
|
||||
return Jwts.parserBuilder().setSigningKey(getSigningKey()).build().parseClaimsJws(token).getBody();
|
||||
}
|
||||
|
||||
private Key getSigningKey() {
|
||||
return Keys.hmacShaKeyFor(SECRET_KEY.getBytes());
|
||||
}
|
||||
public String extractEmail(String token) {
|
||||
return extractClaim(token, Claims::getSubject); // Subject = E-Mail
|
||||
}
|
||||
public boolean validateToken(String token, User user) {
|
||||
final String email = extractEmail(token);
|
||||
return email.equals(user.getEmail()) && !isTokenExpired(token);
|
||||
}
|
||||
private boolean isTokenExpired(String token) {
|
||||
return extractClaim(token, Claims::getExpiration).before(new Date());
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package com.example.backend.services;
|
||||
|
||||
import com.example.backend.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class LikeService {
|
||||
|
||||
private final LikeRepository likeRepository;
|
||||
private final RecipeRepository recipeRepository;
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public LikeService(LikeRepository likeRepository, RecipeRepository recipeRepository, UserRepository userRepository) {
|
||||
this.likeRepository = likeRepository;
|
||||
this.recipeRepository = recipeRepository;
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
// Rezept liken
|
||||
public boolean likeRecipe(Long userId, Long recipeId) {
|
||||
User user = userRepository.findById(userId).orElseThrow();
|
||||
Recipe recipe = recipeRepository.findById(recipeId).orElseThrow();
|
||||
|
||||
if (likeRepository.existsByUserAndRecipe(user, recipe)) {
|
||||
return false; // Bereits geliked
|
||||
}
|
||||
|
||||
Like like = new Like();
|
||||
like.setUser(user);
|
||||
like.setRecipe(recipe);
|
||||
likeRepository.save(like);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Rezept entliken
|
||||
@Transactional
|
||||
public boolean unlikeRecipe(Long userId, Long recipeId) {
|
||||
User user = userRepository.findById(userId)
|
||||
.orElseThrow(() -> new RuntimeException("User nicht gefunden"));
|
||||
Recipe recipe = recipeRepository.findById(recipeId)
|
||||
.orElseThrow(() -> new RuntimeException("Rezept nicht gefunden"));
|
||||
|
||||
// Prüfen, ob das Like existiert
|
||||
if (!likeRepository.existsByUserAndRecipe(user, recipe)) {
|
||||
return false; // Like existiert nicht
|
||||
}
|
||||
|
||||
likeRepository.deleteByUserAndRecipe(user, recipe);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Anzahl der Likes für ein Rezept abrufen
|
||||
public long getLikeCount(Long recipeId) {
|
||||
Recipe recipe = recipeRepository.findById(recipeId).orElseThrow();
|
||||
return likeRepository.countByRecipe(recipe);
|
||||
}
|
||||
|
||||
// Alle geliketen Rezepte eines Users abrufen
|
||||
public List<Recipe> getLikedRecipes(Long userId) {
|
||||
User user = userRepository.findById(userId).orElseThrow();
|
||||
List<Like> likes = likeRepository.findAllByUser(user);
|
||||
return likes.stream().map(Like::getRecipe).toList();
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package com.example.backend.services;
|
||||
|
||||
import com.example.backend.Recipe;
|
||||
import com.example.backend.RecipeRepository;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class RecipeService {
|
||||
|
||||
private final RecipeRepository recipeRepository;
|
||||
|
||||
public RecipeService(RecipeRepository recipeRepository) {
|
||||
this.recipeRepository = recipeRepository;
|
||||
}
|
||||
|
||||
// Alle Rezepte mit Pagination abrufen
|
||||
public Page<Recipe> getAllRecipes(Pageable pageable) {
|
||||
return recipeRepository.findAll(pageable);
|
||||
}
|
||||
|
||||
// Einzelnes Rezept nach ID abrufen
|
||||
public Optional<Recipe> getRecipeById(Long id) {
|
||||
return recipeRepository.findById(id);
|
||||
}
|
||||
|
||||
// Neues Rezept erstellen
|
||||
public Recipe createRecipe(Recipe recipe) {
|
||||
return recipeRepository.save(recipe);
|
||||
}
|
||||
|
||||
// Rezept aktualisieren
|
||||
public Optional<Recipe> updateRecipe(Long id, Recipe recipeDetails) {
|
||||
return recipeRepository.findById(id).map(recipe -> {
|
||||
if (recipeDetails.getName() != null) recipe.setName(recipeDetails.getName());
|
||||
if (recipeDetails.getDescription() != null) recipe.setDescription(recipeDetails.getDescription());
|
||||
if (recipeDetails.getCategory() != null) recipe.setCategory(recipeDetails.getCategory());
|
||||
if (recipeDetails.getImageUrl() != null) recipe.setImageUrl(recipeDetails.getImageUrl());
|
||||
return recipeRepository.save(recipe);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Rezept löschen
|
||||
public boolean deleteRecipe(Long id) {
|
||||
if (recipeRepository.existsById(id)) {
|
||||
recipeRepository.deleteById(id);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//Filter nach Kategorie
|
||||
public Page<Recipe> getRecipesByCategory(String category, Pageable pageable) {
|
||||
return recipeRepository.findByCategoryIgnoreCase(category, pageable);
|
||||
}
|
||||
|
||||
//Filter nach Zutat
|
||||
public Page<Recipe> getRecipesByIngredient(String ingredient, Pageable pageable) {
|
||||
return recipeRepository.findByIngredient(ingredient, pageable);
|
||||
}
|
||||
|
||||
// Eigene Rezepte abrufen
|
||||
public Page<Recipe> getRecipesByUser(Long userId, Pageable pageable) {
|
||||
return recipeRepository.findByUser_Id(userId, pageable);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package com.example.backend.services;
|
||||
|
||||
import com.example.backend.User;
|
||||
import com.example.backend.UserRepository;
|
||||
import com.example.backend.exceptions.UserNotFoundException;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
private final PasswordEncoder passwordEncoder;
|
||||
|
||||
// Dependency Injection (Spring kümmert sich darum)
|
||||
public UserService(UserRepository userRepository) {
|
||||
this.userRepository = userRepository;
|
||||
this.passwordEncoder = new BCryptPasswordEncoder(); // Initialisierung von BCrypt
|
||||
}
|
||||
|
||||
// Neuen Benutzer erstellen (mit Passwort-Hashing)
|
||||
public User createUser(User user) {
|
||||
user.setPassword(passwordEncoder.encode(user.getPassword())); // Passwort hashen
|
||||
return userRepository.save(user);
|
||||
}
|
||||
|
||||
// Benutzer anhand des Benutzernamens suchen
|
||||
public User getUserByUsername(String username) {
|
||||
return userRepository.findByUsername(username).orElse(null);
|
||||
}
|
||||
|
||||
// Benutzer anhand der E-Mail suchen
|
||||
public User getUserByEmail(String email) {
|
||||
return userRepository.findByEmail(email).orElseThrow(()->new UserNotFoundException("User not found: "+email));
|
||||
}
|
||||
|
||||
// Passwort überprüfen
|
||||
public boolean checkPassword(String rawPassword, String hashedPassword) {
|
||||
return passwordEncoder.matches(rawPassword, hashedPassword);
|
||||
}
|
||||
public User updateUser(String email, User updatedUser) {
|
||||
User existingUser = userRepository.findByEmail(email)
|
||||
.orElseThrow(() -> new UserNotFoundException("User not found: "+email));
|
||||
|
||||
existingUser.setUsername(updatedUser.getUsername());
|
||||
// Weitere Felder falls nötig
|
||||
|
||||
return userRepository.save(existingUser);
|
||||
}
|
||||
|
||||
}
|
14
backend/src/main/resources/application.properties
Normal file
14
backend/src/main/resources/application.properties
Normal file
@ -0,0 +1,14 @@
|
||||
spring.application.name=hangry
|
||||
spring.datasource.url=jdbc:mysql://localhost:3306/hangry_app
|
||||
spring.datasource.username=root
|
||||
spring.datasource.password=
|
||||
|
||||
# Hibernate Einstellungen
|
||||
spring.jpa.show-sql=true
|
||||
spring.jpa.properties.hibernate.format_sql=true
|
||||
spring.jpa.properties.hibernate.use_sql_comments=true
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
|
||||
|
||||
server.port=8080
|
||||
server.address=0.0.0.0
|
@ -0,0 +1,13 @@
|
||||
package com.example.backend;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class BackendApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
24
frontend/.gitignore
vendored
Normal file
24
frontend/.gitignore
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
54
frontend/README.md
Normal file
54
frontend/README.md
Normal file
@ -0,0 +1,54 @@
|
||||
# React + TypeScript + Vite
|
||||
|
||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||
|
||||
Currently, two official plugins are available:
|
||||
|
||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
|
||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
||||
|
||||
## Expanding the ESLint configuration
|
||||
|
||||
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
||||
|
||||
```js
|
||||
export default tseslint.config({
|
||||
extends: [
|
||||
// Remove ...tseslint.configs.recommended and replace with this
|
||||
...tseslint.configs.recommendedTypeChecked,
|
||||
// Alternatively, use this for stricter rules
|
||||
...tseslint.configs.strictTypeChecked,
|
||||
// Optionally, add this for stylistic rules
|
||||
...tseslint.configs.stylisticTypeChecked,
|
||||
],
|
||||
languageOptions: {
|
||||
// other options...
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
||||
|
||||
```js
|
||||
// eslint.config.js
|
||||
import reactX from 'eslint-plugin-react-x'
|
||||
import reactDom from 'eslint-plugin-react-dom'
|
||||
|
||||
export default tseslint.config({
|
||||
plugins: {
|
||||
// Add the react-x and react-dom plugins
|
||||
'react-x': reactX,
|
||||
'react-dom': reactDom,
|
||||
},
|
||||
rules: {
|
||||
// other rules...
|
||||
// Enable its recommended typescript rules
|
||||
...reactX.configs['recommended-typescript'].rules,
|
||||
...reactDom.configs.recommended.rules,
|
||||
},
|
||||
})
|
||||
```
|
28
frontend/eslint.config.js
Normal file
28
frontend/eslint.config.js
Normal file
@ -0,0 +1,28 @@
|
||||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import tseslint from 'typescript-eslint'
|
||||
|
||||
export default tseslint.config(
|
||||
{ ignores: ['dist'] },
|
||||
{
|
||||
extends: [js.configs.recommended, ...tseslint.configs.recommended],
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2020,
|
||||
globals: globals.browser,
|
||||
},
|
||||
plugins: {
|
||||
'react-hooks': reactHooks,
|
||||
'react-refresh': reactRefresh,
|
||||
},
|
||||
rules: {
|
||||
...reactHooks.configs.recommended.rules,
|
||||
'react-refresh/only-export-components': [
|
||||
'warn',
|
||||
{ allowConstantExport: true },
|
||||
],
|
||||
},
|
||||
},
|
||||
)
|
13
frontend/index.html
Normal file
13
frontend/index.html
Normal file
@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite + React + TS</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
4468
frontend/package-lock.json
generated
Normal file
4468
frontend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
33
frontend/package.json
Normal file
33
frontend/package.json
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.9.0",
|
||||
"jwt-decode": "^4.0.0",
|
||||
"react": "^19.1.0",
|
||||
"react-dom": "^19.1.0",
|
||||
"react-icons": "^5.5.0",
|
||||
"react-router-dom": "^7.6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.25.0",
|
||||
"@types/react": "^19.1.2",
|
||||
"@types/react-dom": "^19.1.2",
|
||||
"@vitejs/plugin-react": "^4.4.1",
|
||||
"eslint": "^9.25.0",
|
||||
"eslint-plugin-react-hooks": "^5.2.0",
|
||||
"eslint-plugin-react-refresh": "^0.4.19",
|
||||
"globals": "^16.0.0",
|
||||
"typescript": "~5.8.3",
|
||||
"typescript-eslint": "^8.30.1",
|
||||
"vite": "^6.3.5"
|
||||
}
|
||||
}
|
1
frontend/public/vite.svg
Normal file
1
frontend/public/vite.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
After Width: | Height: | Size: 1.5 KiB |
42
frontend/src/App.css
Normal file
42
frontend/src/App.css
Normal file
@ -0,0 +1,42 @@
|
||||
#root {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.logo {
|
||||
height: 6em;
|
||||
padding: 1.5em;
|
||||
will-change: filter;
|
||||
transition: filter 300ms;
|
||||
}
|
||||
.logo:hover {
|
||||
filter: drop-shadow(0 0 2em #646cffaa);
|
||||
}
|
||||
.logo.react:hover {
|
||||
filter: drop-shadow(0 0 2em #61dafbaa);
|
||||
}
|
||||
|
||||
@keyframes logo-spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
a:nth-of-type(2) .logo {
|
||||
animation: logo-spin infinite 20s linear;
|
||||
}
|
||||
}
|
||||
|
||||
.card {
|
||||
padding: 2em;
|
||||
}
|
||||
|
||||
.read-the-docs {
|
||||
color: #888;
|
||||
}
|
70
frontend/src/App.tsx
Normal file
70
frontend/src/App.tsx
Normal file
@ -0,0 +1,70 @@
|
||||
import {BrowserRouter as Router, Routes, Route, Navigate} from "react-router-dom";
|
||||
|
||||
// Screens (du musst diese entsprechend importieren)
|
||||
import ProfileScreen from "./screens/Profile";
|
||||
import EditProfileScreen from "./screens/EditProfileScreen";
|
||||
import LibraryScreen from "./screens/LibraryScreen";
|
||||
import RegistrationScreen from "./screens/RegisterScreen";
|
||||
import LoginScreen from "./screens/LoginScreen";
|
||||
import HomeScreen from "./screens/Home.tsx";
|
||||
import type {JSX} from "react";
|
||||
|
||||
// Optional: Auth-Gateway (z. B. ProtectedRoute)
|
||||
const isAuthenticated = () => {
|
||||
return localStorage.getItem("authToken") !== null;
|
||||
};
|
||||
|
||||
const ProtectedRoute = ({children}: { children: JSX.Element }) => {
|
||||
return isAuthenticated() ? children : <Navigate to="/login"/>;
|
||||
};
|
||||
|
||||
const App = () => {
|
||||
return (
|
||||
<Router>
|
||||
<Routes>
|
||||
{/* Öffentliche Seiten */}
|
||||
<Route path="/login" element={<LoginScreen/>}/>
|
||||
<Route path="/register" element={<RegistrationScreen/>}/>
|
||||
|
||||
{/* Geschützte Seiten */}
|
||||
<Route
|
||||
path="/profile"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<ProfileScreen/>
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/edit-profile"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<EditProfileScreen/>
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/library/:userId"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<LibraryScreen/>
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
path="/recipes/:id"
|
||||
element={
|
||||
<ProtectedRoute>
|
||||
<HomeScreen/>
|
||||
</ProtectedRoute>
|
||||
}
|
||||
/>
|
||||
|
||||
{/* Fallback/Redirect */}
|
||||
<Route path="*" element={<Navigate to="/profile"/>}/>
|
||||
</Routes>
|
||||
</Router>
|
||||
);
|
||||
};
|
||||
|
||||
export default App;
|
1
frontend/src/assets/react.svg
Normal file
1
frontend/src/assets/react.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
After Width: | Height: | Size: 4.0 KiB |
68
frontend/src/index.css
Normal file
68
frontend/src/index.css
Normal file
@ -0,0 +1,68 @@
|
||||
:root {
|
||||
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
|
||||
color-scheme: light dark;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
background-color: #242424;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: 500;
|
||||
color: #646cff;
|
||||
text-decoration: inherit;
|
||||
}
|
||||
a:hover {
|
||||
color: #535bf2;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
place-items: center;
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3.2em;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
button {
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
padding: 0.6em 1.2em;
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
font-family: inherit;
|
||||
background-color: #1a1a1a;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.25s;
|
||||
}
|
||||
button:hover {
|
||||
border-color: #646cff;
|
||||
}
|
||||
button:focus,
|
||||
button:focus-visible {
|
||||
outline: 4px auto -webkit-focus-ring-color;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
color: #213547;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
a:hover {
|
||||
color: #747bff;
|
||||
}
|
||||
button {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
}
|
10
frontend/src/main.tsx
Normal file
10
frontend/src/main.tsx
Normal file
@ -0,0 +1,10 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import './index.css'
|
||||
import App from './App.tsx'
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<App />
|
||||
</StrictMode>,
|
||||
)
|
132
frontend/src/screens/EditProfileScreen.tsx
Normal file
132
frontend/src/screens/EditProfileScreen.tsx
Normal file
@ -0,0 +1,132 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { jwtDecode } from "jwt-decode";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
const API_URL = "http://localhost:8080/users"; // localhost für Web (kein 10.0.2.2)
|
||||
|
||||
const EditProfileScreen = () => {
|
||||
const [username, setUsername] = useState("");
|
||||
const [email, setEmail] = useState("");
|
||||
const [loading, setLoading] = useState(true);
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
const fetchUserProfile = async () => {
|
||||
try {
|
||||
const token = localStorage.getItem("authToken");
|
||||
if (!token) return;
|
||||
|
||||
const decoded: any = jwtDecode(token);
|
||||
const userEmail = decoded.sub;
|
||||
|
||||
const response = await fetch(`${API_URL}/email/${userEmail}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error("Fehler beim Laden");
|
||||
|
||||
const data = await response.json();
|
||||
setUsername(data.username);
|
||||
setEmail(data.email);
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Laden:", error);
|
||||
alert("Profil konnte nicht geladen werden.");
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchUserProfile();
|
||||
}, []);
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!email) return;
|
||||
|
||||
try {
|
||||
const token = localStorage.getItem("authToken");
|
||||
|
||||
const response = await fetch(`${API_URL}/update/email/${email}`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ username, email }),
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error("Fehler beim Speichern");
|
||||
|
||||
alert("Änderungen gespeichert.");
|
||||
navigate(-1); // Zurück
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Speichern:", error);
|
||||
alert("Profil konnte nicht gespeichert werden.");
|
||||
}
|
||||
};
|
||||
|
||||
if (loading) return <p>Lade Profil...</p>;
|
||||
|
||||
return (
|
||||
<div style={styles.container}>
|
||||
<label style={styles.label}>Benutzername</label>
|
||||
<input
|
||||
type="text"
|
||||
value={username}
|
||||
onChange={(e) => setUsername(e.target.value)}
|
||||
style={styles.input}
|
||||
placeholder="Benutzername"
|
||||
/>
|
||||
|
||||
<label style={styles.label}>E-Mail</label>
|
||||
<input
|
||||
type="email"
|
||||
value={email}
|
||||
readOnly
|
||||
style={{ ...styles.input, backgroundColor: "#f0f0f0" }}
|
||||
/>
|
||||
|
||||
<button onClick={handleSave} style={styles.button}>
|
||||
Speichern
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const styles: { [key: string]: React.CSSProperties } = {
|
||||
container: {
|
||||
maxWidth: "400px",
|
||||
margin: "50px auto",
|
||||
padding: "20px",
|
||||
border: "1px solid #ccc",
|
||||
borderRadius: "8px",
|
||||
backgroundColor: "#fff",
|
||||
boxShadow: "0 0 10px rgba(0,0,0,0.1)",
|
||||
},
|
||||
label: {
|
||||
display: "block",
|
||||
fontSize: "16px",
|
||||
marginBottom: "5px",
|
||||
},
|
||||
input: {
|
||||
width: "100%",
|
||||
padding: "10px",
|
||||
marginBottom: "15px",
|
||||
border: "1px solid #ccc",
|
||||
borderRadius: "5px",
|
||||
},
|
||||
button: {
|
||||
width: "100%",
|
||||
padding: "12px",
|
||||
backgroundColor: "#007bff",
|
||||
color: "#fff",
|
||||
border: "none",
|
||||
borderRadius: "5px",
|
||||
fontSize: "16px",
|
||||
cursor: "pointer",
|
||||
},
|
||||
};
|
||||
|
||||
export default EditProfileScreen;
|
11
frontend/src/screens/Home.tsx
Normal file
11
frontend/src/screens/Home.tsx
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
// Dummy HomeScreen – Beispielkomponente
|
||||
const HomeScreen = () => {
|
||||
return (
|
||||
<div style={{ display: "flex", justifyContent: "center", alignItems: "center", height: "100vh" }}>
|
||||
<p>Home Screen</p>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default HomeScreen;
|
103
frontend/src/screens/LibraryScreen.tsx
Normal file
103
frontend/src/screens/LibraryScreen.tsx
Normal file
@ -0,0 +1,103 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import axios from "axios";
|
||||
|
||||
interface Recipe {
|
||||
id: number;
|
||||
name: string;
|
||||
category: string;
|
||||
}
|
||||
|
||||
const LibraryScreen = () => {
|
||||
const [favorites, setFavorites] = useState<Recipe[]>([]);
|
||||
const [ownRecipes, setOwnRecipes] = useState<Recipe[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const navigate = useNavigate();
|
||||
const { userId } = useParams<{ userId: string }>(); // expects userId from route like /library/:userId
|
||||
|
||||
useEffect(() => {
|
||||
fetchRecipes();
|
||||
}, []);
|
||||
|
||||
const fetchRecipes = async () => {
|
||||
try {
|
||||
const favoriteResponse = await axios.get(`http://localhost:8080/api/recipes/favorites/${userId}`);
|
||||
const ownResponse = await axios.get(`http://localhost:8080/api/recipes/user/${userId}`);
|
||||
|
||||
setFavorites(favoriteResponse.data);
|
||||
setOwnRecipes(ownResponse.data);
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Laden der Rezepte:", error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const renderRecipe = (recipe: Recipe) => (
|
||||
<div
|
||||
key={recipe.id}
|
||||
onClick={() => navigate(`/recipes/${recipe.id}`)}
|
||||
style={styles.recipeCard}
|
||||
>
|
||||
<h4 style={{ margin: 0 }}>{recipe.name}</h4>
|
||||
<p style={{ margin: 0, color: "#555" }}>{recipe.category}</p>
|
||||
</div>
|
||||
);
|
||||
|
||||
if (loading) {
|
||||
return <div style={styles.loading}>Lade Rezepte...</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={styles.container}>
|
||||
<h2>Favorisierte Rezepte</h2>
|
||||
{favorites.length === 0 ? (
|
||||
<p>Keine Favoriten gefunden.</p>
|
||||
) : (
|
||||
favorites.map(renderRecipe)
|
||||
)}
|
||||
|
||||
<h2 style={{ marginTop: 30 }}>Eigene Rezepte</h2>
|
||||
{ownRecipes.length === 0 ? (
|
||||
<p>Du hast noch keine eigenen Rezepte.</p>
|
||||
) : (
|
||||
ownRecipes.map(renderRecipe)
|
||||
)}
|
||||
|
||||
<button style={styles.createButton} onClick={() => navigate("/create-recipe")}>
|
||||
Neues Rezept erstellen
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const styles: { [key: string]: React.CSSProperties } = {
|
||||
container: {
|
||||
maxWidth: 800,
|
||||
margin: "40px auto",
|
||||
padding: 20,
|
||||
fontFamily: "Arial, sans-serif",
|
||||
},
|
||||
loading: {
|
||||
textAlign: "center",
|
||||
padding: 40,
|
||||
fontSize: 18,
|
||||
},
|
||||
recipeCard: {
|
||||
borderBottom: "1px solid #ddd",
|
||||
padding: "10px 0",
|
||||
cursor: "pointer",
|
||||
},
|
||||
createButton: {
|
||||
marginTop: 30,
|
||||
padding: "12px 20px",
|
||||
backgroundColor: "#007bff",
|
||||
color: "white",
|
||||
border: "none",
|
||||
borderRadius: 5,
|
||||
fontSize: 16,
|
||||
cursor: "pointer",
|
||||
},
|
||||
};
|
||||
|
||||
export default LibraryScreen;
|
117
frontend/src/screens/LoginScreen.tsx
Normal file
117
frontend/src/screens/LoginScreen.tsx
Normal file
@ -0,0 +1,117 @@
|
||||
import { useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { loginUser } from "../services/authService";
|
||||
import { colors, spacing, radii, fontSizes } from "../theme";
|
||||
|
||||
const LoginScreen = () => {
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleLogin = async () => {
|
||||
try {
|
||||
const token = await loginUser(email, password);
|
||||
if (token) {
|
||||
console.log("Login erfolgreich!", token);
|
||||
|
||||
// Token im localStorage speichern (Web)
|
||||
localStorage.setItem("authToken", token);
|
||||
|
||||
// Navigation zur Home-Seite
|
||||
navigate("/home");
|
||||
} else {
|
||||
console.log("Login fehlgeschlagen");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Login:", error);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div style={styles.wrapper}>
|
||||
<div style={styles.container}>
|
||||
<h2 style={styles.title}>Login</h2>
|
||||
|
||||
<input
|
||||
type="email"
|
||||
placeholder="E-Mail"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
style={styles.input}
|
||||
/>
|
||||
|
||||
<input
|
||||
type="password"
|
||||
placeholder="Passwort"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
style={styles.input}
|
||||
/>
|
||||
|
||||
<button onClick={handleLogin} style={styles.button}>
|
||||
Einloggen
|
||||
</button>
|
||||
|
||||
<p style={styles.linkText} onClick={() => navigate("/register")}>
|
||||
Noch kein Konto? Registrieren
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const styles: { [key: string]: React.CSSProperties } = {
|
||||
wrapper: {
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
height: "100vh", // ganzer Viewport
|
||||
width: "100vw",
|
||||
backgroundColor: colors.background, // optional für Theme-Kontrast
|
||||
},
|
||||
container: {
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
justifyContent: "center",
|
||||
maxWidth: "400px",
|
||||
width: "90%",
|
||||
margin: "10vh auto",
|
||||
padding: spacing.lg,
|
||||
backgroundColor: colors.surface,
|
||||
border: `1px solid ${colors.border}`,
|
||||
borderRadius: radii.lg,
|
||||
boxShadow: "0 4px 12px rgba(0,0,0,0.05)",
|
||||
},
|
||||
title: {
|
||||
fontSize: fontSizes.xl,
|
||||
marginBottom: spacing.md,
|
||||
textAlign: "center",
|
||||
color: colors.text,
|
||||
},
|
||||
input: {
|
||||
padding: spacing.md,
|
||||
marginBottom: spacing.sm,
|
||||
borderRadius: radii.md,
|
||||
border: `1px solid ${colors.border}`,
|
||||
fontSize: fontSizes.md,
|
||||
},
|
||||
button: {
|
||||
padding: spacing.md,
|
||||
backgroundColor: colors.primary,
|
||||
color: "#fff",
|
||||
border: "none",
|
||||
borderRadius: radii.md,
|
||||
cursor: "pointer",
|
||||
fontSize: fontSizes.md,
|
||||
marginTop: spacing.sm,
|
||||
},
|
||||
linkText: {
|
||||
marginTop: spacing.sm,
|
||||
color: colors.primary,
|
||||
textAlign: "center",
|
||||
cursor: "pointer",
|
||||
fontSize: fontSizes.sm,
|
||||
},
|
||||
};
|
||||
|
||||
export default LoginScreen;
|
120
frontend/src/screens/Profile.tsx
Normal file
120
frontend/src/screens/Profile.tsx
Normal file
@ -0,0 +1,120 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { jwtDecode } from "jwt-decode";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
|
||||
const API_URL = "http://localhost:8080/users"; // Web: localhost statt 10.0.2.2
|
||||
|
||||
const ProfileScreen = () => {
|
||||
const [user, setUser] = useState<{ username: string; email: string } | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
const fetchUserProfile = async () => {
|
||||
const token = localStorage.getItem("authToken");
|
||||
if (!token) return;
|
||||
|
||||
try {
|
||||
const decoded: any = jwtDecode(token);
|
||||
const email = decoded.sub;
|
||||
|
||||
const response = await fetch(`${API_URL}/email/${email}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
if (!response.ok) throw new Error("Fehler beim Laden");
|
||||
|
||||
const data = await response.json();
|
||||
setUser(data);
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Laden:", error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchUserProfile();
|
||||
}, []);
|
||||
|
||||
if (loading) return <div style={styles.loader}>Lade Profil...</div>;
|
||||
|
||||
return (
|
||||
<div style={styles.container}>
|
||||
{/* Header */}
|
||||
<div style={styles.headerRow}>
|
||||
<h2 style={styles.welcomeText}>Hi, {user?.username || "User"}!</h2>
|
||||
<button
|
||||
style={styles.settingsButton}
|
||||
onClick={() => alert("Settings-Funktion folgt")}
|
||||
>
|
||||
⚙️
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Bearbeiten */}
|
||||
<div style={{ marginTop: 30 }}>
|
||||
<button style={styles.editButton} onClick={() => navigate("/edit-profile")}>
|
||||
Profil bearbeiten
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Placeholder für Inhalte */}
|
||||
<div style={styles.placeholder}>
|
||||
<p>Hier kommen später Rezepte.</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const styles: { [key: string]: React.CSSProperties } = {
|
||||
container: {
|
||||
maxWidth: "600px",
|
||||
margin: "50px auto",
|
||||
padding: "20px",
|
||||
border: "1px solid #ddd",
|
||||
borderRadius: "10px",
|
||||
backgroundColor: "#f9f9f9",
|
||||
},
|
||||
loader: {
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
height: "100vh",
|
||||
fontSize: "20px",
|
||||
},
|
||||
headerRow: {
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
},
|
||||
welcomeText: {
|
||||
fontSize: "24px",
|
||||
fontWeight: "bold",
|
||||
},
|
||||
settingsButton: {
|
||||
fontSize: "20px",
|
||||
background: "none",
|
||||
border: "none",
|
||||
cursor: "pointer",
|
||||
},
|
||||
editButton: {
|
||||
padding: "10px 20px",
|
||||
fontSize: "16px",
|
||||
backgroundColor: "#007bff",
|
||||
color: "#fff",
|
||||
border: "none",
|
||||
borderRadius: "5px",
|
||||
cursor: "pointer",
|
||||
},
|
||||
placeholder: {
|
||||
marginTop: 40,
|
||||
textAlign: "center",
|
||||
color: "#555",
|
||||
},
|
||||
};
|
||||
|
||||
export default ProfileScreen;
|
124
frontend/src/screens/RegisterScreen.tsx
Normal file
124
frontend/src/screens/RegisterScreen.tsx
Normal file
@ -0,0 +1,124 @@
|
||||
import { useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { registerUser } from "../services/authService";
|
||||
|
||||
const RegistrationScreen = () => {
|
||||
const [username, setUsername] = useState("");
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [confirmPassword, setConfirmPassword] = useState("");
|
||||
const [errorMessage, setErrorMessage] = useState("");
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleRegister = async () => {
|
||||
if (password !== confirmPassword) {
|
||||
setErrorMessage("Passwörter stimmen nicht überein.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await registerUser(email, password, username);
|
||||
if (result) {
|
||||
console.log("Registrierung erfolgreich!");
|
||||
navigate("/login");
|
||||
} else {
|
||||
setErrorMessage("Registrierung fehlgeschlagen.");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Fehler bei der Registrierung:", error);
|
||||
setErrorMessage("Es gab ein Problem bei der Registrierung.");
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div style={styles.container}>
|
||||
<h2 style={styles.title}>Registrierung</h2>
|
||||
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Username"
|
||||
value={username}
|
||||
onChange={(e) => setUsername(e.target.value)}
|
||||
style={styles.input}
|
||||
/>
|
||||
<input
|
||||
type="email"
|
||||
placeholder="E-Mail"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
style={styles.input}
|
||||
/>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="Passwort"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
style={styles.input}
|
||||
/>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="Passwort bestätigen"
|
||||
value={confirmPassword}
|
||||
onChange={(e) => setConfirmPassword(e.target.value)}
|
||||
style={styles.input}
|
||||
/>
|
||||
|
||||
{errorMessage && <p style={styles.errorText}>{errorMessage}</p>}
|
||||
|
||||
<button onClick={handleRegister} style={styles.button}>
|
||||
Registrieren
|
||||
</button>
|
||||
|
||||
<p onClick={() => navigate("/login")} style={styles.linkText}>
|
||||
Schon ein Konto? Einloggen
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const styles: { [key: string]: React.CSSProperties } = {
|
||||
container: {
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
maxWidth: "400px",
|
||||
margin: "100px auto",
|
||||
padding: "20px",
|
||||
border: "1px solid #ccc",
|
||||
borderRadius: "8px",
|
||||
boxShadow: "0 0 10px rgba(0, 0, 0, 0.1)",
|
||||
},
|
||||
title: {
|
||||
fontSize: "24px",
|
||||
marginBottom: "20px",
|
||||
textAlign: "center",
|
||||
},
|
||||
input: {
|
||||
padding: "10px",
|
||||
marginBottom: "10px",
|
||||
borderRadius: "5px",
|
||||
border: "1px solid #ccc",
|
||||
fontSize: "16px",
|
||||
},
|
||||
button: {
|
||||
padding: "10px",
|
||||
backgroundColor: "#007bff",
|
||||
color: "#fff",
|
||||
border: "none",
|
||||
borderRadius: "5px",
|
||||
cursor: "pointer",
|
||||
fontSize: "16px",
|
||||
},
|
||||
linkText: {
|
||||
marginTop: "10px",
|
||||
color: "#007bff",
|
||||
textAlign: "center",
|
||||
cursor: "pointer",
|
||||
},
|
||||
errorText: {
|
||||
color: "red",
|
||||
textAlign: "center",
|
||||
marginBottom: "10px",
|
||||
},
|
||||
};
|
||||
|
||||
export default RegistrationScreen;
|
75
frontend/src/services/AppNavigator.tsx
Normal file
75
frontend/src/services/AppNavigator.tsx
Normal file
@ -0,0 +1,75 @@
|
||||
import {useEffect, useState} from "react";
|
||||
import {Routes, Route, Navigate, Link} from "react-router-dom";
|
||||
import {jwtDecode} from "jwt-decode";
|
||||
|
||||
import Home from "../screens/Home";
|
||||
import LoginScreen from "../screens/LoginScreen";
|
||||
import RegisterScreen from "../screens/RegisterScreen";
|
||||
import Profile from "../screens/Profile";
|
||||
import EditProfileScreen from "../screens/EditProfileScreen";
|
||||
import LibraryScreen from "../screens/LibraryScreen";
|
||||
|
||||
import {MdHome, MdList, MdPerson} from "react-icons/md"; // Web Icons
|
||||
|
||||
// Token validieren mit localStorage
|
||||
const isTokenValid = () => {
|
||||
const token = localStorage.getItem("authToken");
|
||||
if (!token) return false;
|
||||
|
||||
try {
|
||||
const decoded: any = jwtDecode(token);
|
||||
return decoded.exp && decoded.exp > Math.floor(Date.now() / 1000);
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// Web-basierte BottomTabs
|
||||
const BottomTabs = () => (
|
||||
<nav style={{display: "flex", gap: 20, justifyContent: "center", marginBottom: 20}}>
|
||||
<Link to="/"><MdHome size={24}/> Home</Link>
|
||||
<Link to="/library"><MdList size={24}/> Library</Link>
|
||||
<Link to="/profile"><MdPerson size={24}/> Profile</Link>
|
||||
</nav>
|
||||
);
|
||||
|
||||
const AppNavigator = () => {
|
||||
const [isLoggedIn, setIsLoggedIn] = useState<boolean | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
setIsLoggedIn(isTokenValid());
|
||||
}, []);
|
||||
|
||||
if (isLoggedIn === null) {
|
||||
return (
|
||||
<div style={{textAlign: "center", marginTop: "2rem"}}>
|
||||
<p>Loading...</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!isLoggedIn) {
|
||||
return (
|
||||
<Routes>
|
||||
<Route path="/login" element={<LoginScreen/>}/>
|
||||
<Route path="/register" element={<RegisterScreen/>}/>
|
||||
<Route path="*" element={<Navigate to="/login"/>}/>
|
||||
</Routes>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<BottomTabs/>
|
||||
<Routes>
|
||||
<Route path="/" element={<Home/>}/>
|
||||
<Route path="/library" element={<LibraryScreen/>}/>
|
||||
<Route path="/profile" element={<Profile/>}/>
|
||||
<Route path="/edit-profile" element={<EditProfileScreen/>}/>
|
||||
<Route path="*" element={<Navigate to="/"/>}/>
|
||||
</Routes>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default AppNavigator;
|
50
frontend/src/services/authService.ts
Normal file
50
frontend/src/services/authService.ts
Normal file
@ -0,0 +1,50 @@
|
||||
const API_URL = "http://localhost:8080/api/auth";
|
||||
export const loginUser = async (email: string, password: string) => {
|
||||
try {
|
||||
const response = await fetch(`${API_URL}/login`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({email, password})
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Login fehlgeschlagen");
|
||||
}
|
||||
|
||||
return data.token; // Token zurückgeben
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Login:", error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
export const registerUser = async (email: string, password: string, username: string) => {
|
||||
try {
|
||||
// Die Daten, die an das Backend gesendet werden
|
||||
const userData = {email, password, username};
|
||||
|
||||
// Anfrage an das Backend
|
||||
const response = await fetch(`${API_URL}/register`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(userData),
|
||||
});
|
||||
|
||||
// Überprüfen, ob die Antwort erfolgreich war
|
||||
if (!response.ok) {
|
||||
const errorMessage = await response.text();
|
||||
throw new Error(errorMessage); // Beispiel für Fehlermeldung, falls E-Mail oder Username bereits vergeben
|
||||
}
|
||||
|
||||
return userData // Erfolgreiche Antwort, z.B. der neue User
|
||||
} catch (error) {
|
||||
console.error("Fehler bei der Registrierung:", error);
|
||||
throw error; // Fehler weitergeben, damit der Benutzer entsprechend reagieren kann
|
||||
}
|
||||
};
|
||||
|
||||
|
34
frontend/src/theme.ts
Normal file
34
frontend/src/theme.ts
Normal file
@ -0,0 +1,34 @@
|
||||
// theme.ts
|
||||
|
||||
export const colors = {
|
||||
primary: "#007bff",
|
||||
primaryDark: "#0056b3",
|
||||
background: "#f5f5f5",
|
||||
surface: "#ffffff",
|
||||
text: "#333333",
|
||||
muted: "#666666",
|
||||
border: "#cccccc",
|
||||
error: "#ff4d4f",
|
||||
};
|
||||
|
||||
export const spacing = {
|
||||
xs: 4,
|
||||
sm: 8,
|
||||
md: 16,
|
||||
lg: 24,
|
||||
xl: 32,
|
||||
};
|
||||
|
||||
export const radii = {
|
||||
sm: 4,
|
||||
md: 8,
|
||||
lg: 12,
|
||||
xl: 20,
|
||||
};
|
||||
|
||||
export const fontSizes = {
|
||||
sm: 14,
|
||||
md: 16,
|
||||
lg: 20,
|
||||
xl: 28,
|
||||
};
|
1
frontend/src/vite-env.d.ts
vendored
Normal file
1
frontend/src/vite-env.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
27
frontend/tsconfig.app.json
Normal file
27
frontend/tsconfig.app.json
Normal file
@ -0,0 +1,27 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
"target": "ES2020",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
7
frontend/tsconfig.json
Normal file
7
frontend/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json" },
|
||||
{ "path": "./tsconfig.node.json" }
|
||||
]
|
||||
}
|
25
frontend/tsconfig.node.json
Normal file
25
frontend/tsconfig.node.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
"target": "ES2022",
|
||||
"lib": ["ES2023"],
|
||||
"module": "ESNext",
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
25
frontend/vite.config.ts
Normal file
25
frontend/vite.config.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
server: {
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://localhost:8080',
|
||||
secure: false,
|
||||
changeOrigin: true,
|
||||
ws: true,
|
||||
/*configure: (proxy) => {
|
||||
proxy.on('error', (err, _req, _res) => {
|
||||
console.error(err);
|
||||
})
|
||||
proxy.on('proxyReq', (_proxyReq, req, _res) => {
|
||||
console.log("Anfrage an Proxy: ", req.method, req.url);
|
||||
})
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user