Merge branch 'develop' into frontend/kathy

This commit is contained in:
Katharina Will 2019-05-06 16:08:23 +02:00
commit 4bd210ab73
42 changed files with 2121 additions and 499 deletions

View File

@ -40,7 +40,7 @@ dependencies {
compile 'org.springframework.boot:spring-boot-starter-tomcat'
//compile 'org.springframework.boot:spring-boot-starter-security'
//compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.boot:spring-boot-starter-actuator'
//compile 'org.springframework.boot:spring-boot-starter-aop'
//ompile group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version: '1.2.0.RELEASE'
@ -54,6 +54,10 @@ dependencies {
runtime 'io.jsonwebtoken:jjwt-impl:0.10.5',
'io.jsonwebtoken:jjwt-jackson:0.10.5'
compile "io.springfox:springfox-swagger2:2.9.2"
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.0.2'
}
node {

View File

@ -68,6 +68,10 @@ module.exports = function (ctx) {
'QEditor',
'QSelect',
'QField',
'QBtnDropdown',
'QPopupEdit',
'QSlideTransition',
'QToggle',
],
directives: [
@ -105,11 +109,14 @@ module.exports = function (ctx) {
},
env: ctx.dev
? { // Base URL for API-Calls: DEV
API: JSON.stringify('http://localhost:8080')
//API: JSON.stringify('http://localhost:8080')
API: JSON.stringify('https://seserver.se.hs-heilbronn.de:8443/buga19geocaching'),
USER_API: JSON.stringify('https://seserver.se.hs-heilbronn.de:8443/buga19usermanagement')
}
: { // Base URL for API-Calls: PRODUCTION (build)
//API: JSON.stringify('http://seserver.se.hs-heilbronn.de:8090/buga19geocaching')
API: JSON.stringify('http://localhost:8080')
API: JSON.stringify('https://seserver.se.hs-heilbronn.de:8443/buga19geocaching'),
USER_API: JSON.stringify('https://seserver.se.hs-heilbronn.de:8443/buga19usermanagement')
//API: JSON.stringify('http://localhost:8080')
}
},

View File

@ -2,7 +2,7 @@ import axios from "axios";
const axiosInstance = axios.create({
baseURL: process.env.API,
timeout: 3000
timeout: 6000
});
console.log("process.env.DEV: "+process.env.DEV);
console.log("process.env.API: "+process.env.API);

View File

@ -44,6 +44,7 @@
</q-item-section>
</q-item>
<q-item
v-if="this.$store.state.auth.isAuthenticated"
clickable
class="text-primary"
v-ripple
@ -68,7 +69,21 @@
<q-icon name="map"/>
</q-item-section>
<q-item-section>
<q-item-label>Caches</q-item-label>
<q-item-label>Alle Caches</q-item-label>
</q-item-section>
</q-item>
<q-item
clickable
class="text-primary"
v-ripple
tag="a"
to="/mycaches"
>
<q-item-section avatar>
<q-icon name="map"/>
</q-item-section>
<q-item-section>
<q-item-label>Meine Caches</q-item-label>
</q-item-section>
</q-item>
<q-item
@ -86,6 +101,7 @@
</q-item-section>
</q-item>
<q-item
v-if="this.$store.state.auth.isAuthenticated"
clickable
class="text-primary"
v-ripple
@ -99,6 +115,21 @@
<q-item-label>Profil</q-item-label>
</q-item-section>
</q-item>
<q-item
v-if="!this.$store.state.auth.isAuthenticated"
clickable
class="text-primary"
v-ripple
tag="a"
to="/Register"
>
<q-item-section avatar>
<q-icon name="assignment"/>
</q-item-section>
<q-item-section>
<q-item-label>Registrieren</q-item-label>
</q-item-section>
</q-item>
<q-item
clickable
class="text-primary"
@ -110,7 +141,7 @@
<q-icon name="logout"/>
</q-item-section>
<q-item-section>
<q-item-label>Login</q-item-label>
<q-item-label>{{ loginText }}</q-item-label>
</q-item-section>
</q-item>
</q-list>
@ -158,37 +189,41 @@
};
},
computed: {
loginText() {
let text = this.$store.state.auth.isAuthenticated ? "Logout" : "Login";
return text;
},
dialogShow: {
get() {
console.log("get dialogShow: "+this.$store.state.dialog.dialog.show)
// console.log("get dialogShow: "+this.$store.state.dialog.dialog.show)
return this.$store.state.dialog.dialog.show;
},
set(val) {
console.log("set dialogShow: "+val)
// console.log("set dialogShow: "+val)
this.$store.state.dialog.dialog.show = val;
}
},
dialogMessage: {
get() {
console.log("get dialogMessage: "+this.$store.state.dialog.dialog.message)
// console.log("get dialogMessage: "+this.$store.state.dialog.dialog.message)
return this.$store.state.dialog.dialog.message;
},
},
dialogTitle: {
get() {
console.log("get dialogTitle: "+this.$store.state.dialog.dialog.title)
// console.log("get dialogTitle: "+this.$store.state.dialog.dialog.title)
return this.$store.state.dialog.dialog.title;
},
},
dialogColorBg: {
get() {
console.log("get dialogColorBg: " + this.$store.state.dialog.dialog.colorBackground)
// console.log("get dialogColorBg: " + this.$store.state.dialog.dialog.colorBackground)
return this.$store.state.dialog.dialog.colorBackground;
},
},
dialogColorBtn: {
get() {
console.log("get dialogColorBtn: "+this.$store.state.dialog.dialog.colorButton)
// console.log("get dialogColorBtn: "+this.$store.state.dialog.dialog.colorButton)
return this.$store.state.dialog.dialog.colorButton;
},
}

View File

@ -5,9 +5,8 @@
<form>
<div class="q-pa-md q-gutter-y-md">
<p class="text-h5">{{ isNewCache ? "Neuen Cache erstellen" : "Cache bearbeiten"}}</p>
<q-input class="col" dense stack-label filled v-model="tempCache.name" label="Name" @change="cacheToStore"/>
<q-input class="col" dense stack-label filled v-model="tempCache.rankingPoints" label="Punktewert"
@change="cacheToStore"/>
<q-input class="col" dense stack-label filled v-model="computedCache.name" label="Name"/>
<q-input class="col" dense stack-label filled v-model="computedCache.rankingPoints" label="Punktewert"/>
<p class="text-h6">Beschreibung</p>
<q-editor
:toolbar="[
@ -16,10 +15,9 @@
['hr', 'link'],
['fullscreen'],
]"
v-model="tempCache.description"
v-model="computedCache.description"
min-height="5rem"
max-height="50vh"
@change="cacheToStore"
/>
<p class="text-h6">Belohnung</p>
<q-editor
@ -29,15 +27,14 @@
['hr', 'link'],
['fullscreen'],
]"
v-model="tempCache.reward"
v-model="computedCache.reward.rewardDescription"
min-height="5rem"
max-height="50vh"
@change="cacheToStore"
/>
<p class="text-h6">Stationen</p>
<q-list bordered separator class="rounded-borders">
<q-item v-for="(station, index) in cache.stationen" :key="index">
<q-item v-for="(station, index) in computedCache.stationen" :key="index">
<q-item-section avatar>
<q-avatar color="primary" text-color="white">
{{ index + 1 }}
@ -73,19 +70,19 @@
<q-item>
<q-item-section avatar>
<q-avatar color="primary" text-color="white">
{{ tempCache.stationen.length + 1 }}
{{ computedCache.stationen.length + 1 }}
</q-avatar>
</q-item-section>
<q-item-section top>
<q-item-label lines="1">
<span class="text-grey-8">ID: {{ endStation.id ? endStation.id : "keine" }}</span>
<span class="text-grey-8">ID: {{ computedEndstation.id ? computedEndstation.id : "keine" }}</span>
</q-item-label>
<q-item-label lines="1" class="q-mt-xs text-body2">
<span class="cursor-pointer">Endstation</span>
</q-item-label>
<q-item-label caption lines="1">
Koordinaten: {{ endStation.lattitude }}, {{ endStation.longitude }}
Koordinaten: {{ computedEndstation.lattitude }}, {{ computedEndstation.longitude }}
</q-item-label>
</q-item-section>
@ -114,6 +111,8 @@
name: "Cache",
data() {
return {
// stations: [],
// endStation: {},
//endStation: {},
scrolldown: false,
isNewCache: this.$route.params.id === undefined,
@ -128,7 +127,7 @@
created: function () {
console.log("isNewCache: " + this.isNewCache);
console.log("fetch Caches from Store");
this.tempCache = JSON.parse(JSON.stringify(this.cache));
//this.tempCache = JSON.parse(JSON.stringify(this.cache));
},
beforeMount: function () {
},
@ -159,20 +158,32 @@
}
},
cacheToStore() {
// push tempCache to Store
console.log("set Cache");
this.$store.commit('cacheCollector/SET_CACHE', JSON.parse(JSON.stringify(this.tempCache)));
// this.SET_CACHE(JSON.parse(JSON.stringify(this.tempCache)));
},
// getStations() {
// console.log("get Stations");
// let stations = this.computedStations.get();
// this.stations = stations.filter(station => station.description !== "Endstation");
// console.log(this.stations);
// this.endStation = stations.filter(station => station.description === "Endstation");
// console.log(this.endStation);
// },
// setStations() {
// let stations = this.stations;
// stations.push(this.endStation);
// this.computedStations.set(stations);
// },
// cacheToStore() {
// // push tempCache to Store
// console.log("set Cache");
// this.$store.commit('cacheCollector/SET_CACHE', JSON.parse(JSON.stringify(this.tempCache)));
// // this.SET_CACHE(JSON.parse(JSON.stringify(this.tempCache)));
// },
addStation() {
this.$router.push({path: '/station'});
//this.swapComponent(station);
// create Station and add it to array tempCache.stationen
},
editStation(index) {
console.log("editStation(" + index + ")");
const station = this.cache.stationen[index];
console.log(this.$store.getters['cacheCollector/GET_STATIONS']);
const station = this.$store.getters['cacheCollector/GET_STATIONS'][index];
console.log(station);
if (station.hasOwnProperty('id')) {
//this.$router.push({ path: '/station/'+station.id});
@ -189,9 +200,9 @@
saveCache() {
// commit to store, send to api, if success -> reset store
if (this.isNewCache) {
console.log(this.cache);
let cache = this.cache;
cache.stationen.push(this.endStation);
let cache = JSON.parse(JSON.stringify(this.computedCache));
console.log(cache);
cache.stationen.push(this.computedEndstation);
this.$axios.post('/api/createCache', cache)
.then((response) => {
@ -227,18 +238,46 @@
},
computed: {
...mapGetters({
cache: 'cacheCollector/GET_CACHE',
endStation: 'cacheCollector/GET_ENDSTATION'
//cache: 'cacheCollector/GET_CACHE',
//endStation: 'cacheCollector/GET_ENDSTATION'
}),
// computedCache: {
// computedStations: {
// set(value) {
// console.log("set cache")
// console.log("set stations");
// this.computedCache.set(value);
// },
// get() {
// console.log("get cache");
// return this.$store.getters.cacheCollector.GET_CACHE
// console.log("get stations");
// let stations = this.computedCache.stationen;
// return stations.filter(station => station.description !== "Endstation");
// }
// }
// },
computedCache: {
set(value) {
console.log("set cache");
this.$store.commit('cacheCollector/SET_CACHE', value);
},
get() {
console.log("get cache");
return this.$store.getters['cacheCollector/GET_CACHE'];
}
},
computedStations: {
set(value) {
this.$store.commit('cacheCollector/SET_STATIONS', value);
},
get() {
return this.$store.getters['cacheCollector/GET_STATIONS'];
}
},
computedEndstation: {
set(value) {
this.$store.commit('cacheCollector/SET_ENDSTATION', value);
},
get() {
return this.$store.getters['cacheCollector/GET_ENDSTATION'];
}
},
}
}
</script>

View File

@ -5,12 +5,16 @@
<p class="text-h5">{{ end1 + rankingPoints + end2 }}</p>
<div class="column q-gutter-y-md">
<q-btn unelevated v-if="IsLoggedIn" color="primary" label="Zur Rangliste" to="/ranking/"/>
<q-btn unelevated v-if="isLoggedIn" color="primary" label="Zur Rangliste" to="/ranking/"/>
<q-btn unelevated v-if="isLoggedIn" color="primary" label="Zur Belohnung" @click="reward = true" />
<q-dialog v-model="reward">
<q-card>
<q-card-section>
<div>Jetzt ist eine gute Zeit, etwas Neues zu beginnen.</div>
<div class="text-h6">Deine Belohnung: </div>
</q-card-section>
<q-card-section>
<div>{{ cache.reward.rewardDescription }}</div>
</q-card-section>
</q-card>
</q-dialog>
@ -27,6 +31,9 @@
reward: false,
cacheID: "",
cacheName: "",
cache: {
reward: "",
},
rankingPoints: "",
end1: "Gut gemacht, Du hast alle Stationen dieses Cache gefunden. Dir wurden ",
end2: " Punkte gutgeschrieben." //TODO Punkte wirklich gutschreiben, ggf. Cache auf erledigt setzen
@ -45,10 +52,10 @@
this.$axios.get('/api/allCaches')
.then((response) => {
console.log("/api/allCaches");
console.log(JSON.stringify(this.data));
console.log(this.data);
console.log(JSON.stringify(response.data));
console.log(response.data);
const cache = response.data.find(cache => cache.id === Number(this.$route.params.cache));
this.cache = cache;
this.cacheName = cache.name;
this.rankingPoints = cache.rankingPoints;
this.cacheID = this.$route.params.cache;

View File

@ -67,8 +67,6 @@
this.$axios.get('/api/allCaches')
.then((response) => {
console.log("/api/allCaches");
console.log(JSON.stringify(this.data));
console.log(this.data);
console.log(response.data);
const cache = response.data.find(cache => cache.id === Number(this.$route.params.cache));
this.cacheName = cache.name;
@ -97,7 +95,8 @@
params.cacheID = this.result.split('/')[0];
params.stationID = this.result.split('/')[1];
params.durchgefuehrterCacheID = this.cacheID;
console.log(params.cacheID + " und " + params.stationID);
console.log("CacheID: " + params.cacheID + " und StationID: " + params.stationID);
console.log(params.durchgefuehrterCacheID);
if (localStorage.getItem('userToken')) {
params.token = JSON.parse(localStorage.getItem('userToken')).token;
}
@ -126,8 +125,14 @@
this.$axios.get('/api/checkStation', {params})
.then((response) => {
console.log("resolve(true)");
console.log("cache access definition");
console.log(response.data.cacheAccesDefinition);
resolve(true);
this.$router.push({path: `/station/${params.cacheID}/${params.stationID}`});
if (Number(response.data.cacheAccesDefinition.id) === 0) {
this.$router.push({path: `/station/${params.cacheID}/${params.stationID}`});
} else if (Number(response.data.cacheAccesDefinition.id) === 1) {
this.$router.push({path: `/CacheEnd/${params.cacheID}`});
}
}).catch((error) => {
console.log("resolve(false)");
// Error

View File

@ -1,12 +1,12 @@
<template>
<div class="q-pa-md">
<form class="login" @submit.prevent="login">
<form class="login">
<div class="q-pa-md">
<div class="column q-gutter-lg" style="">
<div class="col">
<div class="">
<div class="" style="max-width: 440px">
<q-input outlined filled stack-label v-model="user.email" type="text" label="Benutzername"
<q-input outlined filled stack-label v-model="user.email" type="text" label="Email"
autocomplete="username"/>
</div>
</div>
@ -29,7 +29,7 @@
label="Login"
color="primary"
class="full-width"
type="submit"
@click="login"
unelevated
>
<template v-slot:loading>
@ -61,8 +61,8 @@
return {
loading: false,
user: {
email: "volkmann@geocaching.de",
password: "0123456789",
email: "",
password: "",
//token: "",
// evalAuthentication: false
},
@ -80,14 +80,14 @@
},
computed: {
userAuthenticated() {
console.log("login: userAuthenticated()")
// console.log(this.$store.getters['auth/IS_AUTHENTICATED']);
// return this.$store.getters['auth/IS_AUTHENTICATED']
console.log("login: userAuthenticated()");
console.log(this.$store.state.auth.isAuthenticated);
return this.$store.state.auth.isAuthenticated;
}
},
methods: {
login: function () {
console.log("login called");
this.loading = true;
const data = {
email: this.user.email,
@ -96,20 +96,22 @@
console.log("GET /api/login/ - json: " + JSON.stringify(data));
this.$axios.post('http://www.se.hs-heilbronn.de:8090/buga19usermanagement/account/login', data)
this.$axios.post(process.env.USER_API+'/account/login', data)
.then((response) => {
console.log("GET/POST /api/login/ - response: ");
console.log(response.data);
console.log("TOKEN");
console.log(response.data.token);
localStorage.setItem('userToken', JSON.stringify(response.data));
localStorage.setItem('userMail', JSON.stringify(data.email));
this.evalAuthentication();
this.$router.push({path: `/overview`})
})
.catch((error) => {
let message;
let header = "Fehler: ";
if (error.response) {
console.log("ERROR RESPONSE")
console.log("ERROR RESPONSE");
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
message = error.response.data.error;
@ -118,7 +120,7 @@
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
// http.ClientRequest in node.js
message = error.request;
message = "Anfrage fehlgeschlagen.";
} else {
// Something happened in setting up the request that triggered an Error
console.log('Error', error.message);
@ -128,6 +130,7 @@
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: message, title: header, });
}).finally(() => {
this.loading = false;
this.evalAuthentication();
})
},
evalAuthentication: function () {

View File

@ -0,0 +1,266 @@
<template>
<q-page class="column no-wrap">
<div class="bg-red col col-shrink" style="">
<q-tabs
v-model="tab"
class="bg-grey-2"
inline-label
align="justify"
active-bg-color="bg-grey-1"
active-color="cyan-14"
indicator-color="cyan-14"
switch-indicator
>
<q-tab name="startedCaches" label="Angefangene Caches" icon="playlist_play"/>
<q-tab name="finishedCaches" label="Beendete Caches" icon="playlist_add_check"/>
</q-tabs>
<q-separator color="grey-4"/>
</div>
<div class="col flex column">
<q-tab-panels v-model="tab" animated swipeable class="col">
<q-tab-panel name="startedCaches" class=" fit">
<q-list>
<q-card
class="q-mb-md"
v-for="startedCache in startedCaches.filter(cache => cache.cacheAccesDefinition.id === 0)"
:key="startedCache.id"
>
<q-expansion-item
class=""
expand-icon-toggle
expand-separator
icon="location_on"
:label="startedCache.cache.name"
:caption=" startedCache.cache.description"
>
<q-item>
<q-item-section top avatar class="self-center">
</q-item-section>
<q-item-section>
<q-item-label caption>{{'Nächste Aufgabe: ' + startedCache.aktuelleStation.description }}
</q-item-label>
<q-item-label caption>{{'Ranglistenpunkte für diesen Cache: ' + startedCache.cache.rankingPoints}}
</q-item-label>
</q-item-section>
<q-item-section side top class="self-center">
</q-item-section>
</q-item>
<q-item class="q-pr-sm reverse q-gutter-x-sm">
<q-btn @click="continueCache(startedCache.cache.id)" unelevated color="positive" stack icon="arrow_forward"
label="Fortfahren" size="sm"/>
</q-item>
</q-expansion-item>
</q-card>
</q-list>
</q-tab-panel>
<q-tab-panel name="finishedCaches" class="fit">
<q-list>
<q-card class="q-mb-md" v-for="finishedCache in startedCaches.filter(cache => cache.cacheAccesDefinition.id === 1)" :key="finishedCache.id">
<q-expansion-item
class=""
expand-icon-toggle
expand-separator
icon="location_on"
:label="finishedCache.cache.name"
:caption=" finishedCache.cache.description"
>
<q-item>
<q-item-section top avatar class="self-center">
<!--<q-icon rounded color="cyan-14" name="location_on" size="3rem"/>-->
</q-item-section>
<q-item-section>
<q-item-label caption>{{'Erhaltene Punkte für diesen Cache: ' + finishedCache.cache.rankingPoints
}}
</q-item-label>
</q-item-section>
<q-item-section side top class="self-center">
</q-item-section>
</q-item>
<q-item class="q-pr-sm reverse q-gutter-x-sm">
<q-btn @click="goToReward(finishedCache.cache.id)" unelevated color="primary" stack icon="arrow_forward"
label="Belohnung ansehen" size="sm"/>
</q-item>
</q-expansion-item>
</q-card>
</q-list>
</q-tab-panel>
</q-tab-panels>
</div>
</q-page>
</template>
<style>
</style>
<script>
//import {dom} from 'quasar'
//const {height, width} = dom
export default {
data() {
return {
tab: 'startedCaches',
startedCaches: [],
inviteMail: "",
currentTeamStatus: "Dienstag 15:00 Treffen zum Blumencache",
teamStatus: "",
userName: null,
email: null,
}
},
mounted: function () {
},
computed: {
hasAdminState() {
return this.$store.getters['auth/GET_ADMINSTATE'];
},
},
created: function () {
this.fetchUserCaches();
this.$store.commit('auth/SET_AUTHENTICATED');
this.$store.commit('auth/SET_USER');
},
methods: {
fetchUserCaches: function () {
let token;
if (localStorage.getItem('userToken')) {
token = JSON.parse(localStorage.getItem('userToken')).token;
} else {
return;
}
this.$axios.get('/api/getMyCaches', {params: {token}})
.then((response) => {
console.log(response.data)
this.startedCaches = response.data;
}).catch((error) => {
// Error
let msg;
let title;
if (error.response) {
// The request was made and the server responded with a status code
title = "Problem with response!";
msg = error.response;
} else if (error.request) {
// The request was made but no response was received
title = "Problem with request!";
msg = "Error occured due to wrong server request!"
console.log(error.request);
} else {
// Something happened in setting up the request that triggered an Error
title = "Error";
msg = error.message;
console.log('Error', error.message);
}
console.log(error.config);
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: msg, title: title,});
})
},
continueCache(cacheID) {
console.log("cacheID");
console.log(cacheID);
let currentStationID;
if (localStorage.getItem('userToken')) {
let params = {cacheID: cacheID};
params.token = JSON.parse(localStorage.getItem('userToken')).token;
this.$axios.get('/api/getCurrentStation', {params})
.then((response) => {
console.log(response.data);
currentStationID = response.data.aktuelleStation.id;
this.$router.push({path: `/station/${cacheID}/${currentStationID}`});
})
.catch((error) => {
});
}
},
goToReward(cacheID) {
console.log("cacheID");
console.log(cacheID);
let currentStationID;
if (localStorage.getItem('userToken')) {
let params = {cacheID: cacheID};
params.token = JSON.parse(localStorage.getItem('userToken')).token;
this.$axios.get('/api/getCurrentStation', {params})
.then((response) => {
console.log(response.data);
currentStationID = response.data.aktuelleStation.id;
this.$router.push({path: `/CacheEnd/${params.cacheID}`});
})
.catch((error) => {
});
}
},
getPersonalRanking() {
const name = JSON.parse(localStorage.getItem('userToken')).name;
console.log(JSON.parse(localStorage.getItem('userToken')).name);
this.$axios.get('/api/hello', {params: {name}})
.then((response) => {
this.userRanking = response.data;
console.log(response.data);
}).catch((error) => {
// Error
let msg;
let title;
if (error.response) {
// The request was made and the server responded with a status code
title = "Problem with response!";
msg = error.response;
} else if (error.request) {
// The request was made but no response was received
title = "Problem with request!";
msg = "Error occured due to wrong server request!"
console.log(error.request);
} else {
// Something happened in setting up the request that triggered an Error
title = "Error";
msg = error.message;
console.log('Error', error.message);
}
console.log(error.config);
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: msg, title: title,});
})
},
getTeamData() {
const userName = {name: JSON.parse(localStorage.getItem('userToken')).name};
this.$axios.get('/api/getTeam', {params: userName})
.then(response => {
console.log("getTeam: " + response);
}).catch((error) => {
// Error
let msg;
let title;
if (error.response) {
// The request was made and the server responded with a status code
title = "Problem with response!";
msg = error.response;
} else if (error.request) {
// The request was made but no response was received
title = "Problem with request!";
msg = "Error occured due to wrong server request!"
console.log(error.request);
} else {
// Something happened in setting up the request that triggered an Error
title = "Error";
msg = error.message;
console.log('Error', error.message);
}
console.log(error.config);
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: msg, title: title,});
})
},
dropDownSelectItem(item) {
if (item === 'team') {
this.dropDownSelectedItem = this.teamName;
} else {
this.dropDownSelectedItem = item;
}
},
}
}
</script>

View File

@ -26,7 +26,6 @@
<q-card class="q-mb-md" v-for="cache in caches" :key="cache.id">
<q-expansion-item
class=""
expand-icon-toggle
expand-separator
icon="location_on"
:label="cache.name"
@ -37,7 +36,7 @@
<!--<q-icon rounded color="cyan-14" name="location_on" size="3rem"/>-->
</q-item-section>
<q-item-section>
<q-item-label caption>{{ cache.description }}</q-item-label>
<q-item-label caption v-html="cache.description"></q-item-label>
</q-item-section>
<q-item-section side top class="self-center">
@ -118,26 +117,26 @@
console.log("Caches: " + this.caches);
this.caches = response.data;
}).catch((error) => {
// Error
let msg;
let title;
let message;
let header = "Fehler: ";
if (error.response) {
console.log("ERROR RESPONSE");
// The request was made and the server responded with a status code
title = "Problem with response!";
msg = error.response;
// that falls out of the range of 2xx
message = error.response.data.error;
header += error.response.status;
} else if (error.request) {
// The request was made but no response was received
title = "Problem with request!";
msg = "Error occured due to wrong server request!"
console.log(error.request);
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
// http.ClientRequest in node.js
message = "Anfrage fehlgeschlagen.";
} else {
// Something happened in setting up the request that triggered an Error
title = "Error";
msg = error.message;
console.log('Error', error.message);
message = error.message;
}
console.log(error.config);
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: msg, title: title, });
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: message, title: header, });
})
},
addCache() {
@ -146,71 +145,45 @@
editCache() {
},
deleteCache(id) {
console.log('delete cache: ' + id)
this.$axios.delete('/api/deleteCache', {params: {cacheID: id}})
console.log('delete cache: ' + id);
this.$axios.get('/api/deleteCache', {params: {cacheID: id}})
.then((response) => {
this.fetchAllCaches()
}).catch((error) => {
// Error
let msg;
let title;
let message;
let header = "Fehler: ";
if (error.response) {
console.log("ERROR RESPONSE");
// The request was made and the server responded with a status code
title = "Problem with response!";
msg = error.response;
// that falls out of the range of 2xx
message = error.response.data.error;
header += error.response.status;
} else if (error.request) {
// The request was made but no response was received
title = "Problem with request!";
msg = "Error occured due to wrong server request!"
console.log(error.request);
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
// http.ClientRequest in node.js
message = "Anfrage fehlgeschlagen.";
} else {
// Something happened in setting up the request that triggered an Error
title = "Error";
msg = error.message;
console.log('Error', error.message);
message = error.message;
}
console.log(error.config);
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: msg, title: title, });
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: message, title: header, });
})
},
startCache(cacheID) {
const userToken = JSON.parse(localStorage.getItem('userToken')).token;
let params = {cacheID: cacheID};
if (userToken != null) {
params.token = userToken;
}
console.log(params);
this.$axios.get('/api/startCache', {params})
.then((response) => {
console.log(response.data);
// TODO wenn cache angefangen, dann suche die letzte gefundene Station
let stationID = this.caches.find(x => x.id === cacheID).stationen[0].id;
console.log(stationID);
//this.$router.push({path: `/station/${stationID}`})
this.$router.push({path: `/CacheStart/${cacheID}`})
}).catch((error) => {
// Error
let msg;
let title;
if (error.response) {
// The request was made and the server responded with a status code
title = "Problem with response!";
msg = error.response;
} else if (error.request) {
// The request was made but no response was received
title = "Problem with request!";
msg = "Error occured due to wrong server request!"
console.log(error.request);
} else {
// Something happened in setting up the request that triggered an Error
title = "Error";
msg = error.message;
console.log('Error', error.message);
}
console.log(error.config);
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: msg, title: title, });
})
console.log("startCache()");
// const userToken = JSON.parse(localStorage.getItem('userToken')).token;
// let params = {cacheID: cacheID};
// if (userToken != null) {
// params.token = userToken;
// }
// console.log(params);
this.$store.state.currentCache.cache = this.caches.find(cache => cache.id === Number(cacheID));
console.log(this.$store.state.currentCache.cache);
this.$store.state.currentCache.currentCacheID = Number(cacheID);
this.$router.push({path: `/CacheStart/${cacheID}`})
}
}
}

View File

@ -1,20 +1,19 @@
<template>
<q-page class="column no-wrap">
<div class="bg-red col col-shrink" style="">
<q-tabs
v-model="tab"
class="bg-grey-2"
inline-label
align="justify"
active-bg-color="bg-grey-1"
active-color="cyan-14"
indicator-color="cyan-14"
switch-indicator
>
<q-tab name="profile" label="Profil" icon="perm_identity"/>
<q-tab name="startedCaches" label="Angefangene Caches" icon="playlist_play"/>
<q-tab name="finishedCaches" label="Beendete Caches" icon="playlist_add_check"/>
</q-tabs>
<q-tabs
v-model="tab"
class="bg-grey-2"
inline-label
align="justify"
active-bg-color="bg-grey-1"
active-color="cyan-14"
indicator-color="cyan-14"
switch-indicator
>
<q-tab name="profile" label="Profil" icon="perm_identity"/>
<q-tab name="teams" label="Team" icon="group"/>
</q-tabs>
<q-separator color="grey-4"/>
</div>
@ -22,69 +21,76 @@
<q-tab-panels v-model="tab" animated swipeable class="col">
<q-tab-panel name="profile" class=" fit">
<p class="text-h5"> Persönliche Daten </p>
<q-table
:data="data"
:columns="columns"
row-key="name"
hide-header
hide-bottom
table-class="my-custom"
/>
</q-tab-panel>
<q-tab-panel name="teams">
<div class="q-pa-md" align="center">
<q-btn-dropdown color="primary" :label="dropDownSelectedItem" size="20px">
<q-list>
<q-item clickable v-close-popup @click="dropDownSelectItem('team')">
<q-item-section>
<q-item-label v-html="teamName"></q-item-label>
</q-item-section>
</q-item>
<q-tab-panel name="startedCaches" class=" fit">
<q-list>
<q-card class="q-mb-md" v-for="startedCache in startedCaches" :key="startedCache.id">
<q-expansion-item
class=""
v-if="startedCache.cacheAccesDefinition.description === 'angefangen'"
expand-icon-toggle
expand-separator
icon="location_on"
:label="startedCache.cache.name"
:caption=" startedCache.cache.description"
>
<q-item>
<q-item-section top avatar class="self-center">
<!--<q-icon rounded color="cyan-14" name="location_on" size="3rem"/>-->
<q-item clickable v-close-popup @click="dropDownSelectItem('Offene Teameinladungen')">
<q-item-section avatar>
<q-avatar icon="group_add" color="primary" text-color="white"/>
</q-item-section>
<q-item-section>
<q-item-label caption>{{'Nächste Aufgabe: ' + startedCache.aktuelleStation.description }}
</q-item-label>
<q-item-label caption>{{'Ranglistenpunkte für diesen Cache: ' + startedCache.cache.rankingPoints}}
</q-item-label>
</q-item-section>
<q-item-section side top class="self-center">
<q-item-label>Offene Teameinladungen</q-item-label>
</q-item-section>
</q-item>
<q-item class="q-pr-sm reverse q-gutter-x-sm">
<q-btn @click="continueCache(startedCache.id)" unelevated color="positive" stack icon="arrow_forward"
label="Fortfahren" size="sm"/>
</q-item>
</q-expansion-item>
</q-card>
</q-list>
</q-tab-panel>
<q-tab-panel name="finishedCaches" class="fit">
<q-list>
<q-card class="q-mb-md" v-for="startedCache in startedCaches" :key="startedCache.id">
<q-expansion-item
class=""
v-if="startedCache.cacheAccesDefinition.description === 'abgeschlossen'"
expand-icon-toggle
expand-separator
icon="location_on"
:label="startedCache.cache.name"
:caption=" startedCache.cache.description"
>
<q-item>
<q-item-section top avatar class="self-center">
<!--<q-icon rounded color="cyan-14" name="location_on" size="3rem"/>-->
<q-item clickable v-close-popup @click="dropDownSelectItem('Neues Team erstellen')">
<q-item-section avatar>
<q-avatar icon="add" color="primary" text-color="white"/>
</q-item-section>
<q-item-section>
<q-item-label caption>{{'Erhaltene Punkte für diesen Cache: ' + startedCache.cache.rankingPoints }}</q-item-label>
</q-item-section>
<q-item-section side top class="self-center">
<q-item-label>Neues Team erstellen</q-item-label>
</q-item-section>
</q-item>
</q-expansion-item>
</q-card>
</q-list>
</q-list>
</q-btn-dropdown>
</div>
<p class="text-h5"> Teammitglieder </p>
<q-table
:data="teamData"
:columns="teamColumns"
row-key="name"
table-class="my-custom"
hide-bottom
:pagination.sync="pagination"
/>
<br/>
<p class="text-h5"> Einladungen </p>
<q-input outlined filled stack-label v-model="inviteMail"
type="text" label="Email des Nutzers"
:rules="[val=>validateEmail(val)||'Bitte Email verwenden']"/>
<div align="center">
<q-btn label="Einladung versenden"
color="primary"
type="submit"/>
</div>
<br/>
<p class="text-h5"> Teamstatus </p>
<p>{{currentTeamStatus}}</p>
<q-input outlined filled stack-label v-model="teamStatus"
type="text" label="Neuer Teamstatus"
:rules="[val=>val.length<=160||'Status zu lang!']"/>
<div align="center">
<q-btn label="Teamstatus aktualisieren"
color="primary"
type="submit"/>
</div>
</q-tab-panel>
</q-tab-panels>
@ -94,10 +100,17 @@
</template>
<style>
/*
.my-list-card-item
padding-left: 8px
*/
.my-custom th {
color: #027BE3 !important;
}
.my-custom tr {
color: #027BE3 !important;
}
.my-custom td {
color: #027BE3 !important;
}
</style>
<script>
//import {dom} from 'quasar'
@ -107,6 +120,103 @@
return {
tab: 'profile',
startedCaches: [],
inviteMail: "",
currentTeamStatus: "Dienstag 15:00 Treffen zum Blumencache",
teamStatus: "",
userName: null,
email: null,
userRanking: null,
teamName: null,
teamRanking: null,
dropDownSelectedItem: null,
columns: [
{
name: 'desc',
required: true,
align: 'left',
field: row => row.name,
format: val => `${val}`,
},
{
name: 'userData',
required: true,
align: 'left',
field: 'userData',
}
],
data: [
{
name: 'Mein Nutzername',
userData: this.userName,
},
{
name: 'Meine Email',
userData: this.email,
},
{
name: 'Meine Ranglistenposition',
userData: this.userRanking,
},
{
name: 'Mein Team',
userData: this.teamName,
},
{
name: 'Teamranglistenposition',
userData: this.teamRanking,
},
],
teamColumns: [
{
name: 'desc',
label: 'Benutzername',
required: true,
align: 'left',
field: row => row.name,
format: val => `${val}`,
},
{
name: 'ranking',
label: 'Solo-Ranglistenpunkte',
required: true,
align: 'left',
field: 'ranking',
sortable: true,
}
],
teamData: [
{
name: 'BuGaCacher2019',
ranking: 10,
},
{
name: 'Max',
ranking: 5,
},
{
name: 'Timo',
ranking: 4,
},
{
name: 'Katharina',
ranking: 3,
},
{
name: 'Michael',
ranking: 2,
},
{
name: 'Robin',
ranking: 1,
},
],
pagination: {
sortBy: 'name',
descending: false,
page: 1,
rowsPerPage: 10
// rowsNumber: xx if getting data from a server
},
}
},
mounted: function () {
@ -114,19 +224,35 @@
computed: {
hasAdminState() {
return this.$store.getters['auth/GET_ADMINSTATE'];
}
},
},
created: function() {
this.fetchUserCaches();
created: function () {
this.$store.commit('auth/SET_AUTHENTICATED');
this.$store.commit('auth/SET_USER');
this.userName = JSON.parse(localStorage.getItem('userToken')).name;
this.data[0].userData = this.userName;
this.email = JSON.parse(localStorage.getItem('userMail'));
this.data[1].userData = this.email;
this.userRanking = "1234";
this.data[2].userData = this.userRanking;
this.teamName = "BuGa19Community";
this.data[3].userData = this.teamName;
this.dropDownSelectedItem = this.teamName;
this.teamRanking = "2019";
this.data[4].userData = this.teamRanking;
},
methods: {
fetchUserCaches: function() {
const token = JSON.parse(localStorage.getItem('userToken')).token;
this.$axios.get('/api/getMyCaches', { params: {token}} )
validateEmail(email) {
let re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
},
getPersonalRanking() {
const name = JSON.parse(localStorage.getItem('userToken')).name;
console.log(JSON.parse(localStorage.getItem('userToken')).name);
this.$axios.get('/api/hello', {params: {name}})
.then((response) => {
this.startedCaches = response.data;
this.userRanking = response.data;
console.log(response.data);
}).catch((error) => {
// Error
let msg;
@ -147,11 +273,46 @@
console.log('Error', error.message);
}
console.log(error.config);
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: msg, title: title, });
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: msg, title: title,});
})
},
continueCache(cacheID) {
}
getTeamData() {
const userName = {name: JSON.parse(localStorage.getItem('userToken')).name};
this.$axios.get('/api/getTeam', {params: userName})
.then(response => {
console.log("getTeam: " + response);
}).catch((error) => {
// Error
let msg;
let title;
if (error.response) {
// The request was made and the server responded with a status code
title = "Problem with response!";
msg = error.response;
} else if (error.request) {
// The request was made but no response was received
title = "Problem with request!";
msg = "Error occured due to wrong server request!"
console.log(error.request);
} else {
// Something happened in setting up the request that triggered an Error
title = "Error";
msg = error.message;
console.log('Error', error.message);
}
console.log(error.config);
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: msg, title: title,});
})
},
dropDownSelectItem(item) {
if (item === 'team') {
this.dropDownSelectedItem = this.teamName;
} else {
this.dropDownSelectedItem = item;
}
},
}
}
</script>

View File

@ -0,0 +1,201 @@
<template>
<div class="q-pa-md">
<form class="register">
<div class="q-pa-md">
<div class="column q-gutter-lg" style="">
<div class="col">
<div class="">
<div class="" style="max-width: 440px">
<q-input outlined filled stack-label v-model="user.name" type="text"
label="Nutzername eingeben" :rules="[val=>val.length>=2||'Name muss mindestens 2 Zeichen lang sein!']"/>
</div>
</div>
</div>
<div class="col">
<div class="">
<div class="" style="max-width: 440px">
<q-input outlined filled stack-label v-model="user.email" type="text" label="Email eingeben" :rules="[val=>validateEmail(val)||'Email muss valide sein']"/>
</div>
</div>
</div>
<div class="col">
<div class="">
<div class="" style="max-width: 440px">
<q-input outlined filled stack-label v-model="user.checkemail" type="text"
label="Email erneut eingeben" placeholer="Email" :rules="[val=>val===user.email||'Email stimmt nicht überein']"/>
</div>
</div>
</div>
<div class="col">
<div class="">
<div class="" style="max-width: 440px">
<q-input outlined filled stack-label v-model="user.password" type="password"
label="Passwort eingeben" :rules="[val=>val.length>=8||'Passwort muss mindestens 8 Zeichen lang sein!']"/>
</div>
</div>
</div>
<div class="col">
<div class="">
<div class="" style="max-width: 440px">
<q-input outlined filled stack-label v-model="user.checkpassword" type="password"
label="Passwort erneut eingeben" :rules="[val=>val===user.password||'Passwort stimmt nicht überein']"/>
</div>
</div>
</div>
<div class="col">
<div class="">
<div class="" style="max-width: 440px">
<q-btn
:disabled="!validationSuccesful"
label="Registrieren"
color="primary"
class="full-width"
@click="register()"
unelevated
/>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
</template>
<script>
export default {
data() {
return{
user: {
name:"",
email:"",
checkemail:"",
password: "",
checkpassword: "",
},
}
},
computed: {
validationSuccesful(){
if(this.user.name.length>=2
&&this.validateEmail(this.user.email)
&&this.user.email===this.user.checkemail
&&this.user.password.length>=8
&&this.user.password===this.user.checkpassword){
return true;
}
return false;
}
},
created() {
this.login();
},
methods: {
validateEmail(email) {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(String(email).toLowerCase());
},
register: function () {
if(this.user.email===this.user.checkemail&&this.user.password===this.user.checkpassword){
const data = {
name: this.user.name,
password: this.user.password,
email: this.user.email,
roles: [
{
role: "CACHER",
domain: "geocaching.de"
}
]
};
console.log("POST /api/register/ - json: " + JSON.stringify(data));
const token = JSON.parse(localStorage.getItem('registerToken')).token;
this.$axios.post(process.env.USER_API+'/account/register', data,{
headers: {
'Authorization': 'Bearer ' + token,
}
})
.then((response) => {
console.log(response.data);
if(response.status === 201){
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: "Deine Registrierung war erfolgreich!", title: "Registrierungsprozess", color: "blue"});
}
})
.catch((error) => {
let message;
let header = "Fehler: ";
if (error.response) {
console.log("ERROR RESPONSE")
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
message = error.response.data.error;
header += error.response.status;
} else if (error.request) {
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
// http.ClientRequest in node.js
message = error.request;
} else {
// Something happened in setting up the request that triggered an Error
console.log('Error', error.message);
message = error.message;
}
console.log(error.config);
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: message, title: header,});
})
} else {
if(this.user.email!=this.user.checkemail) {
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {
message: "Email stimmt nicht überein",
title: "Fehler",
});
} else if (this.user.password!=this.user.checkpassword){
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {
message: "Passwort stimmt nicht überein",
title: "Fehler",
});
}
}
},
login() {
const logindata = {
email: "register@bugageocaching.de",
password: "reguser2019"
};
console.log("GET /api/login/ - json: " + JSON.stringify(logindata));
this.$axios.post(process.env.USER_API+'/account/login', logindata)
.then((response) => {
localStorage.setItem('registerToken', JSON.stringify(response.data));
})
.catch((error) => {
let message;
let header = "Fehler: ";
if (error.response) {
console.log("ERROR RESPONSE")
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
message = error.response.data.error;
header += error.response.status;
} else if (error.request) {
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
// http.ClientRequest in node.js
message = error.request;
} else {
// Something happened in setting up the request that triggered an Error
console.log('Error', error.message);
message = error.message;
}
console.log(error.config);
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: message, title: header, });
})
},
},
};
</script>

View File

@ -49,7 +49,7 @@
description: "Rätsel, Aufgabe und Informationen zur Station.",
latlang: "",
station: {
description: "Beschreibung",
description: "Rätsel, Aufgabe und Informationen zur Station.",
lattitude: "0.000",
longitude: "0.000",
solution: "",

View File

@ -6,10 +6,10 @@
src="https://www.buga2019.de/we-bilder/3.Gartenausstellung/Gelaendeplan/190320_Gelaendeplan-quadratisch.jpg"
></q-img>
<div class="q-ma-md">
<p class="text-h4">{{ data.cacheName }}</p>
<p class="text-h4">{{ cache.name }}</p>
<p class="text-h5">Station {{ showCacheProgress }}</p>
<!-- <p class="text-h5">Station {{ data.station.position }}</p>-->
<p>{{ data.station.description }}</p>
<p>{{ station.description }}</p>
<!--<q-input-->
<!--v-model="description"-->
<!--filled-->
@ -51,20 +51,15 @@
data() {
return {
code: "",
cache: null,
data: {
cacheId: 22,
cacheName: "Wasserfall Cache",
station: {
id: 22,
description: "Ein kleines winterliches Schlaginstrument. Welche Blume ist damit gemeint?",
longitude: 9.206628,
lattitude: 49.147734,
code: 213812,
solution: "Schneeglöckchen"
}
//code: "",
cacheID: "",
cacheName: "",
//cache: null,
cache: {
name: "",
stationen: [],
},
station: {},
// Following Params belong to QR-Code Scanner
askForPermission: true,
@ -79,21 +74,49 @@
}
},
beforeRouteUpdate (to, from, next) {
console.log("beforeRouteUpdate: reset data and fetch");
this.cacheID = "";
this.cacheName = "";
this.cache = {
name: "",
stationen: [],
};
this.station = {};
this.askForPermission = true;
this.activateCamera = false;
this.isValid = false;
this.validating = false;
this.loading = false;
this.paused = false;
this.result = null;
this.params = null;
this.noStreamApiSupport = false;
this.fetchData();
next()
},
created: function () {
console.log("StationView: ")
// console.log("'id' from url: " + this.$route.params.id)
// console.log("'cache' from url: " + this.$route.params.cache)
console.log("StationView: created!");
console.log("'id' from url: " + this.$route.params.id);
console.log("'cache' from url: " + this.$route.params.cache);
this.fetchData();
},
beforeMount: function () {
},
mounted: function () {
},
updated: function () {
},
computed: {
showCacheProgress() {
let stationCount = this.cache.stationen.length;
let stationPos = 1 + this.cache.stationen.findIndex(station => station.id === Number(this.$route.params.id));
return `${stationPos} von ${stationCount}`;
if (this.cache !== null) {
let stationCount = this.cache.stationen.length;
let stationPos = 1 + this.cache.stationen.findIndex(station => station.id === Number(this.$route.params.id));
return `${stationPos} von ${stationCount}`;
} else {
return "";
}
}
},
methods: {
@ -101,73 +124,25 @@
this.$axios.get('/api/allCaches')
.then((response) => {
console.log("/api/allCaches");
console.log(JSON.stringify(this.data));
console.log(this.data);
console.log(response.data);
const cache = response.data.find(cache => cache.id === Number(this.$route.params.cache));
this.data.cacheId = cache.id;
this.data.cacheName = cache.name;
this.cache = cache;
console.log(JSON.stringify(this.data));
this.$axios.get('/api/getAllStations')
.then((response) => {
console.log("/api/getAllStations");
console.log(response.data);
const stationView = response.data.find(station => station.id === Number(this.$route.params.id));
console.log(JSON.stringify(stationView));
this.data.station = stationView;
}).catch((error) => {
// Error
let msg;
let title;
if (error.response) {
// The request was made and the server responded with a status code
title = "Problem with response!";
msg = error.response;
} else if (error.request) {
// The request was made but no response was received
title = "Problem with request!";
msg = "Error occured due to wrong server request!"
console.log(error.request);
} else {
// Something happened in setting up the request that triggered an Error
title = "Error";
msg = error.message;
console.log('Error', error.message);
}
console.log(error.config);
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: msg, title: title, });
})
}).catch((error) => {
// Error
let msg;
let title;
if (error.response) {
// The request was made and the server responded with a status code
title = "Problem with response!";
msg = error.response;
} else if (error.request) {
// The request was made but no response was received
title = "Problem with request!";
msg = "Error occured due to wrong server request!"
console.log(error.request);
} else {
// Something happened in setting up the request that triggered an Error
title = "Error";
msg = error.message;
console.log('Error', error.message);
}
console.log(error.config);
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: msg, title: title, });
})
this.station = cache.stationen.find(station => station.id === Number(this.$route.params.id));
this.cacheName = cache.name;
this.cacheID = this.$route.params.cache;
console.log(JSON.stringify(this.cache));
console.log(JSON.stringify(this.station));
console.log(this.cache);
})
},
setParams() {
console.log("setParams: ");
let params = {};
params.cacheID = this.code.split('/')[0];
params.stationID = this.code.split('/')[1];
params.durchgefuehrterCacheID = this.cacheID;
params.cacheID = this.result.split('/')[0];
params.stationID = this.result.split('/')[1];
params.durchgefuehrterCacheID = params.cacheID;
console.log(params.durchgefuehrterCacheID);
console.log(params.cacheID + " und " + params.stationID);
if (localStorage.getItem('userToken')) {
params.token = JSON.parse(localStorage.getItem('userToken')).token;
@ -197,8 +172,14 @@
this.$axios.get('/api/checkStation', {params})
.then((response) => {
console.log("resolve(true)");
console.log("cache access definition");
console.log(response.data.cacheAccesDefinition);
resolve(true);
this.$router.push({path: `/station/${params.cacheID}/${params.stationID}`});
if (Number(response.data.cacheAccesDefinition.id) === 0) {
this.$router.push({path: `/station/${params.cacheID}/${params.stationID}`});
} else if (Number(response.data.cacheAccesDefinition.id) === 1) {
this.$router.push({path: `/CacheEnd/${params.cacheID}`});
}
}).catch((error) => {
console.log("resolve(false)");
// Error

View File

@ -1,6 +1,6 @@
<template>
<div>
<div v-if="askForPermission">
<div >
<div class="q-ma-md" v-if="askForPermission">
<p>Um den QR-Code scannen zu können, müssen Sie den Zugriff auf Ihre Kamera erlauben.</p>
<q-btn @click="toggleCamera(!activateCamera)" :loading="loading" unelevated color="positive" stack
@ -61,12 +61,18 @@
validate() {
return new Promise(resolve => {
this.setParams(0);
let params = this.params;
let params = this.setParams();
this.$axios.get('/api/checkStation', {params})
.then((response) => {
console.log("resolve(true)");
resolve(true)
console.log("cache access definition");
console.log(response.data.cacheAccesDefinition);
resolve(true);
if (Number(response.data.cacheAccesDefinition.id) === 0) {
this.$router.push({path: `/station/${params.cacheID}/${params.stationID}`});
} else if (Number(response.data.cacheAccesDefinition.id) === 1) {
this.$router.push({path: `/CacheEnd/${params.cacheID}`});
}
}).catch((error) => {
console.log("resolve(false)");
// Error
@ -96,20 +102,17 @@
})
},
setParams(cacheID) {
setParams() {
console.log("setParams: ");
let resCacheID = this.result.split('/')[0];
let resStationID = this.result.split('/')[1];
console.log(resCacheID + " und " + resStationID);
this.params = {
token: null,
cacheID: resCacheID,
stationID: resStationID,
durchgefuehrterCacheID: cacheID
};
let params = {};
params.cacheID = this.result.split('/')[0];
params.stationID = this.result.split('/')[1];
params.durchgefuehrterCacheID = params.cacheID;
console.log(params.cacheID + " und " + params.stationID);
if (localStorage.getItem('userToken')) {
this.params.token = JSON.parse(localStorage.getItem('userToken')).token;
params.token = JSON.parse(localStorage.getItem('userToken')).token;
}
return params;
},
pauseCamera() {

View File

@ -74,6 +74,16 @@ const routes = [
path: "/profile/",
component: () => import("layouts/MyLayout.vue"),
children: [{ path: "", component: () => import("pages/Profile.vue") }]
},
{
path: "/mycaches/",
component: () => import("layouts/MyLayout.vue"),
children: [{ path: "", component: () => import("pages/MyCaches.vue") }]
},
{
path: "/register/",
component: () => import("layouts/MyLayout.vue"),
children: [{ path: "", component: () => import("pages/Register.vue") }]
}
];

View File

@ -10,3 +10,7 @@ export const GET_ENDSTATION = (state) => {
console.log("GET_ENDSTATION: retrieve cache from store. ");
return state.endStation;
};
export const GET_STATIONS = (state) => {
console.log("GET_STATIONEN: retrieve cache from store. ");
return state.newCache.stationen;
};

View File

@ -10,6 +10,10 @@ export const SET_ENDSTATION = (state, station) => {
console.log("SET_ENDSTATION: "+station);
state.endStation = station;
};
export const SET_STATIONS = (state, station) => {
console.log("SET_STATIONEN: "+station);
state.newCache.stationen = station;
};
export const ADD_STATION = (state, station) => {
console.log("ADD_STATION: add new station to cache: "+station);
state.newCache.stationen.push(station);
@ -31,13 +35,18 @@ export const RESET_NEW_CACHE = (state) => {
name: "",
description: "",
rankingPoints: 0,
reward: {
rewardDescription: "",
},
stationen: []
};
state.endStation = {
description: "Endstation",
longitude: 0.0001,
lattitude: 0.0001,
longitude: 9.206628,
lattitude: 49.147734,
solution: "",
};
console.log("resetted new Cache");
};
export const LOAD_REMOTE_CACHE = (state, id) => {

View File

@ -3,48 +3,16 @@ export default {
name: "",
description: "",
rankingPoints: 0,
reward: "",
reward: {
rewardDescription: "",
},
stationen: []
},
// newCache: {
// name: "Blumencache",
// description: "Dieser Cache umfasst 4 Stationen mit Rätseln rund um das Thema Blumen",
// rankingPoints: 100,
// stationen: [
// {
// description: "Ein kleines winterliches Schlaginstrument. Welche Blume ist damit gemeint?",
// longitude: 9.206628,
// lattitude: 49.147734,
// code: 213812,
// solution: "Schneeglöckchen"
// },
// {
// description: "Ein blühendes Federvieh. Welche Blume ist damit gemeint?",
// longitude: 9.206806,
// lattitude: 49.147318,
// code: 237823,
// solution: "Gänseblümchen"
// },
// {
// description: "Eine wertvolle Farbe. Welche Blume ist damit gemeint?",
// longitude: 9.207844,
// lattitude: 49.148032,
// code: 899423,
// solution: "Edelweiß"
// },
// {
// description: "Ein Zerkleinerungsgerät in der Brüllöffnung eines Raubtieres. Welche Blume ist damit gemeint?",
// longitude: 9.207649,
// lattitude: 49.150142,
// code: 347923,
// solution: "Löwenzahn"
// }
// ]
// },
tempStation: {},
endStation: {
description: "Endstation",
longitude: 9.206628,
lattitude: 49.147734,
solution: "",
},
}

View File

@ -0,0 +1,4 @@
/*
export function someAction (context) {
}
*/

View File

@ -0,0 +1,4 @@
/*
export function someGetter (state) {
}
*/

View File

@ -0,0 +1,12 @@
import state from './state'
import * as getters from './getters'
import * as mutations from './mutations'
import * as actions from './actions'
export default {
namespaced: true,
state,
getters,
mutations,
actions
}

View File

@ -0,0 +1,4 @@
/*
export function someMutation (state) {
}
*/

View File

@ -0,0 +1,5 @@
export default {
cache: {},
currentCacheID: null,
currentStationID: null,
}

View File

@ -1,12 +1,12 @@
export function NEW_MESSAGE_DIALOG (state, messageObject) {
console.log("NEW_MESSAGE_DIALOG");
console.log(messageObject);
// console.log("NEW_MESSAGE_DIALOG");
// console.log(messageObject);
if (messageObject == null) {
state.dialog.show = true;
return;
}
console.log(messageObject);
// console.log(messageObject);
if (messageObject.hasOwnProperty('color')) {
switch (messageObject.color) {
@ -39,7 +39,7 @@ export function NEW_MESSAGE_DIALOG (state, messageObject) {
state.dialog.show = true;
}
export function RESET_MESSAGE_DIALOG (state) {
console.log("RESET_MESSAGE_DIALOG");
// console.log("RESET_MESSAGE_DIALOG");
state.dialog.colorBackground = "bg-red-9 text-white";
state.dialog.colorButton = "red-9";
state.dialog.message = "Ein unbekannter Fehler ist aufgetreten. Bitte versuchen Sie es noch einmal.";

View File

@ -4,6 +4,7 @@ import Axios from "axios";
import auth from "./auth"
import cacheCollector from "./cacheCollector"
import dialog from "./dialog"
import currentCache from "./currentCache"
// import example from './module-example'
@ -19,7 +20,8 @@ export default function (/* { ssrContext } */) {
modules: {
auth,
cacheCollector,
dialog
dialog,
currentCache
},
// enable strict mode (adds overhead!)
@ -42,11 +44,15 @@ export default function (/* { ssrContext } */) {
module.hot.accept(['./cacheCollector'], () => {
const cacheCollector = require('./cacheCollector').default;
store.hotUpdate({ modules: { cacheCollector: newCacheCollector } })
})
});
module.hot.accept(['./dialog'], () => {
const dialog = require('./dialog').default;
store.hotUpdate({ modules: { dialog: newDialog } })
})
});
module.hot.accept(['./currentCache'], () => {
const currentCache = require('./currentCache').default;
store.hotUpdate({ modules: { currentCache: newCurrentCache } })
});
}
return Store

View File

@ -6,8 +6,15 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication(exclude = { SecurityAutoConfiguration.class })
@EnableSwagger2
public class Application extends SpringBootServletInitializer{
@Override
@ -18,4 +25,13 @@ public class Application extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public Docket swagger(){
return new Docket(DocumentationType.SWAGGER_2).useDefaultResponseMessages(false)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}

View File

@ -2,11 +2,16 @@ package hhn.labsw.bugageocaching.controller;
import com.google.gson.Gson;
import hhn.labsw.bugageocaching.entities.*;
import hhn.labsw.bugageocaching.helper.POI;
import hhn.labsw.bugageocaching.helper.RankingListHelper;
import hhn.labsw.bugageocaching.helper.TeamRankingListHelper;
import hhn.labsw.bugageocaching.repositories.*;
import hhn.labsw.bugageocaching.util.FinderUtil;
import hhn.labsw.bugageocaching.util.VerificationUtil;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@ -15,7 +20,6 @@ import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import static hhn.labsw.bugageocaching.util.CacheConstructionUtil.createCacheUtil;
import static hhn.labsw.bugageocaching.util.CacheConstructionUtil.deleteCacheUtil;
@ -48,104 +52,120 @@ public class Controller {
@Autowired
User_InfoRepository user_infoRepository;
@Autowired
TeamInviteRepository teamInviteRepository;
@PostConstruct
public void init() {
fetchPublicKey();
}
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
@RequestMapping("/api/allCaches")
@ApiOperation(value = "Retrieves all Caches, including their Stations, from the Database")
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
@RequestMapping(value = "/api/allCaches", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public ResponseEntity getAllCaches() {
return ResponseEntity.status(200).body(new Gson().toJson(cacheRepository.findAll()));
}
// alte startCache-methode
// @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
// @RequestMapping("/api/startCache")
// @ResponseBody
// public ResponseEntity startCache(@RequestParam(value = "token", defaultValue = "-1") String token,
// @RequestParam String cacheID) {
//
// if (!token.equals("-1")) { // ein angemeldeter user startet den cache(es werden zwei parameter übergeben)
//
// Bearbeitet bearbeitet = new Bearbeitet();
//
//
// //----------------------
// //Verify token
// ResponseEntity tokenVerification = VerificationUtil.verifyToken(token);
//
// //Error in token verification
// if (tokenVerification.getStatusCodeValue() != 200) {
// return tokenVerification;
// }
//
// Claims claims = (Claims) tokenVerification.getBody();
//
// ResponseEntity getUser = FinderUtil.findUserFromClaim(claims);
//
// if (getUser.getStatusCodeValue() != 200) {
// return getUser;
// }
//
// User user = (User) getUser.getBody();
//
// bearbeitet.setUser(user);
//
// //----------------------
// //Get Cache
// ResponseEntity getCache = FinderUtil.findCacheById(cacheID);
//
// if (getCache.getStatusCodeValue() != 200) {
// return getCache;
// }
//
// Cache cache = (Cache) getCache.getBody();
// //----------------------
//
// if (bearbeitetRepository.findByUserAndCache(user, cache) != null) {
// Bearbeitet bearbeitet1 = bearbeitetRepository.findByUserAndCache(user, cache);
// return ResponseEntity.status(200).body(bearbeitet1);
// }
//
// bearbeitet.setCache(cache);
//
// Station startStation = cache.getStationen().get(0);
// bearbeitet.setAktuelleStation(startStation);
//
// //Get CacheAccesDefinition
// ResponseEntity getCacheAccesDefinition = FinderUtil.findCacheAccesDefinitionById("0");
//
// if (getCacheAccesDefinition.getStatusCodeValue() != 200) {
// return getCacheAccesDefinition;
// }
//
// CacheAccesDefinition cacheAccesDefinition = (CacheAccesDefinition) getCacheAccesDefinition.getBody();
// //----------------------
// bearbeitet.setCacheAccesDefinition(cacheAccesDefinition);
//
// bearbeitetRepository.save(bearbeitet);
//
// return ResponseEntity.status(201).body(new Gson().toJson(bearbeitet));
//
// } else { // kein angemeldeter User startet den cache(es wird nur der cache als parameter übergeben)
//
// ResponseEntity getCache = FinderUtil.findCacheById(cacheID);
//
// if (getCache.getStatusCodeValue() != 200) {
// return getCache;
// }
//
// Cache cache = (Cache) getCache.getBody();
//
// return ResponseEntity.status(200).body(new Gson().toJson(cache));
// }
// }
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
@RequestMapping("/api/checkStation")
@ApiOperation(value = "Starts the given Cache for the given User")
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error"),
@ApiResponse(code = 401, message = "JWT Token expired"),
@ApiResponse(code = 400, message = "Something went wrong at verification")
})
@RequestMapping(value = "/api/startCache", method = RequestMethod.POST, produces = "application/json")
@ResponseBody
public ResponseEntity startCache(@RequestParam(value = "token", defaultValue = "-1") String token,
@RequestParam String cacheID) {
if (!token.equals("-1")) { // ein angemeldeter user startet den cache(es werden zwei parameter übergeben)
Bearbeitet bearbeitet = new Bearbeitet();
//----------------------
//Verify token
ResponseEntity tokenVerification = VerificationUtil.verifyToken(token);
//Error in token verification
if (tokenVerification.getStatusCodeValue() != 200) {
return tokenVerification;
}
Claims claims = (Claims) tokenVerification.getBody();
ResponseEntity getUser = FinderUtil.findUserFromClaim(claims);
if (getUser.getStatusCodeValue() != 200) {
return getUser;
}
User user = (User) getUser.getBody();
bearbeitet.setUser(user);
//----------------------
//Get Cache
ResponseEntity getCache = FinderUtil.findCacheById(cacheID);
if (getCache.getStatusCodeValue() != 200) {
return getCache;
}
Cache cache = (Cache) getCache.getBody();
//----------------------
if (bearbeitetRepository.findByUserAndCache(user, cache) != null) {
Bearbeitet bearbeitet1 = bearbeitetRepository.findByUserAndCache(user, cache);
return ResponseEntity.status(200).body(bearbeitet1);
}
bearbeitet.setCache(cache);
Station startStation = cache.getStationen().get(0);
bearbeitet.setAktuelleStation(startStation);
//Get CacheAccesDefinition
ResponseEntity getCacheAccesDefinition = FinderUtil.findCacheAccesDefinitionById("0");
if (getCacheAccesDefinition.getStatusCodeValue() != 200) {
return getCacheAccesDefinition;
}
CacheAccesDefinition cacheAccesDefinition = (CacheAccesDefinition) getCacheAccesDefinition.getBody();
//----------------------
bearbeitet.setCacheAccesDefinition(cacheAccesDefinition);
//bearbeitetRepository.save(bearbeitet);
return ResponseEntity.status(201).body(new Gson().toJson(bearbeitet));
} else { // kein angemeldeter User startet den cache(es wird nur der cache als parameter übergeben)
ResponseEntity getCache = FinderUtil.findCacheById(cacheID);
if (getCache.getStatusCodeValue() != 200) {
return getCache;
}
Cache cache = (Cache) getCache.getBody();
return ResponseEntity.status(200).body(new Gson().toJson(cache));
}
}
@ApiOperation(value = "Checks if the given Station is the correct next Station in the Cache")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error"),
@ApiResponse(code = 400, message = "Given Station is NOT the correct following station"),
@ApiResponse(code = 401, message = "JWT Token expired"),
@ApiResponse(code = 400, message = "Something went wrong at verification")
})
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
@RequestMapping(value = "/api/checkStation", method = RequestMethod.PUT, produces = "application/json")
@ResponseBody
public ResponseEntity checkStation(@RequestParam String token,
@RequestParam String cacheID,
@ -205,8 +225,11 @@ public class Controller {
Station station = (Station) getStation.getBody();
//----------------------
if (cache != durchgefuehrterCache) {
return ResponseEntity.status(400).body("The scanned station isn´t the correct following station");
System.out.println(cache.getName());
System.out.println(durchgefuehrterCache.getName());
if (!cacheID.equals(durchgefuehrterCacheID)) {
return ResponseEntity.status(400).body("The scanned station isn´t the correct following station (Name)");
}
if (!cache.getStationen().contains(station)) {
@ -220,6 +243,7 @@ public class Controller {
if (getBearbeitet.getStatusCodeValue() != 200) {
if (cache.getStationen().get(0).equals(station)) {
// start Cache
System.out.println("Startstation");
Bearbeitet bearbeitet = new Bearbeitet();
bearbeitet.setUser(user);
bearbeitet.setCache(cache);
@ -256,7 +280,7 @@ public class Controller {
int i = cache.getStationen().indexOf(station);
if (i == 0) {
return ResponseEntity.status(400).body("The scanned station isn´t the correct following station");
return ResponseEntity.status(400).body("The scanned station isn´t the correct following station (i==0)");
}
if (cache.getStationen().get(i - 1).equals(aktuelleStation)) {
@ -274,13 +298,8 @@ public class Controller {
//----------------------
bearbeitet.setCacheAccesDefinition(cacheAccesDefinition);
//Get User_Info
ResponseEntity getUser_Info = FinderUtil.findUser_InfoByID(String.valueOf(user.getId()));
if (getUser_Info.getStatusCodeValue() != 200) {
return getUser_Info;
}
User_Info user_info = (User_Info) getUser_Info.getBody();
System.out.println(String.valueOf(user.getId()));
User_Info user_info = user_infoRepository.findUser_InfoByUser(user);
//----------------------
user_info.setRankingPointsSum(user_info.getRankingPointsSum() + cache.getRankingPoints());
user_infoRepository.save(user_info);
@ -288,20 +307,31 @@ public class Controller {
bearbeitetRepository.save(bearbeitet);
return ResponseEntity.status(200).body(new Gson().toJson(bearbeitet));
} else {
return ResponseEntity.status(400).body("The scanned station isn´t the correct following station");
return ResponseEntity.status(400).body("The scanned station isn´t the correct following station(nicht letzte)");
}
}
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
@RequestMapping("/api/createCache")
@ApiOperation(value = "Creates a new Cache")
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Something wrong with the given Parameters")
})
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
@RequestMapping(value = "/api/createCache", method = RequestMethod.POST, produces = "application/json")
@ResponseBody
public ResponseEntity createCache(@RequestBody Cache cache) {
return createCacheUtil(cache);
}
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
@RequestMapping("/api/checkAdmin")
@ApiOperation(value = "Checks if the given User has an admin role")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error"),
@ApiResponse(code = 401, message = "JWT Token expired"),
@ApiResponse(code = 400, message = "Something went wrong at verification")
})
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
@RequestMapping(value = "/api/checkAdmin", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public ResponseEntity checkAdmin(@RequestParam String token) {
@ -331,23 +361,36 @@ public class Controller {
return ResponseEntity.status(401).body(false);
}
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
@RequestMapping("/api/getAllStations")
@ApiOperation(value = "Returns all Stations")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error")
})
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
@RequestMapping(value = "/api/getAllStations", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public ResponseEntity getAllStations() {
return ResponseEntity.status(200).body(new Gson().toJson(stationRepository.findAll()));
}
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
@RequestMapping("/api/deleteCache")
@ApiOperation(value = "Deletes a Cache")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error")
})
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
@RequestMapping(value = "/api/deleteCache", method = RequestMethod.DELETE, produces = "application/json")
@ResponseBody
public ResponseEntity deleteCache(@RequestParam String cacheID) {
return deleteCacheUtil(cacheID);
}
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
@RequestMapping("/api/getMyCaches")
@ApiOperation(value = "Returns all Caches finished/started by a given User")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error"),
@ApiResponse(code = 401, message = "JWT Token expired"),
@ApiResponse(code = 400, message = "Something went wrong at verification")
})
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
@RequestMapping(value = "/api/getMyCaches", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public ResponseEntity getMyCaches(@RequestParam String token) {
@ -382,22 +425,52 @@ public class Controller {
}
}
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
@RequestMapping("/api/getRankingList")
@ApiOperation(value = "Returns the rankinglist")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error")
})
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
@RequestMapping(value = "/api/getRankingList", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public ResponseEntity getRankingList() {
List<RankingListHelper> sendBackUsers = new LinkedList<>();
List<Object[]> rankingUsers = userRepository.getRankingList();
for (Object[] obj : rankingUsers) {
RankingListHelper tmp = new RankingListHelper((String) obj[1], (int) obj[2]);
RankingListHelper tmp = new RankingListHelper((String) obj[1], (Integer) obj[2]);
System.out.println(tmp);
sendBackUsers.add(tmp);
}
return ResponseEntity.status(200).body(new Gson().toJson(sendBackUsers));
}
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
@RequestMapping("/api/getUser")
@ApiOperation(value = "Returns the Team Rankinglist")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error")
})
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
@RequestMapping(value = "/api/getTeamRankingList", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public ResponseEntity getTeamRankingList() {
List<TeamRankingListHelper> sendBackTeams = new LinkedList<>();
List<Object[]> rankingTeams = userRepository.getTeamRankingList();
for (Object[] obj : rankingTeams) {
TeamRankingListHelper tmp = new TeamRankingListHelper((String) obj[0], (Integer) obj[1]);
System.out.println(tmp);
sendBackTeams.add(tmp);
}
return ResponseEntity.status(200).body(new Gson().toJson(sendBackTeams));
}
@ApiOperation(value = "Returns a user from a given token")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error"),
@ApiResponse(code = 401, message = "JWT Token expired"),
@ApiResponse(code = 400, message = "Something went wrong at verification")
})
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
@RequestMapping(value = "/api/getUser", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public ResponseEntity getUser(@RequestParam String token) {
@ -424,10 +497,588 @@ public class Controller {
}
}
@RequestMapping("/api/hello")
@ApiOperation(value = "Creates a new Team")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error"),
@ApiResponse(code = 401, message = "JWT Token expired"),
@ApiResponse(code = 400, message = "Something went wrong at verification")
})
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
@RequestMapping(value = "/api/createTeam", method = RequestMethod.POST, produces = "application/json")
@ResponseBody
public ResponseEntity createTeam(@RequestParam String token,
@RequestParam String name) {
// verify user
ResponseEntity verifyToken = VerificationUtil.verifyToken(token);
if (verifyToken.getStatusCodeValue() != 200) {
return verifyToken;
}
// get user
Claims claims = (Claims) verifyToken.getBody();
ResponseEntity getUser = FinderUtil.findUserFromClaim(claims);
if (getUser.getStatusCodeValue() != 200) {
return getUser;
}
User user = (User) getUser.getBody();
//Get User_Info
User_Info user_info = user_infoRepository.findUser_InfoByUser(user);
//----------------------
if (user_info.getTeam() != null) {
return ResponseEntity.status(400).body("You already have a team");
}
// checkt, ob der name bereits vorhanden ist
for (Team team : teamRepository.findAll()) {
if (team.getName().equals(name)) {
return ResponseEntity.status(400).body("The teamname is already taken");
}
}
Team team = new Team();
team.setName(name);
teamRepository.save(team);
user_info.setTeam(team);
user_infoRepository.save(user_info);
return ResponseEntity.status(200).body(new Gson().toJson(team));
}
//---------
@ApiOperation(value = "Lets the user join a Team")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error"),
@ApiResponse(code = 401, message = "JWT Token expired"),
@ApiResponse(code = 400, message = "Something went wrong at verification")
})
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
@RequestMapping(value = "/api/joinTeam", method = RequestMethod.PUT, produces = "application/json")
@ResponseBody
public ResponseEntity joinTeam(@RequestParam String token,
@RequestParam String teamID) {
// verify user
ResponseEntity verifyToken = VerificationUtil.verifyToken(token);
if (verifyToken.getStatusCodeValue() != 200) {
return verifyToken;
}
// get user
Claims claims = (Claims) verifyToken.getBody();
ResponseEntity getUser = FinderUtil.findUserFromClaim(claims);
if (getUser.getStatusCodeValue() != 200) {
return getUser;
}
User user = (User) getUser.getBody();
//Get User_Info
User_Info user_info = user_infoRepository.findUser_InfoByUser(user);
//----------------------
if (user_info.getTeam() != null) {
return ResponseEntity.status(400).body("You already have a team");
}
//Get team
ResponseEntity getTeam = FinderUtil.findTeamById(teamID);
if (getTeam.getStatusCodeValue() != 200) {
return getTeam;
}
Team team = (Team) getTeam.getBody();
int i = 0;
// zählt teammitglieder
for (User_Info userInfo1 : user_infoRepository.findAll()) {
if (userInfo1.getTeam().equals(team)) {
i++;
}
}
// wenn maximalanzahl der teammitglieder erreicht...
if (i >= 10) {
return ResponseEntity.status(400).body("The team already has 10 members");
}
// tritt dem team bei
user_info.setTeam(team);
user_infoRepository.save(user_info);
return ResponseEntity.status(200).body(new Gson().toJson(team));
}
@ApiOperation(value = "Removes the user from the Team")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error"),
@ApiResponse(code = 401, message = "JWT Token expired"),
@ApiResponse(code = 400, message = "Something went wrong at verification")
})
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
@RequestMapping(value = "/api/leaveTeam", method = RequestMethod.PUT, produces = "application/json")
@ResponseBody
public ResponseEntity leaveTeam(@RequestParam String token) {
// verify user
ResponseEntity verifyToken = VerificationUtil.verifyToken(token);
if (verifyToken.getStatusCodeValue() != 200) {
return verifyToken;
}
//get User
Claims claims = (Claims) verifyToken.getBody();
ResponseEntity getUser = FinderUtil.findUserFromClaim(claims);
if (getUser.getStatusCodeValue() != 200) {
return getUser;
}
User user = (User) getUser.getBody();
//Get User_Info
User_Info user_info = user_infoRepository.findUser_InfoByUser(user);
//----------------------
if (user_info.getTeam() == null) {
return ResponseEntity.status(400).body("You aren´t in any team");
}
//Get team
ResponseEntity getTeam = FinderUtil.findTeamById(String.valueOf(user_info.getTeam().getId()));
if (getTeam.getStatusCodeValue() != 200) {
return getTeam;
}
Team team = (Team) getTeam.getBody();
// verlässt team
user_info.setTeam(null);
int i = 0;
// zählt teammitglieder
for (User_Info userInfo1 : user_infoRepository.findAll()) {
if (userInfo1.getTeam().equals(team)) {
i++;
}
}
// löscht team, wenn keine teammitglieder mehr vorhanden
if (i == 0) {
teamRepository.delete(team);
}
user_infoRepository.save(user_info);
return ResponseEntity.status(200).body("Ok");
}
@ApiOperation(value = "Sends a Team Invite to the invitedUserEmail from the User (token)")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error"),
@ApiResponse(code = 401, message = "JWT Token expired"),
@ApiResponse(code = 400, message = "Something went wrong at verification")
})
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
@RequestMapping(value = "/api/sendTeamInvite", method = RequestMethod.POST, produces = "application/json")
@ResponseBody
public ResponseEntity sendTeamInvite(@RequestParam String token,
@RequestParam String invitedUserEmail) {
// verify user
ResponseEntity verifyToken = VerificationUtil.verifyToken(token);
if (verifyToken.getStatusCodeValue() != 200) {
return verifyToken;
}
//get User
Claims claims = (Claims) verifyToken.getBody();
ResponseEntity getUser = FinderUtil.findUserFromClaim(claims);
if (getUser.getStatusCodeValue() != 200) {
return getUser;
}
User user = (User) getUser.getBody();
// get InvitedUser
User invitedUser = userRepository.findByEmail(invitedUserEmail);
if (invitedUser == null) {
return ResponseEntity.status(404).body("There isnt any user with that email");
}
//----------------------
//Get User_Info
User_Info user_info = user_infoRepository.findUser_InfoByUser(user);
//----------------------
if (user_info.getTeam() == null) {
return ResponseEntity.status(400).body("You aren´t in any team");
}
//Get team
ResponseEntity getTeam = FinderUtil.findTeamById(String.valueOf(user_info.getTeam().getId()));
if (getTeam.getStatusCodeValue() != 200) {
return getTeam;
}
Team team = (Team) getTeam.getBody();
if (teamInviteRepository.findByUserAndTeam(invitedUser, team) != null) {
return ResponseEntity.status(400).body("The user is already invited to this team");
}
TeamInvite teamInvite = new TeamInvite();
teamInvite.setUser(invitedUser);
teamInvite.setTeam(team);
teamInviteRepository.save(teamInvite);
return ResponseEntity.status(200).body("OK");
}
@ApiOperation(value = "Returns all User invites for a specific User")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error"),
@ApiResponse(code = 401, message = "JWT Token expired"),
@ApiResponse(code = 400, message = "Something went wrong at verification")
})
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
@RequestMapping(value = "/api/getMyTeamInvites", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public ResponseEntity getMyTeamInvites(@RequestParam String token) {
// verify user
ResponseEntity verifyToken = VerificationUtil.verifyToken(token);
if (verifyToken.getStatusCodeValue() != 200) {
return verifyToken;
}
//get User
Claims claims = (Claims) verifyToken.getBody();
ResponseEntity getUser = FinderUtil.findUserFromClaim(claims);
if (getUser.getStatusCodeValue() != 200) {
return getUser;
}
User user = (User) getUser.getBody();
List<TeamInvite> teamInvitesList = new ArrayList<>();
for (TeamInvite teamInvite : teamInviteRepository.findAll()) {
if (teamInvite.getUser() == user) {
teamInvitesList.add(teamInvite);
}
}
return ResponseEntity.status(200).body(new Gson().toJson(teamInvitesList));
}
@ApiOperation(value = "Removes a team invite from a user (called if a user declined a team invite)")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error"),
@ApiResponse(code = 401, message = "JWT Token expired"),
@ApiResponse(code = 400, message = "Something went wrong at verification")
})
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
@RequestMapping(value = "/api/deleteTeamInvite", method = RequestMethod.DELETE, produces = "application/json")
@ResponseBody
public ResponseEntity deleteTeamInvite(@RequestParam String token,
@RequestParam String teamInviteID) {
// verify user
ResponseEntity verifyToken = VerificationUtil.verifyToken(token);
if (verifyToken.getStatusCodeValue() != 200) {
return verifyToken;
}
// get teaminvite
ResponseEntity getTeamInvite = FinderUtil.findTeamInviteByID(teamInviteID);
if (getTeamInvite.getStatusCodeValue() != 200) {
return getTeamInvite;
}
TeamInvite teamInvite = (TeamInvite) getTeamInvite.getBody();
teamInviteRepository.delete(teamInvite);
return ResponseEntity.status(200).body("OK");
}
@ApiOperation(value = "Sets the team status")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error"),
@ApiResponse(code = 401, message = "JWT Token expired"),
@ApiResponse(code = 400, message = "Something went wrong at verification")
})
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
@RequestMapping(value = "/api/setTeamStatus", method = RequestMethod.PUT, produces = "application/json")
@ResponseBody
public ResponseEntity setTeamStatus(@RequestParam String token,
@RequestParam String teamStatus) {
// verify user
ResponseEntity verifyToken = VerificationUtil.verifyToken(token);
if (verifyToken.getStatusCodeValue() != 200) {
return verifyToken;
}
//get User
Claims claims = (Claims) verifyToken.getBody();
ResponseEntity getUser = FinderUtil.findUserFromClaim(claims);
if (getUser.getStatusCodeValue() != 200) {
return getUser;
}
User user = (User) getUser.getBody();
//Get User_Info
User_Info user_info = user_infoRepository.findUser_InfoByUser(user);
//----------------------
if (user_info.getTeam() == null) {
return ResponseEntity.status(400).body("You aren´t in any team");
}
//Get team
ResponseEntity getTeam = FinderUtil.findTeamById(String.valueOf(user_info.getTeam().getId()));
if (getTeam.getStatusCodeValue() != 200) {
return getTeam;
}
Team team = (Team) getTeam.getBody();
team.setTeamStatus(teamStatus);
teamRepository.save(team);
return ResponseEntity.status(200).body(new Gson().toJson(teamStatus));
}
@ApiOperation(value = "Returns a team by a name")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error"),
})
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
@RequestMapping(value = "/api/getTeam", method = RequestMethod.GET, produces = "application/json")
public ResponseEntity getTeam(@RequestParam String name) {
ResponseEntity responseEntity = FinderUtil.findTeamByName(name);
return responseEntity;
}
@ApiOperation(value = "Returns all teammembers by the team name")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error"),
})
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
@RequestMapping(value = "/api/getTeamMembers", method = RequestMethod.GET, produces = "application/json")
public ResponseEntity getTeamMembers(@RequestParam String name) {
return FinderUtil.findTeammemberByTeamName(name);
}
@ApiOperation(value = "Returns the station the user is currently at (for a specific cache)")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error"),
@ApiResponse(code = 401, message = "JWT Token expired"),
@ApiResponse(code = 400, message = "Something went wrong at verification")
})
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
@RequestMapping(value = "/api/getCurrentStation", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public ResponseEntity getStationFromUserAndCache(@RequestParam String token,
@RequestParam String cacheID) {
// verify user
ResponseEntity verifyToken = VerificationUtil.verifyToken(token);
if (verifyToken.getStatusCodeValue() != 200) {
return verifyToken;
}
// get user
Claims claims = (Claims) verifyToken.getBody();
ResponseEntity getUser = FinderUtil.findUserFromClaim(claims);
if (getUser.getStatusCodeValue() != 200) {
return getUser;
}
User user = (User) getUser.getBody();
//----------------------
//Get Cache
ResponseEntity getCache = FinderUtil.findCacheById(cacheID);
if (getCache.getStatusCodeValue() != 200) {
return getCache;
}
Cache cache = (Cache) getCache.getBody();
//----------------------
return ResponseEntity.status(200).body(bearbeitetRepository.findByUserAndCache(user, cache));
}
@ApiOperation(value = "Returns the ranking place on the leaderboard for a specific user")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error"),
@ApiResponse(code = 401, message = "JWT Token expired"),
@ApiResponse(code = 400, message = "Something went wrong at verification")
})
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
@RequestMapping(value = "/api/getRankingPlace", method = RequestMethod.GET, produces = "application/json")
public ResponseEntity getRankingPlace(@RequestParam String token) {
// verify user
ResponseEntity verifyToken = VerificationUtil.verifyToken(token);
if (verifyToken.getStatusCodeValue() != 200) {
return verifyToken;
}
//get User
Claims claims = (Claims) verifyToken.getBody();
ResponseEntity getUser = FinderUtil.findUserFromClaim(claims);
if (getUser.getStatusCodeValue() != 200) {
return getUser;
}
User user = (User) getUser.getBody();
return ResponseEntity.status(200).body(userRepository.getRankingPlaceFromUser(user.getUsername()));
}
@ApiOperation(value = "Returns startstations and all other stations the user already visited as POIS")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error"),
@ApiResponse(code = 401, message = "JWT Token expired"),
@ApiResponse(code = 400, message = "Something went wrong at verification")
})
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
@RequestMapping(value = "/api/getMyStationPOIS", method = RequestMethod.GET, produces = "application/json")
public ResponseEntity getMyStationPOIS(@RequestParam String token) {
// verify user
ResponseEntity verifyToken = VerificationUtil.verifyToken(token);
if (verifyToken.getStatusCodeValue() != 200) {
return verifyToken;
}
//get User
Claims claims = (Claims) verifyToken.getBody();
ResponseEntity getUser = FinderUtil.findUserFromClaim(claims);
if (getUser.getStatusCodeValue() != 200) {
return getUser;
}
User user = (User) getUser.getBody();
//
ArrayList<POI> poisList = new ArrayList<>();
for (Cache cache : cacheRepository.findAll()) {
Station station = cache.getStationen().get(0);
// ICONS müssen noch erstellt werden und die categoryID entsprechend angepasst
POI poi = new POI(cache.getName() + "_Station1", (float) station.getLattitude(), (float) station.getLongitude(), 0);
poisList.add(poi);
}
for (Bearbeitet bearbeitet : bearbeitetRepository.findAll()) {
if (bearbeitet.getUser() == user) {
Cache cache = bearbeitet.getCache();
Station aktuelleStation = bearbeitet.getAktuelleStation();
int index = cache.getStationen().indexOf(aktuelleStation);
for (int i = 1; i <= index; i++) {
Station station = cache.getStationen().get(i);
// ICONS müssen noch erstellt werden und die categoryID entsprechend angepasst
int categoryID;
if (i < cache.getStationen().size() - 1) { // isnt endstation
categoryID = 1;
} else { // is endstation
categoryID = 2;
}
POI poi = new POI(cache.getName() + "_Station" + (i + 1), (float) station.getLattitude(), (float) station.getLongitude(), categoryID);
poisList.add(poi);
}
}
}
POI[] pois = new POI[poisList.size()];
for (int i = 0; i < poisList.size(); i++) {
pois[i] = poisList.get(i);
}
return ResponseEntity.status(200).body(new Gson().toJson(pois));
}
@ApiOperation(value = "Returns the Team of a user")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error"),
@ApiResponse(code = 401, message = "JWT Token expired"),
@ApiResponse(code = 400, message = "Something went wrong at verification")
})
@RequestMapping(value = "/api/getTeamOfUser", method = RequestMethod.GET, produces = "application/json")
public ResponseEntity getTeamOfUser(@RequestParam String token){
// verify user
ResponseEntity verifyToken = VerificationUtil.verifyToken(token);
if (verifyToken.getStatusCodeValue() != 200) {
return verifyToken;
}
//get User
Claims claims = (Claims) verifyToken.getBody();
ResponseEntity getUser = FinderUtil.findUserFromClaim(claims);
if (getUser.getStatusCodeValue() != 200) {
return getUser;
}
User user = (User) getUser.getBody();
User_Info user_info = user_infoRepository.findUser_InfoByUser(user);
return ResponseEntity.status(200).body(user_info.getTeam());
}
@ApiOperation(value = "Test method (Changes its purpose often)")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error"),
@ApiResponse(code = 401, message = "JWT Token expired"),
@ApiResponse(code = 400, message = "Something went wrong at verification")
})
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
@RequestMapping(value = "/api/hello", method = RequestMethod.GET, produces = "application/json")
public ResponseEntity hello(@RequestParam String name) {
return ResponseEntity.status(200).body(userRepository.getRankingPlaceFromUser(name));
}
}

View File

@ -1,6 +1,9 @@
package hhn.labsw.bugageocaching.entities;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
@ -11,16 +14,24 @@ public class Cache {
@Id
@GeneratedValue
@ApiModelProperty(notes = "The autogenerated CacheID (Primary Key)")
private int id;
@ApiModelProperty(notes = "The name of the Cache")
private String name;
@ApiModelProperty(notes = "The Description of the Cache")
private String description;
@ApiModelProperty(notes = "The number of ranking points the user gets fro completing the cache")
private int rankingPoints;
@OneToMany
@ApiModelProperty(notes = "All stations included in the Cache")
private List<Station> stationen = new ArrayList<>();
@ManyToOne
@ApiModelProperty(notes = "The Reward for the Cache")
@ManyToOne (cascade = {CascadeType.ALL})
private Reward reward;
public Cache() {

View File

@ -13,7 +13,8 @@ public class Team {
private int id;
private String name;
private int rankingPoints;
private String teamStatus;
public int getId() {
return id;
@ -31,11 +32,11 @@ public class Team {
this.name = name;
}
public int getRankingPoints() {
return rankingPoints;
public String getTeamStatus() {
return teamStatus;
}
public void setRankingPoints(int rankingPoints) {
this.rankingPoints = rankingPoints;
public void setTeamStatus(String teamStatus) {
this.teamStatus = teamStatus;
}
}

View File

@ -0,0 +1,42 @@
package hhn.labsw.bugageocaching.entities;
import javax.persistence.*;
@Entity
@Table
public class TeamInvite {
@Id
@GeneratedValue
private int id;
@OneToOne
private User user;
@OneToOne
private Team team;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Team getTeam() {
return team;
}
public void setTeam(Team team) {
this.team = team;
}
}

View File

@ -1,7 +1,9 @@
package hhn.labsw.bugageocaching.entities;
import org.hibernate.validator.constraints.UniqueElements;
import org.springframework.context.annotation.Primary;
import javax.annotation.Generated;
import javax.persistence.*;
import java.io.Serializable;
@ -15,6 +17,9 @@ public class User_Info implements Serializable {
private User user;
@Id
@GeneratedValue
private int id;
private int rankingPointsSum;
@ManyToOne
@ -24,6 +29,14 @@ public class User_Info implements Serializable {
public User_Info() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public User getUser() {
return user;
}
@ -47,4 +60,5 @@ public class User_Info implements Serializable {
public void setTeam(Team team) {
this.team = team;
}
}

View File

@ -4,5 +4,5 @@ import java.io.Serializable;
public class User_InfoID implements Serializable {
private int user;
private int rankingPointsSum;
private int id;
}

View File

@ -0,0 +1,49 @@
package hhn.labsw.bugageocaching.helper;
public class POI {
private String Name;
private float Latitude;
private float Longitude;
// ICONS müssen noch erstellt werden und die categoryID entsprechend angepasst
private int CategoryID; // 0 = grünes icon(startstation) // 1 = orangenes icon(folgestationen) // 2 = rotes icon(endstation)
public POI(String name, float latitude, float longitude, int categoryID) {
Name = name;
Latitude = latitude;
Longitude = longitude;
CategoryID = categoryID;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public float getLatitude() {
return Latitude;
}
public void setLatitude(float latitude) {
Latitude = latitude;
}
public float getLongitude() {
return Longitude;
}
public void setLongitude(float longitude) {
Longitude = longitude;
}
public int getCategoryID() {
return CategoryID;
}
public void setCategoryID(int categoryID) {
CategoryID = categoryID;
}
}

View File

@ -3,11 +3,11 @@ package hhn.labsw.bugageocaching.helper;
public class RankingListHelper {
private String username;
private int ranking_Points;
private int rankingPointsSum;
public RankingListHelper(String username, int ranking_Points) {
this.username = username;
this.ranking_Points = ranking_Points;
this.rankingPointsSum = ranking_Points;
}
public String getUsername() {
@ -19,10 +19,15 @@ public class RankingListHelper {
}
public int getRanking_Points() {
return ranking_Points;
return rankingPointsSum;
}
public void setRanking_Points(int ranking_Points) {
this.ranking_Points = ranking_Points;
this.rankingPointsSum = ranking_Points;
}
@Override
public String toString() {
return "( " + username + " | " + rankingPointsSum + " )";
}
}

View File

@ -0,0 +1,34 @@
package hhn.labsw.bugageocaching.helper;
public class TeamRankingListHelper {
private String teamname;
private int rankingPointsSum;
public TeamRankingListHelper(String teamname, int ranking_Points) {
this.teamname = teamname;
this.rankingPointsSum = ranking_Points;
}
public String getTeamname() {
return teamname;
}
public void setTeamname(String teamname) {
this.teamname = teamname;
}
public int getRanking_Points() {
return rankingPointsSum;
}
public void setRanking_Points(int ranking_Points) {
this.rankingPointsSum = ranking_Points;
}
@Override
public String toString() {
return "( " + teamname + " | " + rankingPointsSum + " )";
}
}

View File

@ -0,0 +1,11 @@
package hhn.labsw.bugageocaching.repositories;
import hhn.labsw.bugageocaching.entities.Cache;
import hhn.labsw.bugageocaching.entities.Team;
import hhn.labsw.bugageocaching.entities.TeamInvite;
import hhn.labsw.bugageocaching.entities.User;
import org.springframework.data.jpa.repository.JpaRepository;
public interface TeamInviteRepository extends JpaRepository<TeamInvite, Integer> {
TeamInvite findByUserAndTeam(User user, Team team);
}

View File

@ -1,8 +1,28 @@
package hhn.labsw.bugageocaching.repositories;
import hhn.labsw.bugageocaching.entities.Team;
import hhn.labsw.bugageocaching.entities.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
public interface TeamRepository extends JpaRepository<Team, Integer> {
Team findByName(String name);
@Query(value = "SELECT *\n" +
"FROM user\n" +
"WHERE id = (\n" +
" SELECT user_id\n" +
" FROM user_info\n" +
" WHERE team_id = (SELECT team_id\n" +
" FROM team\n" +
" WHERE name = ?1\n" +
" )\n" +
")", nativeQuery = true)
List<Object[]> getTeammembers(String name);
}

View File

@ -7,7 +7,7 @@ import org.springframework.data.repository.CrudRepository;
import java.util.List;
public interface UserRepository extends CrudRepository<User, Integer> {
User findByUsername(String username);
User findByEmail(String email);
@Query(value = "SELECT DISTINCT u.id AS ID, SUBSTRING_INDEX(u.email, '@', 1) AS Name, ui.ranking_points_sum AS Ranglistenpunkte\n" +
"FROM user u,\n" +
@ -16,7 +16,7 @@ public interface UserRepository extends CrudRepository<User, Integer> {
"WHERE u.id = ui.user_id\n" +
"AND u.id = ur.user_id\n" +
"order by ranking_points_sum DESC\n" +
"LIMIT 100;", nativeQuery = true)
"LIMIT 10;", nativeQuery = true)
List<Object[]> getRankingList();
@Query(value = "SELECT Rang\n" +
@ -35,4 +35,18 @@ public interface UserRepository extends CrudRepository<User, Integer> {
"WHERE Name = ?1", nativeQuery = true)
int getRankingPlaceFromUser(String username);
@Query(value = "SELECT DISTINCT t.name AS teamname, SUM(ui.ranking_points_sum) AS Ranglistenpunkte\n" +
"FROM user u,\n" +
" user_info ui,\n" +
" user_roles ur,\n" +
" team t\n" +
"WHERE u.id = ui.user_id\n" +
" AND u.id = ur.user_id\n" +
" AND t.id = ui.team_id\n" +
" AND ui.team_id IS NOT NULL\n" +
"GROUP BY teamname\n" +
"ORDER by ranking_points_sum DESC" +
"LIMIT 10;", nativeQuery = true)
List<Object[]> getTeamRankingList();
}

View File

@ -1,8 +1,13 @@
package hhn.labsw.bugageocaching.repositories;
import hhn.labsw.bugageocaching.entities.User;
import hhn.labsw.bugageocaching.entities.User_Info;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
public interface User_InfoRepository extends CrudRepository<User_Info, Integer> {
import java.util.List;
import java.util.Optional;
public interface User_InfoRepository extends CrudRepository<User_Info, Integer> {
User_Info findUser_InfoByUser(User user);
}

View File

@ -10,6 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
@Component
@ -31,10 +33,12 @@ public class FinderUtil {
static User_InfoRepository user_infoRepository;
static TeamInviteRepository teamInviteRepository;
@Autowired
public void setCacheRepository(CacheRepository cacheRepository) {
FinderUtil.cacheRepository= cacheRepository;
FinderUtil.cacheRepository = cacheRepository;
}
@Autowired
@ -72,6 +76,11 @@ public class FinderUtil {
FinderUtil.user_infoRepository = user_infoRepository;
}
@Autowired
public void setTeamInviteRepository(TeamInviteRepository teamInviteRepository) {
FinderUtil.teamInviteRepository = teamInviteRepository;
}
public static ResponseEntity findCacheById(String cacheID) {
@ -104,16 +113,6 @@ public class FinderUtil {
return ResponseEntity.status(404).body("The user has not started this cache yet");
}
public static ResponseEntity findUserByUsername(String username) {
User user = userRepository.findByUsername(username);
if (user != null) {
return ResponseEntity.status(200).body(user);
}
return ResponseEntity.status(404).body("Couldnt find user with username " + username);
}
public static ResponseEntity findCacheAccesDefinitionById(String cacheAccesDefinitionID) {
Optional<CacheAccesDefinition> cacheAccesDefinitionOptional = cacheAccesDefinitionRepository.findById(Integer.valueOf(cacheAccesDefinitionID));
if (cacheAccesDefinitionOptional.isPresent()) {
@ -123,15 +122,6 @@ public class FinderUtil {
}
}
public static ResponseEntity findUser_InfoByID(String infoID) {
Optional<User_Info> user_InfoOptional = user_infoRepository.findById(Integer.valueOf(infoID));
if (user_InfoOptional.isPresent()) {
return ResponseEntity.status(200).body(user_InfoOptional.get());
} else {
return ResponseEntity.status(404).body("Couldnt find User_Info " + infoID);
}
}
public static ResponseEntity findUserFromClaim(Claims claims) {
try {
@ -152,4 +142,51 @@ public class FinderUtil {
}
}
public static ResponseEntity findTeamById(String teamID) {
Optional<Team> teamOptional = teamRepository.findById(Integer.valueOf(teamID));
if (teamOptional.isPresent()) {
return ResponseEntity.status(200).body(teamOptional.get());
} else {
return ResponseEntity.status(404).body("Couldnt find User_Info " + teamID);
}
}
public static ResponseEntity findTeamInviteByID(String teamInviteID) {
Optional<TeamInvite> teamInviteOptional = teamInviteRepository.findById(Integer.valueOf(teamInviteID));
if (teamInviteOptional.isPresent()) {
return ResponseEntity.status(200).body(teamInviteOptional.get());
} else {
return ResponseEntity.status(404).body("Couldnt find User_Info " + teamInviteID);
}
}
public static ResponseEntity findTeamByName(String name) {
Team team = teamRepository.findByName(name);
if (team != null) {
return ResponseEntity.status(200).body(team);
} else {
return ResponseEntity.status(404).body("Couldnt find Team with name " + name);
}
}
public static ResponseEntity findTeammemberByTeamName(String name) {
List<Object[]> list = teamRepository.getTeammembers(name);
if (list != null) {
List<User> sendBack = new LinkedList<>();
for (Object[] obj :
list) {
User tmp = new User();
tmp.setUsername((String) obj[3]);
sendBack.add(tmp);
}
return ResponseEntity.status(200).body(sendBack);
} else {
return ResponseEntity.status(404).body("Couldnt find Team member of Team " + name);
}
}
}

View File

@ -5,4 +5,5 @@ spring.jmx.default-domain=buga19geocaching
spring.datasource.driver-class-name=org.mariadb.jdbc.Driver
spring.jooq.sql-dialect=org.hibernate.dialect.MariaDBDialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.show-sql=true
debug=true