лр3
This commit is contained in:
parent
5dcc482ff9
commit
346b1fac1c
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.env
|
14
dcaa/src/main/java/com/spring/dcaa/config/AppConfig.java
Normal file
14
dcaa/src/main/java/com/spring/dcaa/config/AppConfig.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package com.spring.dcaa.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class AppConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RestTemplate restTemplate() {
|
||||||
|
return new RestTemplate();
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,9 @@ import com.spring.dcaa.repository.VisitorRepository;
|
|||||||
import jakarta.persistence.EntityNotFoundException;
|
import jakarta.persistence.EntityNotFoundException;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.core.ParameterizedTypeReference;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
@ -14,6 +17,9 @@ import org.springframework.web.bind.annotation.PutMapping;
|
|||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@ -21,6 +27,21 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class VisitorController {
|
public class VisitorController {
|
||||||
private final VisitorRepository visitorRepository;
|
private final VisitorRepository visitorRepository;
|
||||||
|
private final RestTemplate restTemplate;
|
||||||
|
|
||||||
|
@GetMapping("/report")
|
||||||
|
public Object externalReport() {
|
||||||
|
log.info("Fetching report from external service");
|
||||||
|
String externalServiceUrl = "http://report:8082/visitors";
|
||||||
|
ResponseEntity<Object> response = restTemplate.exchange(
|
||||||
|
externalServiceUrl,
|
||||||
|
HttpMethod.GET,
|
||||||
|
null,
|
||||||
|
new ParameterizedTypeReference<>() {
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return response.getBody();
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public ReportDto report() {
|
public ReportDto report() {
|
||||||
|
61
docker-compose.yml
Normal file
61
docker-compose.yml
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
version: "3.8"
|
||||||
|
|
||||||
|
services:
|
||||||
|
gateway:
|
||||||
|
container_name: gateway
|
||||||
|
build: ./gateway
|
||||||
|
image: gateway
|
||||||
|
ports:
|
||||||
|
- "6060:6060"
|
||||||
|
networks:
|
||||||
|
backend:
|
||||||
|
aliases:
|
||||||
|
- "gateway"
|
||||||
|
postgres:
|
||||||
|
image: postgres:16-alpine
|
||||||
|
ports:
|
||||||
|
- "5433:5432"
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: Rental
|
||||||
|
POSTGRES_USER: role_for_spring
|
||||||
|
POSTGRES_PASSWORD: ${DB_PASSWORD}
|
||||||
|
networks:
|
||||||
|
backend:
|
||||||
|
aliases:
|
||||||
|
- "postgres"
|
||||||
|
rental:
|
||||||
|
container_name: rental
|
||||||
|
build: ./dcaa
|
||||||
|
image: rental
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
||||||
|
depends_on:
|
||||||
|
- postgres
|
||||||
|
environment:
|
||||||
|
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/Rental
|
||||||
|
SPRING_DATASOURCE_USERNAME: role_for_spring
|
||||||
|
SPRING_DATASOURCE_PASSWORD: ${DB_PASSWORD}
|
||||||
|
networks:
|
||||||
|
backend:
|
||||||
|
aliases:
|
||||||
|
- "rental"
|
||||||
|
report:
|
||||||
|
container_name: report
|
||||||
|
build: ./report
|
||||||
|
image: report
|
||||||
|
ports:
|
||||||
|
- "8082:8082"
|
||||||
|
depends_on:
|
||||||
|
- rental
|
||||||
|
environment:
|
||||||
|
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/Rental
|
||||||
|
SPRING_DATASOURCE_USERNAME: role_for_spring
|
||||||
|
SPRING_DATASOURCE_PASSWORD: ${DB_PASSWORD}
|
||||||
|
networks:
|
||||||
|
backend:
|
||||||
|
aliases:
|
||||||
|
- "rental"
|
||||||
|
|
||||||
|
networks:
|
||||||
|
backend:
|
||||||
|
driver: bridge
|
19
rental/.gitignore → gateway/.gitignore
vendored
19
rental/.gitignore → gateway/.gitignore
vendored
@ -1,10 +1,8 @@
|
|||||||
.env
|
|
||||||
HELP.md
|
HELP.md
|
||||||
.gradle
|
target/
|
||||||
build/
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
!gradle/wrapper/gradle-wrapper.jar
|
!**/src/main/**/target/
|
||||||
!**/src/main/**/build/
|
!**/src/test/**/target/
|
||||||
!**/src/test/**/build/
|
|
||||||
|
|
||||||
### STS ###
|
### STS ###
|
||||||
.apt_generated
|
.apt_generated
|
||||||
@ -14,18 +12,12 @@ build/
|
|||||||
.settings
|
.settings
|
||||||
.springBeans
|
.springBeans
|
||||||
.sts4-cache
|
.sts4-cache
|
||||||
bin/
|
|
||||||
!**/src/main/**/bin/
|
|
||||||
!**/src/test/**/bin/
|
|
||||||
|
|
||||||
### IntelliJ IDEA ###
|
### IntelliJ IDEA ###
|
||||||
.idea
|
.idea
|
||||||
*.iws
|
*.iws
|
||||||
*.iml
|
*.iml
|
||||||
*.ipr
|
*.ipr
|
||||||
out/
|
|
||||||
!**/src/main/**/out/
|
|
||||||
!**/src/test/**/out/
|
|
||||||
|
|
||||||
### NetBeans ###
|
### NetBeans ###
|
||||||
/nbproject/private/
|
/nbproject/private/
|
||||||
@ -33,6 +25,9 @@ out/
|
|||||||
/dist/
|
/dist/
|
||||||
/nbdist/
|
/nbdist/
|
||||||
/.nb-gradle/
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
### VS Code ###
|
### VS Code ###
|
||||||
.vscode/
|
.vscode/
|
19
gateway/.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
19
gateway/.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
|
3
gateway/Dockerfile
Normal file
3
gateway/Dockerfile
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
FROM bellsoft/liberica-openjdk-alpine:17.0.8
|
||||||
|
ADD target/gateway-0.0.1-SNAPSHOT.jar /app/
|
||||||
|
CMD ["java", "-Xmx200m", "-jar", "/app/gateway-0.0.1-SNAPSHOT.jar"]
|
259
gateway/mvnw
vendored
Normal file
259
gateway/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
gateway/mvnw.cmd
vendored
Normal file
149
gateway/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"
|
66
gateway/pom.xml
Normal file
66
gateway/pom.xml
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?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.3.4</version>
|
||||||
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
|
</parent>
|
||||||
|
<groupId>com.spring</groupId>
|
||||||
|
<artifactId>gateway</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<name>gateway</name>
|
||||||
|
<description>gateway project</description>
|
||||||
|
<url/>
|
||||||
|
<licenses>
|
||||||
|
<license/>
|
||||||
|
</licenses>
|
||||||
|
<developers>
|
||||||
|
<developer/>
|
||||||
|
</developers>
|
||||||
|
<scm>
|
||||||
|
<connection/>
|
||||||
|
<developerConnection/>
|
||||||
|
<tag/>
|
||||||
|
<url/>
|
||||||
|
</scm>
|
||||||
|
<properties>
|
||||||
|
<java.version>17</java.version>
|
||||||
|
<spring-cloud.version>2023.0.3</spring-cloud.version>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-starter-gateway</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.cloud</groupId>
|
||||||
|
<artifactId>spring-cloud-dependencies</artifactId>
|
||||||
|
<version>${spring-cloud.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -1,15 +1,13 @@
|
|||||||
package com.car.rental;
|
package com.spring.gateway;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@RestController
|
public class GatewayApplication {
|
||||||
public class RentalApplication {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(RentalApplication.class, args);
|
SpringApplication.run(GatewayApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
28
gateway/src/main/resources/application.yml
Normal file
28
gateway/src/main/resources/application.yml
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
server:
|
||||||
|
port: 6060
|
||||||
|
|
||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: gateway
|
||||||
|
cloud:
|
||||||
|
gateway:
|
||||||
|
routes:
|
||||||
|
- id: visitors
|
||||||
|
uri: http://rental:8080
|
||||||
|
predicates:
|
||||||
|
- Path=/rental/**
|
||||||
|
filters:
|
||||||
|
- RewritePath=/rental/(?<path>.*), /$\{path}
|
||||||
|
- RemoveRequestHeader=Cookie,Set-Cookie
|
||||||
|
# - id: report
|
||||||
|
# uri: http://report:8082
|
||||||
|
# predicates:
|
||||||
|
# - Path=/report/**
|
||||||
|
# filters:
|
||||||
|
# - RewritePath=/report/(?<path>.*), /$\{path}
|
||||||
|
# - RemoveRequestHeader=Cookie,Set-Cookie
|
||||||
|
management:
|
||||||
|
endpoint:
|
||||||
|
end:
|
||||||
|
exposure:
|
||||||
|
include: "*"
|
@ -1,47 +0,0 @@
|
|||||||
plugins {
|
|
||||||
id 'java'
|
|
||||||
id 'org.springframework.boot' version '3.0.2'
|
|
||||||
id 'io.spring.dependency-management' version '1.1.0'
|
|
||||||
}
|
|
||||||
|
|
||||||
group = 'com.car'
|
|
||||||
version = '0.0.1-SNAPSHOT'
|
|
||||||
|
|
||||||
java {
|
|
||||||
sourceCompatibility = '17'
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
|
||||||
implementation 'org.springframework.boot:spring-boot-devtools'
|
|
||||||
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
|
|
||||||
|
|
||||||
implementation 'org.webjars:bootstrap:5.1.3'
|
|
||||||
implementation 'org.webjars:jquery:3.6.0'
|
|
||||||
implementation 'org.webjars:font-awesome:6.1.0'
|
|
||||||
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
|
||||||
implementation 'com.h2database:h2:2.1.210'
|
|
||||||
|
|
||||||
implementation 'org.springframework.boot:spring-boot-starter-security'
|
|
||||||
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
|
|
||||||
|
|
||||||
implementation 'org.hibernate.validator:hibernate-validator'
|
|
||||||
|
|
||||||
implementation 'org.springdoc:springdoc-openapi-ui:1.6.5'
|
|
||||||
|
|
||||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.named('bootBuildImage') {
|
|
||||||
builder = 'paketobuildpacks/builder-jammy-base:latest'
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.named('test') {
|
|
||||||
useJUnitPlatform()
|
|
||||||
}
|
|
Binary file not shown.
BIN
rental/gradle/wrapper/gradle-wrapper.jar
vendored
BIN
rental/gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
@ -1,7 +0,0 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
|
||||||
distributionPath=wrapper/dists
|
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
|
|
||||||
networkTimeout=10000
|
|
||||||
validateDistributionUrl=true
|
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
|
||||||
zipStorePath=wrapper/dists
|
|
249
rental/gradlew
vendored
249
rental/gradlew
vendored
@ -1,249 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
#
|
|
||||||
# Copyright © 2015-2021 the original authors.
|
|
||||||
#
|
|
||||||
# Licensed 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
|
|
||||||
#
|
|
||||||
# https://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.
|
|
||||||
#
|
|
||||||
|
|
||||||
##############################################################################
|
|
||||||
#
|
|
||||||
# Gradle start up script for POSIX generated by Gradle.
|
|
||||||
#
|
|
||||||
# Important for running:
|
|
||||||
#
|
|
||||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
|
||||||
# noncompliant, but you have some other compliant shell such as ksh or
|
|
||||||
# bash, then to run this script, type that shell name before the whole
|
|
||||||
# command line, like:
|
|
||||||
#
|
|
||||||
# ksh Gradle
|
|
||||||
#
|
|
||||||
# Busybox and similar reduced shells will NOT work, because this script
|
|
||||||
# requires all of these POSIX shell features:
|
|
||||||
# * functions;
|
|
||||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
|
||||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
|
||||||
# * compound commands having a testable exit status, especially «case»;
|
|
||||||
# * various built-in commands including «command», «set», and «ulimit».
|
|
||||||
#
|
|
||||||
# Important for patching:
|
|
||||||
#
|
|
||||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
|
||||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
|
||||||
#
|
|
||||||
# The "traditional" practice of packing multiple parameters into a
|
|
||||||
# space-separated string is a well documented source of bugs and security
|
|
||||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
|
||||||
# options in "$@", and eventually passing that to Java.
|
|
||||||
#
|
|
||||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
|
||||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
|
||||||
# see the in-line comments for details.
|
|
||||||
#
|
|
||||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
|
||||||
# Darwin, MinGW, and NonStop.
|
|
||||||
#
|
|
||||||
# (3) This script is generated from the Groovy template
|
|
||||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
|
||||||
# within the Gradle project.
|
|
||||||
#
|
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
|
||||||
#
|
|
||||||
##############################################################################
|
|
||||||
|
|
||||||
# Attempt to set APP_HOME
|
|
||||||
|
|
||||||
# Resolve links: $0 may be a link
|
|
||||||
app_path=$0
|
|
||||||
|
|
||||||
# Need this for daisy-chained symlinks.
|
|
||||||
while
|
|
||||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
|
||||||
[ -h "$app_path" ]
|
|
||||||
do
|
|
||||||
ls=$( ls -ld "$app_path" )
|
|
||||||
link=${ls#*' -> '}
|
|
||||||
case $link in #(
|
|
||||||
/*) app_path=$link ;; #(
|
|
||||||
*) app_path=$APP_HOME$link ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
# This is normally unused
|
|
||||||
# shellcheck disable=SC2034
|
|
||||||
APP_BASE_NAME=${0##*/}
|
|
||||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
|
||||||
MAX_FD=maximum
|
|
||||||
|
|
||||||
warn () {
|
|
||||||
echo "$*"
|
|
||||||
} >&2
|
|
||||||
|
|
||||||
die () {
|
|
||||||
echo
|
|
||||||
echo "$*"
|
|
||||||
echo
|
|
||||||
exit 1
|
|
||||||
} >&2
|
|
||||||
|
|
||||||
# OS specific support (must be 'true' or 'false').
|
|
||||||
cygwin=false
|
|
||||||
msys=false
|
|
||||||
darwin=false
|
|
||||||
nonstop=false
|
|
||||||
case "$( uname )" in #(
|
|
||||||
CYGWIN* ) cygwin=true ;; #(
|
|
||||||
Darwin* ) darwin=true ;; #(
|
|
||||||
MSYS* | MINGW* ) msys=true ;; #(
|
|
||||||
NONSTOP* ) nonstop=true ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
|
||||||
|
|
||||||
|
|
||||||
# Determine the Java command to use to start the JVM.
|
|
||||||
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
|
|
||||||
else
|
|
||||||
JAVACMD=$JAVA_HOME/bin/java
|
|
||||||
fi
|
|
||||||
if [ ! -x "$JAVACMD" ] ; then
|
|
||||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
location of your Java installation."
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
JAVACMD=java
|
|
||||||
if ! command -v java >/dev/null 2>&1
|
|
||||||
then
|
|
||||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
location of your Java installation."
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
|
||||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
|
||||||
case $MAX_FD in #(
|
|
||||||
max*)
|
|
||||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
|
||||||
# shellcheck disable=SC2039,SC3045
|
|
||||||
MAX_FD=$( ulimit -H -n ) ||
|
|
||||||
warn "Could not query maximum file descriptor limit"
|
|
||||||
esac
|
|
||||||
case $MAX_FD in #(
|
|
||||||
'' | soft) :;; #(
|
|
||||||
*)
|
|
||||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
|
||||||
# shellcheck disable=SC2039,SC3045
|
|
||||||
ulimit -n "$MAX_FD" ||
|
|
||||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Collect all arguments for the java command, stacking in reverse order:
|
|
||||||
# * args from the command line
|
|
||||||
# * the main class name
|
|
||||||
# * -classpath
|
|
||||||
# * -D...appname settings
|
|
||||||
# * --module-path (only if needed)
|
|
||||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
|
||||||
|
|
||||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
|
||||||
if "$cygwin" || "$msys" ; then
|
|
||||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
|
||||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
|
||||||
|
|
||||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
|
||||||
|
|
||||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
||||||
for arg do
|
|
||||||
if
|
|
||||||
case $arg in #(
|
|
||||||
-*) false ;; # don't mess with options #(
|
|
||||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
|
||||||
[ -e "$t" ] ;; #(
|
|
||||||
*) false ;;
|
|
||||||
esac
|
|
||||||
then
|
|
||||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
|
||||||
fi
|
|
||||||
# Roll the args list around exactly as many times as the number of
|
|
||||||
# args, so each arg winds up back in the position where it started, but
|
|
||||||
# possibly modified.
|
|
||||||
#
|
|
||||||
# NB: a `for` loop captures its iteration list before it begins, so
|
|
||||||
# changing the positional parameters here affects neither the number of
|
|
||||||
# iterations, nor the values presented in `arg`.
|
|
||||||
shift # remove old arg
|
|
||||||
set -- "$@" "$arg" # push replacement arg
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
|
||||||
|
|
||||||
# Collect all arguments for the java command:
|
|
||||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
|
||||||
# and any embedded shellness will be escaped.
|
|
||||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
|
||||||
# treated as '${Hostname}' itself on the command line.
|
|
||||||
|
|
||||||
set -- \
|
|
||||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
|
||||||
-classpath "$CLASSPATH" \
|
|
||||||
org.gradle.wrapper.GradleWrapperMain \
|
|
||||||
"$@"
|
|
||||||
|
|
||||||
# Stop when "xargs" is not available.
|
|
||||||
if ! command -v xargs >/dev/null 2>&1
|
|
||||||
then
|
|
||||||
die "xargs is not available"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Use "xargs" to parse quoted args.
|
|
||||||
#
|
|
||||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
|
||||||
#
|
|
||||||
# In Bash we could simply go:
|
|
||||||
#
|
|
||||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
|
||||||
# set -- "${ARGS[@]}" "$@"
|
|
||||||
#
|
|
||||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
|
||||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
|
||||||
# character that might be a shell metacharacter, then use eval to reverse
|
|
||||||
# that process (while maintaining the separation between arguments), and wrap
|
|
||||||
# the whole thing up as a single "set" statement.
|
|
||||||
#
|
|
||||||
# This will of course break if any of these variables contains a newline or
|
|
||||||
# an unmatched quote.
|
|
||||||
#
|
|
||||||
|
|
||||||
eval "set -- $(
|
|
||||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
|
||||||
xargs -n1 |
|
|
||||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
|
||||||
tr '\n' ' '
|
|
||||||
)" '"$@"'
|
|
||||||
|
|
||||||
exec "$JAVACMD" "$@"
|
|
92
rental/gradlew.bat
vendored
92
rental/gradlew.bat
vendored
@ -1,92 +0,0 @@
|
|||||||
@rem
|
|
||||||
@rem Copyright 2015 the original author or authors.
|
|
||||||
@rem
|
|
||||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
@rem you may not use this file except in compliance with the License.
|
|
||||||
@rem You may obtain a copy of the License at
|
|
||||||
@rem
|
|
||||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
@rem
|
|
||||||
@rem Unless required by applicable law or agreed to in writing, software
|
|
||||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
@rem See the License for the specific language governing permissions and
|
|
||||||
@rem limitations under the License.
|
|
||||||
@rem
|
|
||||||
|
|
||||||
@if "%DEBUG%"=="" @echo off
|
|
||||||
@rem ##########################################################################
|
|
||||||
@rem
|
|
||||||
@rem Gradle startup script for Windows
|
|
||||||
@rem
|
|
||||||
@rem ##########################################################################
|
|
||||||
|
|
||||||
@rem Set local scope for the variables with windows NT shell
|
|
||||||
if "%OS%"=="Windows_NT" setlocal
|
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
|
||||||
if "%DIRNAME%"=="" set DIRNAME=.
|
|
||||||
@rem This is normally unused
|
|
||||||
set APP_BASE_NAME=%~n0
|
|
||||||
set APP_HOME=%DIRNAME%
|
|
||||||
|
|
||||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
|
||||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
|
||||||
|
|
||||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
|
||||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
|
||||||
|
|
||||||
@rem Find java.exe
|
|
||||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
|
||||||
|
|
||||||
set JAVA_EXE=java.exe
|
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
|
||||||
if %ERRORLEVEL% equ 0 goto execute
|
|
||||||
|
|
||||||
echo.
|
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
|
||||||
echo.
|
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
echo location of your Java installation.
|
|
||||||
|
|
||||||
goto fail
|
|
||||||
|
|
||||||
:findJavaFromJavaHome
|
|
||||||
set JAVA_HOME=%JAVA_HOME:"=%
|
|
||||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
|
||||||
|
|
||||||
if exist "%JAVA_EXE%" goto execute
|
|
||||||
|
|
||||||
echo.
|
|
||||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
|
||||||
echo.
|
|
||||||
echo Please set the JAVA_HOME variable in your environment to match the
|
|
||||||
echo location of your Java installation.
|
|
||||||
|
|
||||||
goto fail
|
|
||||||
|
|
||||||
:execute
|
|
||||||
@rem Setup the command line
|
|
||||||
|
|
||||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
|
||||||
|
|
||||||
|
|
||||||
@rem Execute Gradle
|
|
||||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
|
||||||
|
|
||||||
:end
|
|
||||||
@rem End local scope for the variables with windows NT shell
|
|
||||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
|
||||||
|
|
||||||
:fail
|
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
|
||||||
rem the _cmd.exe /c_ return code!
|
|
||||||
set EXIT_CODE=%ERRORLEVEL%
|
|
||||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
|
||||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
|
||||||
exit /b %EXIT_CODE%
|
|
||||||
|
|
||||||
:mainEnd
|
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
|
||||||
|
|
||||||
:omega
|
|
@ -1 +0,0 @@
|
|||||||
rootProject.name = 'rental'
|
|
@ -1,14 +0,0 @@
|
|||||||
package com.car.rental.configuration;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class PasswordEncoderConfiguration {
|
|
||||||
@Bean
|
|
||||||
public PasswordEncoder createPasswordEncoder() {
|
|
||||||
return new BCryptPasswordEncoder();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,74 +0,0 @@
|
|||||||
package com.car.rental.configuration;
|
|
||||||
|
|
||||||
import com.car.rental.rental.model.UserRole;
|
|
||||||
import com.car.rental.rental.service.UserService;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.http.HttpMethod;
|
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
|
||||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
|
||||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
|
||||||
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.configuration.WebSecurityCustomizer;
|
|
||||||
import org.springframework.security.config.annotation.web.configurers.LogoutConfigurer;
|
|
||||||
import org.springframework.security.web.SecurityFilterChain;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@EnableWebSecurity
|
|
||||||
@EnableGlobalMethodSecurity(securedEnabled = true)
|
|
||||||
public class SecurityConfiguration {
|
|
||||||
private final Logger log = LoggerFactory.getLogger(SecurityConfiguration.class);
|
|
||||||
private static final String LOGIN_URL = "/login";
|
|
||||||
private final UserService userService;
|
|
||||||
|
|
||||||
public SecurityConfiguration(UserService userService) {
|
|
||||||
this.userService = userService;
|
|
||||||
createAdminOnStartup();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createAdminOnStartup() {
|
|
||||||
final String admin = "admin";
|
|
||||||
final String login = "79999999999";
|
|
||||||
if (userService.findByLogin(login) == null) {
|
|
||||||
log.info("Admin user successfully created");
|
|
||||||
userService.createUser(admin, admin, login, admin, admin, UserRole.ADMIN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
|
||||||
http.headers().frameOptions().sameOrigin().and()
|
|
||||||
.cors().and()
|
|
||||||
.csrf().disable()
|
|
||||||
.authorizeHttpRequests()
|
|
||||||
.requestMatchers("/signup").permitAll()
|
|
||||||
.requestMatchers(HttpMethod.GET, LOGIN_URL).permitAll()
|
|
||||||
.anyRequest().authenticated()
|
|
||||||
.and()
|
|
||||||
.formLogin()
|
|
||||||
.loginPage(LOGIN_URL).permitAll()
|
|
||||||
.and()
|
|
||||||
.logout().permitAll();
|
|
||||||
return http.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public AuthenticationManager authenticationManagerBean(HttpSecurity http) throws Exception {
|
|
||||||
AuthenticationManagerBuilder authenticationManagerBuilder = http
|
|
||||||
.getSharedObject(AuthenticationManagerBuilder.class);
|
|
||||||
authenticationManagerBuilder.userDetailsService(userService);
|
|
||||||
return authenticationManagerBuilder.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public WebSecurityCustomizer webSecurityCustomizer() {
|
|
||||||
return web -> web.ignoring()
|
|
||||||
.requestMatchers("/css/**")
|
|
||||||
.requestMatchers("/js/**")
|
|
||||||
.requestMatchers("/templates/**")
|
|
||||||
.requestMatchers("/webjars/**");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
package com.car.rental.configuration;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
|
||||||
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class WebConfiguration implements WebMvcConfigurer {
|
|
||||||
public static final String REST_API = "/api";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addViewControllers(ViewControllerRegistry registry) {
|
|
||||||
WebMvcConfigurer.super.addViewControllers(registry);
|
|
||||||
registry.addViewController("login");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addCorsMappings(CorsRegistry registry) {
|
|
||||||
registry.addMapping("/**").allowedMethods("*");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
|||||||
package com.car.rental.rental.dto;
|
|
||||||
|
|
||||||
import com.car.rental.rental.model.Brand;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class BrandDto {
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@NotBlank(message = "name can't be null or empty")
|
|
||||||
@Size(min = 1, max = 64)
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
public BrandDto(Brand brand) {
|
|
||||||
this.id = brand.getId();
|
|
||||||
this.name = brand.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public BrandDto() {
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,103 +0,0 @@
|
|||||||
package com.car.rental.rental.dto;
|
|
||||||
|
|
||||||
import com.car.rental.rental.model.Car;
|
|
||||||
import com.car.rental.rental.model.Model;
|
|
||||||
import com.car.rental.rental.model.OrderCar;
|
|
||||||
import com.car.rental.rental.model.enums.CarStatus;
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CarDto {
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@NotBlank(message = "year can't be null or empty")
|
|
||||||
@Size(min = 4, max = 4)
|
|
||||||
private Integer year;
|
|
||||||
|
|
||||||
@NotBlank(message = "price can't be null or empty")
|
|
||||||
@Size(min = 4, max = 10)
|
|
||||||
private Double price;
|
|
||||||
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
@NotBlank(message = "year can't be null or empty")
|
|
||||||
@Size(min = 4, max = 4)
|
|
||||||
private CarStatus status;
|
|
||||||
|
|
||||||
private ModelDto model;
|
|
||||||
|
|
||||||
private String image;
|
|
||||||
|
|
||||||
public CarDto() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public CarDto(Car car) {
|
|
||||||
this.id = car.getId();
|
|
||||||
this.year = car.getYear();
|
|
||||||
this.price = car.getPrice();
|
|
||||||
this.description = car.getDescription();
|
|
||||||
this.status = car.getStatus();
|
|
||||||
this.model = new ModelDto(car.getModel());
|
|
||||||
this.image = new String(car.getImage(), StandardCharsets.UTF_8);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getYear() {
|
|
||||||
return year;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setYear(Integer year) {
|
|
||||||
this.year = year;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getPrice() {
|
|
||||||
return price;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPrice(Double price) {
|
|
||||||
this.price = price;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDescription(String description) {
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CarStatus getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(CarStatus status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ModelDto getModel() {
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setModel(ModelDto model) {
|
|
||||||
this.model = model;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getImage() {
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setImage(String image) {
|
|
||||||
this.image = image;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,137 +0,0 @@
|
|||||||
package com.car.rental.rental.dto;
|
|
||||||
|
|
||||||
import com.car.rental.rental.model.enums.BodyType;
|
|
||||||
import com.car.rental.rental.model.Model;
|
|
||||||
import com.car.rental.rental.model.enums.DriveUnitType;
|
|
||||||
import com.car.rental.rental.model.enums.TransmissionType;
|
|
||||||
import jakarta.persistence.EnumType;
|
|
||||||
import jakarta.persistence.Enumerated;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
|
|
||||||
public class ModelDto {
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@NotBlank(message = "name can't be null or empty")
|
|
||||||
@Size(min = 1, max = 64)
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
// двигатель + кол-во литров
|
|
||||||
@NotBlank(message = "engine can't be null or empty")
|
|
||||||
@Size(min = 1, max = 64)
|
|
||||||
private String engine;
|
|
||||||
|
|
||||||
// коробка передач
|
|
||||||
@NotBlank(message = "transmission can't be null or empty")
|
|
||||||
@Enumerated(EnumType.STRING)
|
|
||||||
private TransmissionType transmission;
|
|
||||||
|
|
||||||
// привод
|
|
||||||
@NotBlank(message = "driveUnit can't be null or empty")
|
|
||||||
@Enumerated(EnumType.STRING)
|
|
||||||
private DriveUnitType driveUnit;
|
|
||||||
|
|
||||||
// мест
|
|
||||||
@NotBlank(message = "places can't be null or empty")
|
|
||||||
@Size(min = 1, max = 3)
|
|
||||||
private Integer places;
|
|
||||||
|
|
||||||
// кузов
|
|
||||||
@NotBlank(message = "body can't be null or empty")
|
|
||||||
@Enumerated(EnumType.STRING)
|
|
||||||
private BodyType body;
|
|
||||||
|
|
||||||
// пробег
|
|
||||||
@NotBlank(message = "mileage can't be null or empty")
|
|
||||||
@Size(min = 1, max = 4)
|
|
||||||
private Integer mileage;
|
|
||||||
|
|
||||||
private BrandDto brand;
|
|
||||||
|
|
||||||
public ModelDto(Model model) {
|
|
||||||
this.id = model.getId();
|
|
||||||
this.name = model.getName();
|
|
||||||
this.engine = model.getEngine();
|
|
||||||
this.transmission = model.getTransmission();
|
|
||||||
this.driveUnit = model.getDriveUnit();
|
|
||||||
this.places = model.getPlaces();
|
|
||||||
this.body = model.getBody();
|
|
||||||
this.mileage = model.getMileage();
|
|
||||||
this.brand = new BrandDto(model.getBrand());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ModelDto() {
|
|
||||||
}
|
|
||||||
|
|
||||||
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 getEngine() {
|
|
||||||
return engine;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEngine(String engine) {
|
|
||||||
this.engine = engine;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TransmissionType getTransmission() {
|
|
||||||
return transmission;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTransmission(TransmissionType transmission) {
|
|
||||||
this.transmission = transmission;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DriveUnitType getDriveUnit() {
|
|
||||||
return driveUnit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDriveUnit(DriveUnitType driveUnit) {
|
|
||||||
this.driveUnit = driveUnit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getPlaces() {
|
|
||||||
return places;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlaces(Integer places) {
|
|
||||||
this.places = places;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BodyType getBody() {
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBody(BodyType body) {
|
|
||||||
this.body = body;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getMileage() {
|
|
||||||
return mileage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMileage(Integer mileage) {
|
|
||||||
this.mileage = mileage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BrandDto getBrand() {
|
|
||||||
return brand;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBrand(BrandDto brand) {
|
|
||||||
this.brand = brand;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
package com.car.rental.rental.dto;
|
|
||||||
|
|
||||||
public class OrderCarDto {
|
|
||||||
private CarDto car;
|
|
||||||
private Long orderId;
|
|
||||||
|
|
||||||
public OrderCarDto() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderCarDto(CarDto car, Long orderId) {
|
|
||||||
this.car = car;
|
|
||||||
this.orderId = orderId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCar(CarDto car) {
|
|
||||||
this.car = car;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOrderId(Long orderId) {
|
|
||||||
this.orderId = orderId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CarDto getCar() {
|
|
||||||
return car;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getOrderId() {
|
|
||||||
return orderId;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,131 +0,0 @@
|
|||||||
package com.car.rental.rental.dto;
|
|
||||||
|
|
||||||
import com.car.rental.rental.model.Order;
|
|
||||||
import com.car.rental.rental.model.enums.OrderStatus;
|
|
||||||
import jakarta.persistence.EnumType;
|
|
||||||
import jakarta.persistence.Enumerated;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class OrderDto {
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@NotBlank(message = "status can't be null or empty")
|
|
||||||
@Enumerated(EnumType.STRING)
|
|
||||||
private OrderStatus status;
|
|
||||||
|
|
||||||
@NotNull(message = "startDateTime can't be null or empty")
|
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
|
|
||||||
private LocalDateTime startDateTime;
|
|
||||||
|
|
||||||
@NotNull(message = "endDateTime can't be null or empty")
|
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
|
|
||||||
private LocalDateTime endDateTime;
|
|
||||||
|
|
||||||
@NotBlank(message = "price can't be null or empty")
|
|
||||||
@Size(min = 4, max = 10)
|
|
||||||
private Double price;
|
|
||||||
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
private boolean hasFine;
|
|
||||||
|
|
||||||
private Double fineAmount;
|
|
||||||
|
|
||||||
private List<OrderCarDto> cars;
|
|
||||||
|
|
||||||
public OrderDto() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderDto(Order order) {
|
|
||||||
this.id = order.getId();
|
|
||||||
this.status = order.getStatus();
|
|
||||||
this.startDateTime = order.getStartDateTime();
|
|
||||||
this.endDateTime = order.getEndDateTime();
|
|
||||||
this.price = order.getPrice();
|
|
||||||
this.description = order.getDescription();
|
|
||||||
this.hasFine = order.isHasFine();
|
|
||||||
this.fineAmount = order.getFineAmount();
|
|
||||||
if (order.getCars() != null && !order.getCars().isEmpty())
|
|
||||||
this.cars = order.getCars()
|
|
||||||
.stream()
|
|
||||||
.map(x -> new OrderCarDto(new CarDto(x.getCar()), x.getId().getOrderId())).toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderStatus getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(OrderStatus status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDateTime getStartDateTime() {
|
|
||||||
return startDateTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStartDateTime(LocalDateTime startDateTime) {
|
|
||||||
this.startDateTime = startDateTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDateTime getEndDateTime() {
|
|
||||||
return endDateTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEndDateTime(LocalDateTime endDateTime) {
|
|
||||||
this.endDateTime = endDateTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getPrice() {
|
|
||||||
return price;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPrice(Double price) {
|
|
||||||
this.price = price;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDescription(String description) {
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isHasFine() {
|
|
||||||
return hasFine;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHasFine(boolean hasFine) {
|
|
||||||
this.hasFine = hasFine;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getFineAmount() {
|
|
||||||
return fineAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFineAmount(Double fineAmount) {
|
|
||||||
this.fineAmount = fineAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<OrderCarDto> getCars() {
|
|
||||||
return cars;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCars(List<OrderCarDto> cars) {
|
|
||||||
this.cars = cars;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,84 +0,0 @@
|
|||||||
package com.car.rental.rental.dto;
|
|
||||||
|
|
||||||
import com.car.rental.rental.model.User;
|
|
||||||
import com.car.rental.rental.model.UserRole;
|
|
||||||
import jakarta.persistence.Column;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
|
|
||||||
public class UserDto {
|
|
||||||
private Long id;
|
|
||||||
@NotBlank(message = "firstName can't be null or empty")
|
|
||||||
@Size(min = 3, max = 64)
|
|
||||||
private String firstName;
|
|
||||||
@NotBlank(message = "lastName can't be null or empty")
|
|
||||||
@Size(min = 3, max = 64)
|
|
||||||
private String lastName;
|
|
||||||
@NotBlank(message = "phoneNumber can't be null or empty")
|
|
||||||
@Size(min = 11, max = 11)
|
|
||||||
private String phoneNumber;
|
|
||||||
@NotBlank(message = "password can't be null or empty")
|
|
||||||
@Size(min = 6, max = 64)
|
|
||||||
private String password;
|
|
||||||
private UserRole role;
|
|
||||||
|
|
||||||
public UserDto(User user) {
|
|
||||||
this.id = user.getId();
|
|
||||||
this.firstName = user.getFirstName();
|
|
||||||
this.lastName = user.getLastName();
|
|
||||||
this.phoneNumber = user.getPhoneNumber();
|
|
||||||
this.password = user.getPassword();
|
|
||||||
this.role = user.getRole();
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserDto() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFirstName() {
|
|
||||||
return firstName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFirstName(String firstName) {
|
|
||||||
this.firstName = firstName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLastName() {
|
|
||||||
return lastName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastName(String lastName) {
|
|
||||||
this.lastName = lastName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPhoneNumber() {
|
|
||||||
return phoneNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPhoneNumber(String phoneNumber) {
|
|
||||||
this.phoneNumber = phoneNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserRole getRole() {
|
|
||||||
return role;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRole(UserRole role) {
|
|
||||||
this.role = role;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
package com.car.rental.rental.dto;
|
|
||||||
|
|
||||||
import com.car.rental.rental.model.UserRole;
|
|
||||||
import jakarta.persistence.Column;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
|
|
||||||
public class UserSignupDto {
|
|
||||||
@NotBlank(message = "firstName can't be null or empty")
|
|
||||||
@Size(min = 3, max = 64)
|
|
||||||
private String firstName;
|
|
||||||
|
|
||||||
@NotBlank(message = "lastName can't be null or empty")
|
|
||||||
@Size(min = 3, max = 64)
|
|
||||||
private String lastName;
|
|
||||||
|
|
||||||
@NotBlank(message = "phoneNumber can't be null or empty")
|
|
||||||
@Size(min = 11, max = 11)
|
|
||||||
private String phoneNumber;
|
|
||||||
|
|
||||||
@NotBlank(message = "password can't be null or empty")
|
|
||||||
@Size(min = 6, max = 64)
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
@NotBlank(message = "passwordConfirm can't be null or empty")
|
|
||||||
@Size(min = 6, max = 64)
|
|
||||||
private String passwordConfirm;
|
|
||||||
|
|
||||||
public String getFirstName() {
|
|
||||||
return firstName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFirstName(String firstName) {
|
|
||||||
this.firstName = firstName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLastName() {
|
|
||||||
return lastName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastName(String lastName) {
|
|
||||||
this.lastName = lastName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPhoneNumber() {
|
|
||||||
return phoneNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPhoneNumber(String phoneNumber) {
|
|
||||||
this.phoneNumber = phoneNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPasswordConfirm() {
|
|
||||||
return passwordConfirm;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPasswordConfirm(String passwordConfirm) {
|
|
||||||
this.passwordConfirm = passwordConfirm;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
package com.car.rental.rental.model;
|
|
||||||
|
|
||||||
import com.car.rental.rental.dto.BrandDto;
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
public class Brand {
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@Column(nullable = false, unique = true, length = 64)
|
|
||||||
@NotBlank(message = "name can't be null or empty")
|
|
||||||
@Size(min = 1, max = 64)
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "brand", cascade = CascadeType.REMOVE)
|
|
||||||
private List<Model> models;
|
|
||||||
|
|
||||||
public Brand() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Brand(String name) {
|
|
||||||
this.name = name;
|
|
||||||
this.models = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Brand(BrandDto dto) {
|
|
||||||
this.name = dto.getName();
|
|
||||||
this.models = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
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 List<Model> getModels() {
|
|
||||||
return models;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setModel(Model model) {
|
|
||||||
if (model.getBrand().equals(this)) {
|
|
||||||
this.models.add(model);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,137 +0,0 @@
|
|||||||
package com.car.rental.rental.model;
|
|
||||||
|
|
||||||
import com.car.rental.rental.dto.CarDto;
|
|
||||||
import com.car.rental.rental.model.enums.CarStatus;
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
public class Car {
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@Column(nullable = false, length = 4, name = "year_of_issue")
|
|
||||||
@NotBlank(message = "year can't be null or empty")
|
|
||||||
@Size(min = 4, max = 4)
|
|
||||||
private Integer year;
|
|
||||||
|
|
||||||
@Column(nullable = false, length = 10)
|
|
||||||
@NotBlank(message = "price can't be null or empty")
|
|
||||||
@Size(min = 4, max = 10)
|
|
||||||
private Double price;
|
|
||||||
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
@Column(nullable = false, unique = true, length = 64)
|
|
||||||
@NotBlank(message = "year can't be null or empty")
|
|
||||||
@Size(min = 4, max = 4)
|
|
||||||
private CarStatus status;
|
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
|
||||||
@JoinColumn(name = "model_id")
|
|
||||||
private Model model;
|
|
||||||
|
|
||||||
@Lob
|
|
||||||
private byte[] image;
|
|
||||||
|
|
||||||
@OneToMany(mappedBy = "car", fetch = FetchType.LAZY)
|
|
||||||
private List<OrderCar> orders;
|
|
||||||
|
|
||||||
public Car() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Car(CarDto car) {
|
|
||||||
this.year = car.getYear();
|
|
||||||
this.price = car.getPrice();
|
|
||||||
this.status = car.getStatus();
|
|
||||||
this.model = new Model(car.getModel());
|
|
||||||
this.description = car.getDescription();
|
|
||||||
this.image = car.getImage().getBytes();
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] getImage() {
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setImage(byte[] image) {
|
|
||||||
this.image = image;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addOrder(OrderCar orderCar) {
|
|
||||||
if (orders == null) {
|
|
||||||
orders = new ArrayList<>();
|
|
||||||
}
|
|
||||||
if (!orders.contains(orderCar)) {
|
|
||||||
this.orders.add(orderCar);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeOrder(OrderCar orderCar) {
|
|
||||||
if (orders.contains(orderCar))
|
|
||||||
this.orders.remove(orderCar);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<OrderCar> getOrders() {
|
|
||||||
return orders;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOrders(List<OrderCar> orders) {
|
|
||||||
this.orders = orders;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDescription(String description) {
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CarStatus getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(CarStatus status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Model getModel() {
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setModel(Model model) {
|
|
||||||
this.model = model;
|
|
||||||
if (!model.getCars().contains(this)) {
|
|
||||||
model.setCar(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getYear() {
|
|
||||||
return year;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setYear(Integer year) {
|
|
||||||
this.year = year;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getPrice() {
|
|
||||||
return price;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPrice(Double price) {
|
|
||||||
this.price = price;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,172 +0,0 @@
|
|||||||
package com.car.rental.rental.model;
|
|
||||||
|
|
||||||
import com.car.rental.rental.dto.ModelDto;
|
|
||||||
import com.car.rental.rental.model.enums.BodyType;
|
|
||||||
import com.car.rental.rental.model.enums.DriveUnitType;
|
|
||||||
import com.car.rental.rental.model.enums.TransmissionType;
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
public class Model {
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@Column(nullable = false, length = 64)
|
|
||||||
@NotBlank(message = "name can't be null or empty")
|
|
||||||
@Size(min = 1, max = 64)
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
// двигатель + кол-во литров
|
|
||||||
@Column(nullable = false, length = 64)
|
|
||||||
@NotBlank(message = "engine can't be null or empty")
|
|
||||||
@Size(min = 1, max = 64)
|
|
||||||
private String engine;
|
|
||||||
|
|
||||||
// коробка передач
|
|
||||||
@Column(nullable = false, length = 64)
|
|
||||||
@NotBlank(message = "transmission can't be null or empty")
|
|
||||||
@Enumerated(EnumType.STRING)
|
|
||||||
private TransmissionType transmission;
|
|
||||||
|
|
||||||
// привод
|
|
||||||
@Column(nullable = false, length = 64)
|
|
||||||
@NotBlank(message = "driveUnit can't be null or empty")
|
|
||||||
@Enumerated(EnumType.STRING)
|
|
||||||
private DriveUnitType driveUnit;
|
|
||||||
|
|
||||||
// мест
|
|
||||||
@Column(nullable = false, length = 64)
|
|
||||||
@NotBlank(message = "places can't be null or empty")
|
|
||||||
@Size(min = 1, max = 3)
|
|
||||||
private Integer places;
|
|
||||||
|
|
||||||
// кузов
|
|
||||||
@Column(nullable = false, length = 64)
|
|
||||||
@NotBlank(message = "body can't be null or empty")
|
|
||||||
@Enumerated(EnumType.STRING)
|
|
||||||
private BodyType body;
|
|
||||||
|
|
||||||
// пробег
|
|
||||||
@Column(nullable = false, length = 64)
|
|
||||||
@NotBlank(message = "mileage can't be null or empty")
|
|
||||||
@Size(min = 1, max = 4)
|
|
||||||
private Integer mileage;
|
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
|
||||||
@JoinColumn(name = "brand_id")
|
|
||||||
private Brand brand;
|
|
||||||
|
|
||||||
@OneToMany(fetch = FetchType.LAZY, mappedBy = "model", cascade = CascadeType.REMOVE)
|
|
||||||
private List<Car> cars;
|
|
||||||
|
|
||||||
public Model() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Model(ModelDto model) {
|
|
||||||
this.id = model.getId();
|
|
||||||
this.name = model.getName();
|
|
||||||
this.engine = model.getEngine();
|
|
||||||
this.transmission = model.getTransmission();
|
|
||||||
this.driveUnit = model.getDriveUnit();
|
|
||||||
this.places = model.getPlaces();
|
|
||||||
this.body = model.getBody();
|
|
||||||
this.mileage = model.getMileage();
|
|
||||||
this.brand = new Brand(model.getBrand());
|
|
||||||
this.cars = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Car> getCars() {
|
|
||||||
return cars;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCar(Car car) {
|
|
||||||
if (car.getModel().equals(this)) {
|
|
||||||
this.cars.add(car);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getEngine() {
|
|
||||||
return engine;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEngine(String engine) {
|
|
||||||
this.engine = engine;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TransmissionType getTransmission() {
|
|
||||||
return transmission;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTransmission(TransmissionType transmission) {
|
|
||||||
this.transmission = transmission;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DriveUnitType getDriveUnit() {
|
|
||||||
return driveUnit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDriveUnit(DriveUnitType driveUnit) {
|
|
||||||
this.driveUnit = driveUnit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getPlaces() {
|
|
||||||
return places;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlaces(Integer places) {
|
|
||||||
this.places = places;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BodyType getBody() {
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBody(BodyType body) {
|
|
||||||
this.body = body;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCars(List<Car> cars) {
|
|
||||||
this.cars = cars;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getMileage() {
|
|
||||||
return mileage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMileage(Integer mileage) {
|
|
||||||
this.mileage = mileage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Brand getBrand() {
|
|
||||||
return brand;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBrand(Brand brand) {
|
|
||||||
this.brand = brand;
|
|
||||||
if (!brand.getModels().contains(this)) {
|
|
||||||
brand.setModel(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,167 +0,0 @@
|
|||||||
package com.car.rental.rental.model;
|
|
||||||
|
|
||||||
import com.car.rental.rental.dto.OrderDto;
|
|
||||||
import com.car.rental.rental.model.enums.OrderStatus;
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Table(name = "tab_order")
|
|
||||||
public class Order {
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
@Column(nullable = false, length = 64)
|
|
||||||
@NotBlank(message = "status can't be null or empty")
|
|
||||||
@Enumerated(EnumType.STRING)
|
|
||||||
private OrderStatus status;
|
|
||||||
|
|
||||||
@NotNull(message = "startDateTime can't be null or empty")
|
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
|
|
||||||
private LocalDateTime startDateTime;
|
|
||||||
|
|
||||||
@NotNull(message = "endDateTime can't be null or empty")
|
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
|
||||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
|
|
||||||
private LocalDateTime endDateTime;
|
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
|
||||||
@JoinColumn(name = "user_id")
|
|
||||||
private User user;
|
|
||||||
|
|
||||||
@Column(nullable = false, length = 10)
|
|
||||||
@NotBlank(message = "price can't be null or empty")
|
|
||||||
@Size(min = 4, max = 10)
|
|
||||||
private Double price;
|
|
||||||
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
private boolean hasFine;
|
|
||||||
|
|
||||||
private Double fineAmount;
|
|
||||||
|
|
||||||
@OneToMany(mappedBy = "order", fetch = FetchType.LAZY, cascade =
|
|
||||||
{
|
|
||||||
CascadeType.REMOVE,
|
|
||||||
CascadeType.MERGE,
|
|
||||||
CascadeType.PERSIST
|
|
||||||
}, orphanRemoval = true)
|
|
||||||
private List<OrderCar> cars;
|
|
||||||
|
|
||||||
public Order() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public Order(OrderDto order) {
|
|
||||||
this.status = order.getStatus();
|
|
||||||
this.startDateTime = order.getStartDateTime();
|
|
||||||
this.endDateTime = order.getEndDateTime();
|
|
||||||
this.price = order.getPrice();
|
|
||||||
this.description = order.getDescription();
|
|
||||||
this.hasFine = order.isHasFine();
|
|
||||||
this.fineAmount = order.getFineAmount();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addCar(OrderCar orderCar) {
|
|
||||||
if (cars == null) {
|
|
||||||
cars = new ArrayList<>();
|
|
||||||
}
|
|
||||||
if (!cars.contains(orderCar))
|
|
||||||
this.cars.add(orderCar);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<OrderCar> getCars() {
|
|
||||||
return cars;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCars(List<OrderCar> cars) {
|
|
||||||
this.cars = cars;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeCar(OrderCar orderCar){
|
|
||||||
if (cars.contains(orderCar))
|
|
||||||
this.cars.remove(orderCar);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Long id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderStatus getStatus() {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(OrderStatus status) {
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDateTime getStartDateTime() {
|
|
||||||
return startDateTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStartDateTime(LocalDateTime startDateTime) {
|
|
||||||
this.startDateTime = startDateTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LocalDateTime getEndDateTime() {
|
|
||||||
return endDateTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEndDateTime(LocalDateTime endDateTime) {
|
|
||||||
this.endDateTime = endDateTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public User getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUser(User user) {
|
|
||||||
this.user = user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getPrice() {
|
|
||||||
return price;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPrice(Double price) {
|
|
||||||
this.price = price;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDescription(String description) {
|
|
||||||
this.description = description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isHasFine() {
|
|
||||||
return hasFine;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHasFine(boolean hasFine) {
|
|
||||||
this.hasFine = hasFine;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Double getFineAmount() {
|
|
||||||
return fineAmount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFineAmount(Double fineAmount) {
|
|
||||||
this.fineAmount = fineAmount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
|||||||
package com.car.rental.rental.model;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Table(name = "order_car")
|
|
||||||
public class OrderCar {
|
|
||||||
@EmbeddedId
|
|
||||||
private OrderCarKey id;
|
|
||||||
@ManyToOne
|
|
||||||
@MapsId("carId")
|
|
||||||
@JoinColumn(name = "car_id")
|
|
||||||
private Car car;
|
|
||||||
@ManyToOne
|
|
||||||
@MapsId("orderId")
|
|
||||||
@JoinColumn(name = "order_id")
|
|
||||||
private Order order;
|
|
||||||
|
|
||||||
public OrderCar() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderCar(Order order, Car car) {
|
|
||||||
this.order = order;
|
|
||||||
this.car = car;
|
|
||||||
this.id = new OrderCarKey(car.getId(), order.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderCarKey getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(OrderCarKey id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Order getOrder() {
|
|
||||||
return order;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOrder(Order order) {
|
|
||||||
this.order = order;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Car getCar() {
|
|
||||||
return car;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCar(Car car) {
|
|
||||||
this.car = car;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
package com.car.rental.rental.model;
|
|
||||||
|
|
||||||
import jakarta.persistence.Embeddable;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@Embeddable
|
|
||||||
public class OrderCarKey implements Serializable {
|
|
||||||
private Long carId;
|
|
||||||
private Long orderId;
|
|
||||||
|
|
||||||
public OrderCarKey() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderCarKey(Long carId, Long orderId) {
|
|
||||||
this.carId = carId;
|
|
||||||
this.orderId = orderId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getCarId() {
|
|
||||||
return carId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCarId(Long carId) {
|
|
||||||
this.carId = carId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getOrderId() {
|
|
||||||
return orderId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOrderId(Long orderId) {
|
|
||||||
this.orderId = orderId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (!(o instanceof OrderCarKey that)) return false;
|
|
||||||
return Objects.equals(getCarId(), that.getCarId()) && Objects.equals(getOrderId(), that.getOrderId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(getCarId(), getOrderId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,116 +0,0 @@
|
|||||||
package com.car.rental.rental.model;
|
|
||||||
|
|
||||||
import com.car.rental.rental.dto.UserSignupDto;
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import jakarta.validation.constraints.NotBlank;
|
|
||||||
import jakarta.validation.constraints.Size;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Table(name = "tab_user")
|
|
||||||
public class User {
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
|
||||||
private Long id;
|
|
||||||
@Column(nullable = false, length = 64)
|
|
||||||
@NotBlank(message = "firstName can't be null or empty")
|
|
||||||
@Size(min = 3, max = 64)
|
|
||||||
private String firstName;
|
|
||||||
@Column(nullable = false, length = 64)
|
|
||||||
@NotBlank(message = "lastName can't be null or empty")
|
|
||||||
@Size(min = 3, max = 64)
|
|
||||||
private String lastName;
|
|
||||||
@Column(nullable = false, unique = true, length = 11)
|
|
||||||
@NotBlank(message = "phoneNumber can't be null or empty")
|
|
||||||
@Size(min = 11, max = 11)
|
|
||||||
private String phoneNumber;
|
|
||||||
@Column(nullable = false, length = 64)
|
|
||||||
@NotBlank(message = "password can't be null or empty")
|
|
||||||
@Size(min = 6, max = 64)
|
|
||||||
private String password;
|
|
||||||
private UserRole role;
|
|
||||||
|
|
||||||
public User() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public User(String firstName, String lastName, String phoneNumber, String password, UserRole role) {
|
|
||||||
this.firstName = firstName;
|
|
||||||
this.lastName = lastName;
|
|
||||||
this.phoneNumber = phoneNumber;
|
|
||||||
this.password = password;
|
|
||||||
this.role = role;
|
|
||||||
}
|
|
||||||
|
|
||||||
public User(UserSignupDto dto) {
|
|
||||||
this.firstName = dto.getFirstName();
|
|
||||||
this.lastName = dto.getLastName();
|
|
||||||
this.phoneNumber = dto.getPhoneNumber();
|
|
||||||
this.password = dto.getPassword();
|
|
||||||
this.role = UserRole.USER;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserRole getRole() {
|
|
||||||
return role;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFirstName() {
|
|
||||||
return firstName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFirstName(String firstName) {
|
|
||||||
this.firstName = firstName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLastName() {
|
|
||||||
return lastName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastName(String lastName) {
|
|
||||||
this.lastName = lastName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPhoneNumber() {
|
|
||||||
return phoneNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPhoneNumber(String phoneNumber) {
|
|
||||||
this.phoneNumber = phoneNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
|
||||||
User user = (User) o;
|
|
||||||
return Objects.equals(id, user.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "User{" +
|
|
||||||
"id=" + id +
|
|
||||||
", firstName='" + firstName + '\'' +
|
|
||||||
", lastName='" + lastName + '\'' +
|
|
||||||
", phoneNumber='" + phoneNumber + '\'' +
|
|
||||||
", role=" + role.getAuthority() +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
package com.car.rental.rental.model;
|
|
||||||
|
|
||||||
import org.springframework.security.core.GrantedAuthority;
|
|
||||||
|
|
||||||
public enum UserRole implements GrantedAuthority {
|
|
||||||
ADMIN,
|
|
||||||
USER;
|
|
||||||
|
|
||||||
private static final String PREFIX = "ROLE_";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getAuthority() {
|
|
||||||
return PREFIX + this.name();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final class AsString {
|
|
||||||
public static final String ADMIN = PREFIX + "ADMIN";
|
|
||||||
public static final String USER = PREFIX + "USER";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
package com.car.rental.rental.model.enums;
|
|
||||||
|
|
||||||
public enum BodyType {
|
|
||||||
SEDAN,
|
|
||||||
HATCHBACK,
|
|
||||||
COUPE,
|
|
||||||
CONVERTIBLE,
|
|
||||||
SUV,
|
|
||||||
STATION_WAGON,
|
|
||||||
TRUCK,
|
|
||||||
VAN,
|
|
||||||
OTHER
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
package com.car.rental.rental.model.enums;
|
|
||||||
|
|
||||||
public enum CarStatus {
|
|
||||||
// доступен
|
|
||||||
AVAILABLE,
|
|
||||||
// забронирован
|
|
||||||
BOOKED,
|
|
||||||
// в аренде
|
|
||||||
RENTED,
|
|
||||||
// поврежден
|
|
||||||
DAMAGED,
|
|
||||||
// на обслуживании
|
|
||||||
MAINTENANCE,
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package com.car.rental.rental.model.enums;
|
|
||||||
|
|
||||||
public enum DriveUnitType {
|
|
||||||
FRONT_WHEEL_DRIVE,
|
|
||||||
REAR_WHEEL_DRIVE,
|
|
||||||
ALL_WHEEL_DRIVE,
|
|
||||||
FOUR_WHEEL_DRIVE,
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
package com.car.rental.rental.model.enums;
|
|
||||||
|
|
||||||
public enum OrderStatus {
|
|
||||||
BOOKING,
|
|
||||||
RENTAL
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package com.car.rental.rental.model.enums;
|
|
||||||
|
|
||||||
public enum TransmissionType {
|
|
||||||
AUTOMATIC,
|
|
||||||
MECHANICAL,
|
|
||||||
ROBOTIC,
|
|
||||||
VARIABLE
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package com.car.rental.rental.repository;
|
|
||||||
|
|
||||||
import com.car.rental.rental.model.Brand;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
|
|
||||||
public interface BrandRepository extends JpaRepository<Brand, Long> {
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package com.car.rental.rental.repository;
|
|
||||||
|
|
||||||
import com.car.rental.rental.model.Car;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
|
|
||||||
public interface CarRepository extends JpaRepository<Car, Long> {
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package com.car.rental.rental.repository;
|
|
||||||
|
|
||||||
import com.car.rental.rental.model.Model;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
|
|
||||||
public interface ModelRepository extends JpaRepository<Model, Long> {
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package com.car.rental.rental.repository;
|
|
||||||
|
|
||||||
import com.car.rental.rental.model.Order;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
|
|
||||||
public interface OrderRepository extends JpaRepository<Order, Long> {
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
package com.car.rental.rental.repository;
|
|
||||||
|
|
||||||
import com.car.rental.rental.model.User;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
|
|
||||||
public interface UserRepository extends JpaRepository<User, Long> {
|
|
||||||
User findOneByPhoneNumberIgnoreCase(String login);
|
|
||||||
}
|
|
@ -1,68 +0,0 @@
|
|||||||
package com.car.rental.rental.service;
|
|
||||||
|
|
||||||
import com.car.rental.rental.dto.BrandDto;
|
|
||||||
import com.car.rental.rental.model.Brand;
|
|
||||||
import com.car.rental.rental.repository.BrandRepository;
|
|
||||||
import com.car.rental.rental.util.validation.ValidatorUtil;
|
|
||||||
import jakarta.persistence.EntityNotFoundException;
|
|
||||||
import jakarta.transaction.Transactional;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class BrandService {
|
|
||||||
private final BrandRepository brandRepository;
|
|
||||||
private final ValidatorUtil validatorUtil;
|
|
||||||
|
|
||||||
public BrandService(BrandRepository brandRepository, ValidatorUtil validatorUtil) {
|
|
||||||
this.brandRepository = brandRepository;
|
|
||||||
this.validatorUtil = validatorUtil;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Brand addBrand(BrandDto dto) {
|
|
||||||
final Brand brand = new Brand(dto);
|
|
||||||
validatorUtil.validate(brand);
|
|
||||||
return brandRepository.save(brand);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Brand addBrand(String name) {
|
|
||||||
final Brand brand = new Brand(name);
|
|
||||||
validatorUtil.validate(brand);
|
|
||||||
return brandRepository.save(brand);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Brand findBrand(Long id) {
|
|
||||||
final Optional<Brand> brand = brandRepository.findById(id);
|
|
||||||
return brand.orElseThrow(() -> new EntityNotFoundException("Brand with id " + id + "doesn't exist"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public List<Brand> findAllBrands() {
|
|
||||||
return brandRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Brand updateBrand(BrandDto brand) {
|
|
||||||
final Brand currentBrand = findBrand(brand.getId());
|
|
||||||
currentBrand.setName(brand.getName());
|
|
||||||
validatorUtil.validate(currentBrand);
|
|
||||||
return brandRepository.save(currentBrand);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Brand deleteBrand(Long id) {
|
|
||||||
final Brand currentBrand = findBrand(id);
|
|
||||||
brandRepository.delete(currentBrand);
|
|
||||||
return currentBrand;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void deleteAllBrands() {
|
|
||||||
brandRepository.deleteAll();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
package com.car.rental.rental.service;
|
|
||||||
|
|
||||||
import com.car.rental.rental.dto.CarDto;
|
|
||||||
import com.car.rental.rental.model.Car;
|
|
||||||
import com.car.rental.rental.repository.CarRepository;
|
|
||||||
import com.car.rental.rental.util.validation.ValidatorUtil;
|
|
||||||
import jakarta.persistence.EntityNotFoundException;
|
|
||||||
import jakarta.transaction.Transactional;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class CarService {
|
|
||||||
private final CarRepository carRepository;
|
|
||||||
private final ValidatorUtil validatorUtil;
|
|
||||||
|
|
||||||
public CarService(CarRepository carRepository, ValidatorUtil validatorUtil) {
|
|
||||||
this.carRepository = carRepository;
|
|
||||||
this.validatorUtil = validatorUtil;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Car addCar(CarDto dto) {
|
|
||||||
final Car car = new Car(dto);
|
|
||||||
validatorUtil.validate(car);
|
|
||||||
return carRepository.save(car);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Car findCar(Long id) {
|
|
||||||
final Optional<Car> car = carRepository.findById(id);
|
|
||||||
return car.orElseThrow(() -> new EntityNotFoundException("Car with id " + id + "doesn't exist"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public List<Car> findAllCars() {
|
|
||||||
return carRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Car updateCar(CarDto car) {
|
|
||||||
final Car currentCar = findCar(car.getId());
|
|
||||||
currentCar.setPrice(car.getPrice());
|
|
||||||
currentCar.setDescription(car.getDescription());
|
|
||||||
validatorUtil.validate(currentCar);
|
|
||||||
return carRepository.save(currentCar);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Car deleteCar(Long id) {
|
|
||||||
final Car currentCar = findCar(id);
|
|
||||||
carRepository.delete(currentCar);
|
|
||||||
return currentCar;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void deleteAllCars() {
|
|
||||||
carRepository.deleteAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
|||||||
package com.car.rental.rental.service;
|
|
||||||
|
|
||||||
import com.car.rental.rental.dto.ModelDto;
|
|
||||||
import com.car.rental.rental.model.Model;
|
|
||||||
import com.car.rental.rental.repository.ModelRepository;
|
|
||||||
import com.car.rental.rental.util.validation.ValidatorUtil;
|
|
||||||
import jakarta.persistence.EntityNotFoundException;
|
|
||||||
import jakarta.transaction.Transactional;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class ModelService {
|
|
||||||
private final ModelRepository modelRepository;
|
|
||||||
private final ValidatorUtil validatorUtil;
|
|
||||||
|
|
||||||
public ModelService(ModelRepository modelRepository, ValidatorUtil validatorUtil) {
|
|
||||||
this.modelRepository = modelRepository;
|
|
||||||
this.validatorUtil = validatorUtil;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Model addModel(ModelDto dto) {
|
|
||||||
final Model model = new Model(dto);
|
|
||||||
validatorUtil.validate(model);
|
|
||||||
return modelRepository.save(model);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Model findModel(Long id) {
|
|
||||||
final Optional<Model> model = modelRepository.findById(id);
|
|
||||||
return model.orElseThrow(() -> new EntityNotFoundException("Model with id " + id + "doesn't exist"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public List<Model> findAllModels() {
|
|
||||||
return modelRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Model deleteModel(Long id) {
|
|
||||||
final Model currentModel = findModel(id);
|
|
||||||
modelRepository.delete(currentModel);
|
|
||||||
return currentModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void deleteAllModels() {
|
|
||||||
modelRepository.deleteAll();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,103 +0,0 @@
|
|||||||
package com.car.rental.rental.service;
|
|
||||||
|
|
||||||
import com.car.rental.rental.dto.OrderDto;
|
|
||||||
import com.car.rental.rental.model.Order;
|
|
||||||
import com.car.rental.rental.model.User;
|
|
||||||
import com.car.rental.rental.repository.OrderRepository;
|
|
||||||
import com.car.rental.rental.util.validation.ValidatorUtil;
|
|
||||||
import jakarta.persistence.EntityNotFoundException;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.sql.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class OrderService {
|
|
||||||
private final OrderRepository orderRepository;
|
|
||||||
private final UserService userService;
|
|
||||||
private final CarService carService;
|
|
||||||
private final ValidatorUtil validatorUtil;
|
|
||||||
|
|
||||||
public OrderService(OrderRepository orderRepository, UserService userService, CarService carService, ValidatorUtil validatorUtil) {
|
|
||||||
this.orderRepository = orderRepository;
|
|
||||||
this.userService = userService;
|
|
||||||
this.carService = carService;
|
|
||||||
this.validatorUtil = validatorUtil;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Order addOrder(OrderDto orderDto, Long userId) {
|
|
||||||
final Order order = new Order(orderDto);
|
|
||||||
final User user = userService.findUser(userId);
|
|
||||||
order.setUser(user);
|
|
||||||
validatorUtil.validate(order);
|
|
||||||
return orderRepository.save(order);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Order addCar(Long id, Long carId, Integer count) {
|
|
||||||
final Car currentCar = carService.findCar(carId);
|
|
||||||
final Order currentOrder = findOrder(id);
|
|
||||||
final OrderCar currentOrderCar = orderRepository.getOrderCar(id, carId);
|
|
||||||
|
|
||||||
final Integer currentCarCapacity = currentCar.getMaxCount() - carService.getCapacity(carId);
|
|
||||||
if (currentCarCapacity < count ||
|
|
||||||
(currentOrderCar != null && currentOrderCar.getCount() + count > currentCar.getMaxCount())) {
|
|
||||||
throw new IllegalArgumentException(String.format("No more tickets in car. Capacity: %1$s. Count: %2$s",
|
|
||||||
currentCarCapacity, count));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentOrderCar == null) {
|
|
||||||
currentOrder.addCar(new OrderCar(currentOrder, currentCar, count));
|
|
||||||
}
|
|
||||||
else if (currentOrderCar.getCount() + count <= currentCar.getMaxCount()) {
|
|
||||||
currentOrder.removeCar(currentOrderCar);
|
|
||||||
currentOrder.addCar(new OrderCar(currentOrder, currentCar,
|
|
||||||
currentOrderCar.getCount() + count));
|
|
||||||
}
|
|
||||||
|
|
||||||
return orderRepository.save(currentOrder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public Order findOrder(Long id) {
|
|
||||||
final Optional<Order> order = orderRepository.findById(id);
|
|
||||||
return order.orElseThrow(() -> new OrderNotFoundException(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public List<Order> findAllOrders() {
|
|
||||||
return orderRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Order deleteOrder(Long id) {
|
|
||||||
final Order currentOrder = findOrder(id);
|
|
||||||
orderRepository.delete(currentOrder);
|
|
||||||
return currentOrder;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public Order deleteCarInOrder(Long id, Long car, Integer count) {
|
|
||||||
final Order currentOrder = findOrder(id);
|
|
||||||
final Car currentCar = carService.findCar(car);
|
|
||||||
final OrderCar currentOrderCar = orderRepository.getOrderCar(id, car);
|
|
||||||
if (currentOrderCar == null)
|
|
||||||
throw new EntityNotFoundException();
|
|
||||||
|
|
||||||
if (count >= currentOrderCar.getCount()) {
|
|
||||||
currentOrder.removeCar(currentOrderCar);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
currentOrder.removeCar(currentOrderCar);
|
|
||||||
currentOrder.addCar(new OrderCar(currentOrder, currentCar,
|
|
||||||
currentOrderCar.getCount() - count));
|
|
||||||
}
|
|
||||||
return orderRepository.save(currentOrder);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void deleteAllOrders() {
|
|
||||||
orderRepository.deleteAll();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,119 +0,0 @@
|
|||||||
package com.car.rental.rental.service;
|
|
||||||
|
|
||||||
import com.car.rental.rental.model.User;
|
|
||||||
import com.car.rental.rental.model.UserRole;
|
|
||||||
import com.car.rental.rental.dto.UserSignupDto;
|
|
||||||
import com.car.rental.rental.repository.UserRepository;
|
|
||||||
import com.car.rental.rental.util.validation.ValidatorUtil;
|
|
||||||
import jakarta.persistence.EntityNotFoundException;
|
|
||||||
import jakarta.validation.ValidationException;
|
|
||||||
import org.springframework.data.domain.Page;
|
|
||||||
import org.springframework.data.domain.PageRequest;
|
|
||||||
import org.springframework.data.domain.Sort;
|
|
||||||
import org.springframework.security.core.userdetails.UserDetails;
|
|
||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
|
||||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class UserService implements UserDetailsService {
|
|
||||||
private final UserRepository userRepository;
|
|
||||||
private final PasswordEncoder passwordEncoder;
|
|
||||||
private final ValidatorUtil validatorUtil;
|
|
||||||
|
|
||||||
public UserService(UserRepository userRepository, PasswordEncoder passwordEncoder, ValidatorUtil validatorUtil) {
|
|
||||||
this.userRepository = userRepository;
|
|
||||||
this.passwordEncoder = passwordEncoder;
|
|
||||||
this.validatorUtil = validatorUtil;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Page<User> findAllPages(int page, int size) {
|
|
||||||
return userRepository.findAll(PageRequest.of(page - 1, size, Sort.by("id").ascending()));
|
|
||||||
}
|
|
||||||
|
|
||||||
public User findByLogin(String login) {
|
|
||||||
return userRepository.findOneByPhoneNumberIgnoreCase(login);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public User addUser(String name, String lastName, String login, String password, String passwordConfirm) {
|
|
||||||
return createUser(name, lastName, login, password, passwordConfirm, UserRole.USER);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public User addUser(UserSignupDto userSignupDto) {
|
|
||||||
if (findByLogin(userSignupDto.getPhoneNumber()) != null) {
|
|
||||||
throw new ValidationException(String.format("User with number '%s' already exists", userSignupDto.getPhoneNumber()));
|
|
||||||
}
|
|
||||||
if (!Objects.equals(userSignupDto.getPassword(), userSignupDto.getPasswordConfirm())) {
|
|
||||||
throw new ValidationException("Passwords not equals");
|
|
||||||
}
|
|
||||||
final User user = new User(userSignupDto);
|
|
||||||
validatorUtil.validate(user);
|
|
||||||
return userRepository.save(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
public User createUser(String name, String lastName, String login, String password, String passwordConfirm, UserRole role) {
|
|
||||||
if (findByLogin(login) != null) {
|
|
||||||
throw new ValidationException(String.format("User '%s' already exists", login));
|
|
||||||
}
|
|
||||||
final User user = new User(name, lastName, login, passwordEncoder.encode(password), role);
|
|
||||||
validatorUtil.validate(user);
|
|
||||||
if (!Objects.equals(password, passwordConfirm)) {
|
|
||||||
throw new ValidationException("Passwords not equals");
|
|
||||||
}
|
|
||||||
return userRepository.save(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public User findUser(Long id) {
|
|
||||||
final Optional<User> user = userRepository.findById(id);
|
|
||||||
return user.orElseThrow(() -> new EntityNotFoundException("User with id " + id + " doesn't exist"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
|
||||||
public List<User> findAllUsers() {
|
|
||||||
return userRepository.findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public User updateUser(Long id, String name, String lastName, String phoneNumber, String password) {
|
|
||||||
final User currentUser = findUser(id);
|
|
||||||
currentUser.setFirstName(name);
|
|
||||||
currentUser.setLastName(lastName);
|
|
||||||
currentUser.setPhoneNumber(phoneNumber);
|
|
||||||
currentUser.setPassword(password);
|
|
||||||
validatorUtil.validate(currentUser);
|
|
||||||
return userRepository.save(currentUser);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public User deleteUser(Long id) {
|
|
||||||
final User user = findUser(id);
|
|
||||||
userRepository.deleteById(id);
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
|
||||||
public void deleteAllUsers() {
|
|
||||||
userRepository.deleteAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
|
||||||
final User userEntity = findByLogin(username);
|
|
||||||
if (userEntity == null) {
|
|
||||||
throw new UsernameNotFoundException(username);
|
|
||||||
}
|
|
||||||
return new org.springframework.security.core.userdetails.User(
|
|
||||||
userEntity.getPhoneNumber(), userEntity.getPassword(), Collections.singleton(userEntity.getRole()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
|||||||
package com.car.rental.rental.util.error;
|
|
||||||
|
|
||||||
import com.car.rental.rental.util.validation.ValidationException;
|
|
||||||
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
|
||||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
||||||
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@ControllerAdvice
|
|
||||||
public class AdviceController {
|
|
||||||
@ExceptionHandler({
|
|
||||||
ValidationException.class,
|
|
||||||
IllegalArgumentException.class
|
|
||||||
})
|
|
||||||
public ResponseEntity<Object> handleException(Throwable e) {
|
|
||||||
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
|
||||||
public ResponseEntity<Object> handleBindException(MethodArgumentNotValidException e) {
|
|
||||||
final ValidationException validationException = new ValidationException(
|
|
||||||
e.getBindingResult().getAllErrors().stream()
|
|
||||||
.map(DefaultMessageSourceResolvable::getDefaultMessage)
|
|
||||||
.collect(Collectors.toSet()));
|
|
||||||
return handleException(validationException);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ExceptionHandler(Exception.class)
|
|
||||||
public ResponseEntity<Object> handleUnknownException(Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
package com.car.rental.rental.util.validation;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class ValidationException extends RuntimeException {
|
|
||||||
public ValidationException(Set<String> errors) {
|
|
||||||
super(String.join("\n", errors));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
package com.car.rental.rental.util.validation;
|
|
||||||
|
|
||||||
import jakarta.validation.ConstraintViolation;
|
|
||||||
import jakarta.validation.Validation;
|
|
||||||
import jakarta.validation.Validator;
|
|
||||||
import jakarta.validation.ValidatorFactory;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class ValidatorUtil {
|
|
||||||
private final Validator validator;
|
|
||||||
|
|
||||||
public ValidatorUtil() {
|
|
||||||
try (ValidatorFactory factory = Validation.buildDefaultValidatorFactory()) {
|
|
||||||
this.validator = factory.getValidator();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public <T> void validate(T object) {
|
|
||||||
final Set<ConstraintViolation<T>> errors = validator.validate(object);
|
|
||||||
if (!errors.isEmpty()) {
|
|
||||||
throw new ValidationException(errors.stream()
|
|
||||||
.map(ConstraintViolation::getMessage)
|
|
||||||
.collect(Collectors.toSet()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
spring.main.banner-mode=off
|
|
||||||
spring.datasource.url=jdbc:h2:file:./data
|
|
||||||
spring.datasource.driverClassName=org.h2.Driver
|
|
||||||
spring.datasource.username=sa
|
|
||||||
spring.datasource.password=password
|
|
||||||
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
|
||||||
spring.jpa.hibernate.ddl-auto=update
|
|
||||||
spring.h2.console.enabled=true
|
|
||||||
spring.h2.console.settings.trace=false
|
|
||||||
spring.h2.console.settings.web-allow-others=false
|
|
@ -1,16 +0,0 @@
|
|||||||
html {
|
|
||||||
position: relative;
|
|
||||||
min-height: 100%;
|
|
||||||
}
|
|
||||||
main {
|
|
||||||
padding-top: 60px; /* Размер высоты header */
|
|
||||||
}
|
|
||||||
|
|
||||||
.footer {
|
|
||||||
position: absolute;
|
|
||||||
bottom: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 60px;
|
|
||||||
background-color: #f5f5f5;
|
|
||||||
line-height: 60px;
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg"
|
|
||||||
viewBox="0 0 448 512"><!--! Font Awesome Pro 6.1.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. -->
|
|
||||||
<path d="M448 48V384c-63.09 22.54-82.34 32-119.5 32c-62.82 0-86.6-32-149.3-32C158.6 384 142.6 387.6 128 392.2v-64C142.6 323.6 158.6 320 179.2 320c62.73 0 86.51 32 149.3 32C348.9 352 364.1 349 384 342.7v-208C364.1 141 348.9 144 328.5 144c-62.82 0-86.6-32-149.3-32C128.4 112 104.3 132.6 64 140.7v307.3C64 465.7 49.67 480 32 480S0 465.7 0 448V63.1C0 46.33 14.33 32 31.1 32S64 46.33 64 63.1V76.66C104.3 68.63 128.4 48 179.2 48c62.73 0 86.51 32 149.3 32C365.7 80 384.9 70.54 448 48z"/>
|
|
||||||
</svg>
|
|
Before Width: | Height: | Size: 727 B |
@ -1,71 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="ru"
|
|
||||||
xmlns:th="http://www.thymeleaf.org"
|
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
|
||||||
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity6">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8"/>
|
|
||||||
<title>Аренда авто</title>
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
||||||
<link rel="icon" href="/favicon.svg">
|
|
||||||
<script type="text/javascript" src="/webjars/bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
|
|
||||||
<link rel="stylesheet" href="/webjars/bootstrap/5.1.3/css/bootstrap.min.css"/>
|
|
||||||
<link rel="stylesheet" href="/webjars/font-awesome/6.1.0/css/all.min.css"/>
|
|
||||||
<link rel="stylesheet" href="/css/style.css"/>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
|
|
||||||
<header>
|
|
||||||
<!-- Fixed navbar -->
|
|
||||||
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
|
|
||||||
<a class="navbar-brand ms-3" href="#">Аренда автомобилей</a>
|
|
||||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse"
|
|
||||||
aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
|
|
||||||
<span class="navbar-toggler-icon"></span>
|
|
||||||
</button>
|
|
||||||
<div class="collapse navbar-collapse" id="navbarCollapse">
|
|
||||||
<ul class="navbar-nav" sec:authorize="!isAuthenticated()">
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="/login">Вход</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<ul class="navbar-nav" sec:authorize="isAuthenticated()">
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="/">Главная</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="/car">Машины</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a sec:authorize="hasRole('ROLE_ADMIN')" class="nav-link" href="/user">Пользователи</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="/order">Заказы</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="/h2-console/" target="_blank"
|
|
||||||
sec:authorize="hasRole('ROLE_ADMIN')">Консоль H2</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="/logout">Выход</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<!-- Begin page content -->
|
|
||||||
<main role="main" class="container">
|
|
||||||
<div layout:fragment="content">
|
|
||||||
</div>
|
|
||||||
</main>
|
|
||||||
|
|
||||||
<footer class="footer">
|
|
||||||
<div class="container">
|
|
||||||
<span class="text-muted">© 2023 ООО «Автоцарь»</span>
|
|
||||||
</div>
|
|
||||||
</footer>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
<th:block layout:fragment="scripts">
|
|
||||||
</th:block>
|
|
@ -1,13 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en"
|
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
|
||||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div layout:fragment="content">
|
|
||||||
<div><span th:text="${error}"></span></div>
|
|
||||||
<a href="/">На главную</a>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,12 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en"
|
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
|
||||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div layout:fragment="content">
|
|
||||||
Сайт работает!
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,32 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en"
|
|
||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
|
||||||
layout:decorate="~{default}" xmlns:th="http://www.w3.org/1999/xhtml">
|
|
||||||
<body>
|
|
||||||
<head>
|
|
||||||
</head>
|
|
||||||
<div layout:fragment="content">
|
|
||||||
<div th:if="${param.error}" class="alert alert-danger margin-bottom">
|
|
||||||
Пользователь не найден или пароль указан неверно
|
|
||||||
</div>
|
|
||||||
<div th:if="${param.logout}" class="alert alert-success margin-bottom">
|
|
||||||
Выход успешно произведен
|
|
||||||
</div>
|
|
||||||
<div th:if="${param.created}" class="alert alert-success margin-bottom">
|
|
||||||
Пользователь '<span th:text="${param.created}"></span>' успешно создан
|
|
||||||
</div>
|
|
||||||
<form th:action="@{/login}" method="post">
|
|
||||||
<div class="mb-3">
|
|
||||||
<input type="text" name="username" id="username" class="form-control"
|
|
||||||
placeholder="Логин" required="true" autofocus="true"/>
|
|
||||||
</div>
|
|
||||||
<div class="mb-3">
|
|
||||||
<input type="password" name="password" id="password" class="form-control"
|
|
||||||
placeholder="Пароль" required="true"/>
|
|
||||||
</div>
|
|
||||||
<button type="submit" class="btn btn-success button-fixed">Войти</button>
|
|
||||||
<a class="btn btn-primary button-fixed" href="/signup">Регистрация</a>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,13 +0,0 @@
|
|||||||
package com.car.rental;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
class RentalApplicationTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void contextLoads() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
FROM bellsoft/liberica-openjdk-alpine:17.0.8
|
FROM bellsoft/liberica-openjdk-alpine:17.0.8
|
||||||
ADD target/report-0.0.1-SNAPSHOT.jar /app/
|
ADD target/report-0.0.1-SNAPSHOT.jar /app/
|
||||||
CMD ["java", "-Xmx200m", "-jar", "/app/report-0.0.1-SNAPSHOT.jar"]
|
CMD ["java", "-Xmx200m", "-jar", "/app/report-0.0.1-SNAPSHOT.jar"]
|
||||||
EXPOSE 8080
|
EXPOSE 8082
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
version: '3.8'
|
|
||||||
|
|
||||||
services:
|
|
||||||
postgres:
|
|
||||||
image: postgres:16-alpine
|
|
||||||
environment:
|
|
||||||
POSTGRES_DB: Rental
|
|
||||||
POSTGRES_USER: role_for_spring
|
|
||||||
POSTGRES_PASSWORD: ${DB_PASSWORD}
|
|
||||||
ports:
|
|
||||||
- "5433:5432"
|
|
||||||
networks:
|
|
||||||
backend:
|
|
||||||
aliases:
|
|
||||||
- "postgres"
|
|
||||||
|
|
||||||
report:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
ports:
|
|
||||||
- "8082:8082"
|
|
||||||
depends_on:
|
|
||||||
- postgres
|
|
||||||
environment:
|
|
||||||
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/Rental
|
|
||||||
SPRING_DATASOURCE_USERNAME: role_for_spring
|
|
||||||
SPRING_DATASOURCE_PASSWORD: ${DB_PASSWORD}
|
|
||||||
networks:
|
|
||||||
backend:
|
|
||||||
aliases:
|
|
||||||
- "report"
|
|
||||||
|
|
||||||
networks:
|
|
||||||
backend:
|
|
||||||
driver: bridge
|
|
Loading…
Reference in New Issue
Block a user