Compare commits

..

No commits in common. "bfbcd5c44b3247146ae7541b7048d5ec059f5b50" and "f3a6cdb3e96c1e2a5503e1c3035825cec54d1e79" have entirely different histories.

21 changed files with 0 additions and 1209 deletions

24
.gitignore vendored
View File

@ -1,24 +0,0 @@
# Compiled class file
*.class
# Log file
*.log
# Package Files
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# private file with login-data
application.properties
.idea/
.gradle/

View File

@ -1,31 +1,2 @@
# VPR-Backend
This project includes the backend for the VPR-project.
# Installation and Getting Started
- To run the server you first have to install a MySQL database.
> For example MariaDB (https://mariadb.com/downloads/)
- Then you have to create a the database with the "create VPR-DB.sql"-file.
- Create a new user for the db e.g. named "springuser"
> The database should only be reachable from localhost to improve the security!
- Next create a "application.properties"-file in "vpr/src/main/resources". It should contain following content:
```
# "update" will automatically get the db-structure
# It can be "none", "update", "create", or "create-drop", but you have to start with "create" or "update" and should use "none" in production(for security).
# see https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#configurations-hbmddl for more information.
spring.jpa.hibernate.ddl-auto=update
# Specify the database address, port and name
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/vpr
# Add the login-data
spring.datasource.username=<USERNAME>
spring.datasource.password=<PASSWORD>
spring.datasource.driver-class-name =com.mysql.jdbc.Driver
#spring.jpa.show-sql: true
```
You should now be able to start the application :D

View File

@ -1,91 +0,0 @@
-- --------------------------------------------------------
-- Host: 127.0.0.1
-- Server Version: 10.6.4-MariaDB - mariadb.org binary distribution
-- Server Betriebssystem: Win64
-- HeidiSQL Version: 11.3.0.6295
-- --------------------------------------------------------
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
-- Exportiere Datenbank Struktur für vpr
CREATE DATABASE IF NOT EXISTS `vpr` /*!40100 DEFAULT CHARACTER SET utf8mb3 */;
USE `vpr`;
-- Exportiere Struktur von Tabelle vpr.event
CREATE TABLE IF NOT EXISTS `event` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL DEFAULT '0',
`priority` tinyint(2) unsigned NOT NULL DEFAULT 0,
`is_full_day` bit(1) NOT NULL DEFAULT b'0',
`start` time DEFAULT NULL,
`end` time DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb3;
-- Exportiere Daten aus Tabelle vpr.event: ~2 rows (ungefähr)
/*!40000 ALTER TABLE `event` DISABLE KEYS */;
INSERT INTO `event` (`id`, `name`, `priority`, `is_full_day`, `start`, `end`) VALUES
(1, 'TestEvent', 0, b'0', '00:00:00', '00:00:00'),
(2, 'Event 2', 1, b'0', NULL, NULL);
/*!40000 ALTER TABLE `event` ENABLE KEYS */;
-- Exportiere Struktur von Tabelle vpr.event_list
CREATE TABLE IF NOT EXISTS `event_list` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`user_id` int(10) unsigned NOT NULL,
`event_id` int(10) unsigned NOT NULL,
`date` date DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `UID` (`user_id`) USING BTREE,
KEY `EID` (`event_id`) USING BTREE,
CONSTRAINT `event_id` FOREIGN KEY (`event_id`) REFERENCES `event` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb3;
-- Exportiere Daten aus Tabelle vpr.event_list: ~2 rows (ungefähr)
/*!40000 ALTER TABLE `event_list` DISABLE KEYS */;
INSERT INTO `event_list` (`id`, `user_id`, `event_id`, `date`) VALUES
(1, 1, 2, '2021-11-11'),
(2, 2, 1, '2021-12-24');
/*!40000 ALTER TABLE `event_list` ENABLE KEYS */;
-- Exportiere Struktur von Tabelle vpr.hibernate_sequence
CREATE TABLE IF NOT EXISTS `hibernate_sequence` (
`next_val` bigint(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
-- Exportiere Daten aus Tabelle vpr.hibernate_sequence: ~1 rows (ungefähr)
/*!40000 ALTER TABLE `hibernate_sequence` DISABLE KEYS */;
INSERT INTO `hibernate_sequence` (`next_val`) VALUES
(3);
/*!40000 ALTER TABLE `hibernate_sequence` ENABLE KEYS */;
-- Exportiere Struktur von Tabelle vpr.user
CREATE TABLE IF NOT EXISTS `user` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL DEFAULT '0',
`forename` varchar(20) NOT NULL DEFAULT '0',
`password` varchar(50) NOT NULL DEFAULT '0',
`token` varchar(50) DEFAULT '0',
`is_admin` bit(1) NOT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb3;
-- Exportiere Daten aus Tabelle vpr.user: ~3 rows (ungefähr)
/*!40000 ALTER TABLE `user` DISABLE KEYS */;
INSERT INTO `user` (`id`, `name`, `forename`, `password`, `token`, `is_admin`) VALUES
(1, 'Beyer', 'Marc', 'test', 'test', b'1'),
(2, 'Kühn', 'Marco', 'test', 'test', b'0'),
(3, 'Rechtin', 'Alex', 'test', 'test', b'1');
/*!40000 ALTER TABLE `user` ENABLE KEYS */;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40111 SET SQL_NOTES=IFNULL(@OLD_SQL_NOTES, 1) */;

37
server/.gitignore vendored
View File

@ -1,37 +0,0 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/

View File

@ -1,24 +0,0 @@
plugins {
id 'org.springframework.boot' version '2.5.6'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.vpr'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'mysql:mysql-connector-java'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}

Binary file not shown.

View File

@ -1,5 +0,0 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

234
server/gradlew vendored
View File

@ -1,234 +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/master/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
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
APP_BASE_NAME=${0##*/}
# 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"'
# 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
which java >/dev/null 2>&1 || 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
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
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
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# 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" "$@"

89
server/gradlew.bat vendored
View File

@ -1,89 +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=.
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%" == "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%"=="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!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@ -1 +0,0 @@
rootProject.name = 'server'

View File

@ -1,118 +0,0 @@
package com.vpr.server;
import java.sql.Date;
import java.sql.Time;
public class DateEvent {
private long userId;
private String userName;
private String userForename;
private Date date;
private String name;
private Integer priority;
private boolean isFullDay;
private Time start;
private Time end;
public DateEvent(UserEvent userEvent) {
this.userId = userEvent.getUser().getId();
this.userName = userEvent.getUser().getName();
this.userForename = userEvent.getUser().getForename();
this.date = userEvent.getDate();
this.name = userEvent.getEvent().getName();
this.priority = userEvent.getEvent().getPriority();
this.isFullDay = userEvent.getEvent().isFullDay();
this.start = userEvent.getEvent().getStart();
this.end = userEvent.getEvent().getEnd();
}
public DateEvent(long userId, String userName, String userForename, Date date, String name, Integer priority, boolean isFullDay, Time start, Time end) {
this.userId = userId;
this.userName = userName;
this.userForename = userForename;
this.date = date;
this.name = name;
this.priority = priority;
this.isFullDay = isFullDay;
this.start = start;
this.end = end;
}
/*********************
* Getter and Setter *
*********************/
public long getUserId() {
return userId;
}
public void setUserId(long userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserForename() {
return userForename;
}
public void setUserForename(String userForename) {
this.userForename = userForename;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getPriority() {
return priority;
}
public void setPriority(Integer priority) {
this.priority = priority;
}
public boolean isFullDay() {
return isFullDay;
}
public void setFullDay(boolean fullDay) {
isFullDay = fullDay;
}
public Time getStart() {
return start;
}
public void setStart(Time start) {
this.start = start;
}
public Time getEnd() {
return end;
}
public void setEnd(Time end) {
this.end = end;
}
}

View File

@ -1,117 +0,0 @@
package com.vpr.server;
import javax.persistence.*;
import java.sql.Time;
import java.util.List;
// @Entity creates a table out of this class with Hibernate
@Entity(name = "Event")
public class Event {
// Generate the primary key
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private long id;
@Column(name="name", nullable=false)
private String name;
@Column(name="priority", nullable=false)
private Integer priority;
@Column(name="is_full_day", nullable=false)
private boolean isFullDay;
@Column(name="is_private", nullable=false)
private boolean isPrivate;
@Column(name="start")
private Time start;
@Column(name="end")
private Time end;
@OneToMany(mappedBy = "event")
private List<UserEvent> userEvent;
/*********************
* Getter and Setter *
*********************/
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getPriority() {
return priority;
}
public void setPriority(Integer priority) {
this.priority = priority;
}
public boolean isFullDay() {
return isFullDay;
}
public void setFullDay(boolean fullDay) {
isFullDay = fullDay;
}
public boolean isPrivate() {
return isPrivate;
}
public void setPrivate(boolean aPrivate) {
isPrivate = aPrivate;
}
public Time getStart() {
return start;
}
public void setStart(Time start) {
this.start = start;
}
public Time getEnd() {
return end;
}
public void setEnd(Time end) {
this.end = end;
}
public List<UserEvent> getUserEvent() {
return userEvent;
}
public void setUserEvent(List<UserEvent> userEvent) {
this.userEvent = userEvent;
}
// toString
@Override
public String toString() {
return "Event{" +
"id=" + id +
", name='" + name + '\'' +
", priority=" + priority +
", isFullDay=" + isFullDay +
", start=" + start +
", end=" + end +
", userEvent=" + userEvent +
'}';
}
}

View File

@ -1,47 +0,0 @@
package com.vpr.server;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import javax.transaction.Transactional;
import java.util.List;
// This will be AUTO IMPLEMENTED by Spring into a Bean called eventRepository
// CRUD refers Create, Read, Update, Delete
public interface EventRepository extends CrudRepository<Event, Integer> {
@Query(value = "SELECT e.id AS eid, e.name AS ename, e.start, e.end, e.priority , e.is_full_day, " +
"ue.date, " +
"u.id AS uid, u.forename, u.name AS uname " +
"FROM event e " +
"INNER JOIN user_event ue " +
"ON e.id = ue.event_id " +
"INNER JOIN user u " +
"ON ue.user_id = u.id " +
"WHERE u.id = ?1 " +
"OR e.is_private = 0",
nativeQuery = true)
Object[] findAllVisibleByUserId(long id);
@Query(value = "SELECT * " +
"FROM event e " +
"INNER JOIN user_event ue " +
"ON e.id = ue.event_id " +
"WHERE ue.user_id = ?1",
nativeQuery = true)
Object[] findAllByUserId(long id);
@Modifying
@Transactional
@Query(value = "DELETE ue FROM user_event ue WHERE ue.event_id = ?1",
nativeQuery = true)
void deleteUserEventsById(long id);
@Modifying
@Transactional
@Query(value = "DELETE e FROM event e WHERE e.id = ?1",
nativeQuery = true)
void deleteById(long id);
}

View File

@ -1,141 +0,0 @@
package com.vpr.server;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.sql.Date;
import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.Optional;
@Controller // This means that this class is a Controller
@RequestMapping(path="/vpr") // This means URL's start with /demo (after Application path)
public class MainController {
// This means to get the bean called userRepository
// Which is auto-generated by Spring, we will use it to handle the data
@Autowired
private com.vpr.server.UserRepository userRepository;
@Autowired
private EventRepository eventRepository;
@Autowired
private UserEventRepository userEventRepository;
// POST-request at /add with request parameter
// @ResponseBody means the returned String is the response, not a view name
@PostMapping(path="/add-user")
public @ResponseBody String addNewUser (
@RequestParam String name,
@RequestParam String forename,
@RequestParam String password,
@RequestParam String isAdmin
) {
com.vpr.server.User user = new com.vpr.server.User();
// TODO set correct token and password
user.setName(name);
user.setForename(forename);
user.setPassword(password);
user.setToken("test");
user.setAdmin(isAdmin.equals("1"));
userRepository.save(user);
return "Saved";
}
@PostMapping(path="/add-event")
public @ResponseBody String addEvent (
@RequestParam Integer userId,
@RequestParam String date,
@RequestParam String name,
@RequestParam String start,
@RequestParam String end,
@RequestParam Integer prority,
@RequestParam Boolean isFullDay,
@RequestParam Boolean isPrivate
) {
com.vpr.server.Event event = new com.vpr.server.Event();
event.setName(name);
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("hh:mm");
long ms = simpleDateFormat.parse(start).getTime();
event.setStart(new Time(ms));
}catch (Exception e){
event.setStart(null);
}
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("hh:mm");
long ms = simpleDateFormat.parse(end).getTime();
event.setEnd(new Time(ms));
}catch (Exception e){
event.setEnd(null);
}
event.setPriority(prority);
event.setFullDay(isFullDay);
event.setPrivate(isPrivate);
eventRepository.save(event);
com.vpr.server.UserEvent userEvent = new com.vpr.server.UserEvent();
try {
System.out.println("date " + date);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
userEvent.setDate(new java.sql.Date(simpleDateFormat.parse(date).getTime()));
}catch (Exception e){
System.out.println("DATE FORMAT NOT CORRECT");
}
userEvent.setEvent(event);
long uId = Long.valueOf(userId);
User user = userRepository.findById(uId);
userEvent.setUser(user);
System.out.println(userEvent);
System.out.println(user);
userEventRepository.save(userEvent);
return "Saved";
}
@PostMapping(path="/del-event")
public @ResponseBody String addEvent ( @RequestParam Integer eventId ) {
eventRepository.deleteUserEventsById(Long.valueOf(eventId));
eventRepository.deleteById(Long.valueOf(eventId));
return "Deleted";
}
// GET-request at /all-users
// returns JSON-data
@GetMapping(path="/all-users")
public @ResponseBody Object[] getAllUsers() {
return userRepository.findAllUsernames();
}
// POST-request at /all-events
// returns JSON-data
@PostMapping(path="/all-events")
public @ResponseBody Object[] getAllEvents(@RequestParam long userId) {
return eventRepository.findAllVisibleByUserId(userId);
}
@GetMapping(path="/all-events-test")
public @ResponseBody Iterable<com.vpr.server.Event> getAllEventsTest() {
return eventRepository.findAll();
}
}

View File

@ -1,13 +0,0 @@
package com.vpr.server;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class ServerApplication {
public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
}
}

View File

@ -1,91 +0,0 @@
package com.vpr.server;
import javax.persistence.*;
import java.util.List;
// @Entity creates a table out of this class with Hibernate
@Entity
public class User {
// Generate the primary key
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private long id;
@Column(name="name", nullable=false)
private String name;
@Column(name="forename", nullable=false)
private String forename;
@Column(name="password", nullable=false)
private String password;
@Column(name="token")
private String token;
@Column(name="is_admin", nullable=false)
private boolean isAdmin;
@OneToMany(mappedBy = "user")
private List<UserEvent> userEvent;
/*********************
* Getter and Setter *
*********************/
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getForename() {
return forename;
}
public void setForename(String forename) {
this.forename = forename;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public boolean isAdmin() {
return isAdmin;
}
public void setAdmin(boolean admin) {
isAdmin = admin;
}
public List<UserEvent> getEventList() {
return userEvent;
}
public void setEventList(List<UserEvent> userEvent) {
this.userEvent = userEvent;
}
}

View File

@ -1,64 +0,0 @@
package com.vpr.server;
import javax.persistence.*;
import java.sql.Date;
import java.util.List;
// @Entity creates a table out of this class with Hibernate
// @Table defines the table-name
@Entity
@Table(name="user_event")
@IdClass(UserEventId.class)
public class UserEvent {
@Id
@ManyToOne
@JoinColumn(name = "user_id", referencedColumnName = "id")
private User user;
@Id
@ManyToOne
@JoinColumn(name = "event_id", referencedColumnName = "id")
private Event event;
@Id
@Column(name="date", columnDefinition = "DATE DEFAULT CURRENT_DATE", nullable = false)
private Date date;
/*********************
* Getter and Setter *
*********************/
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Event getEvent() {
return event;
}
public void setEvent(Event event) {
this.event = event;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
// toString
@Override
public String toString() {
return "UserEvent{" +
"user=" + user.getId() +
", event=" + event.getId() +
", date=" + date +
'}';
}
}

View File

@ -1,38 +0,0 @@
package com.vpr.server;
import java.io.Serializable;
import java.sql.Date;
public class UserEventId implements Serializable {
private long user;
private long event;
private Date date;
/*********************
* Getter and Setter *
*********************/
public long getUser() {
return user;
}
public void setUser(long user) {
this.user = user;
}
public long getEvent() {
return event;
}
public void setEvent(long event) {
this.event = event;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}

View File

@ -1,14 +0,0 @@
package com.vpr.server;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import java.sql.Date;
import java.util.List;
// This will be AUTO IMPLEMENTED by Spring into a Bean called eventListRepository
// CRUD refers Create, Read, Update, Delete
public interface UserEventRepository extends CrudRepository<UserEvent, Integer> {
}

View File

@ -1,19 +0,0 @@
package com.vpr.server;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
// This will be AUTO IMPLEMENTED by Spring into a Bean called userRepository
// CRUD refers Create, Read, Update, Delete
public interface UserRepository extends CrudRepository<User, Integer> {
@Query(value = "SELECT u.id, u.name, u.forename " +
"FROM user u",
nativeQuery = true)
Object[] findAllUsernames();
com.vpr.server.User findById(long id);
}

View File

@ -1,13 +0,0 @@
package com.vpr.server;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class ServerApplicationTests {
@Test
void contextLoads() {
}
}