Merge branch 'develop' into frontend/robin

This commit is contained in:
rchrist 2019-05-16 16:39:48 +02:00
commit 0675bdc2a4
15 changed files with 123 additions and 127 deletions

View File

@ -93,9 +93,15 @@
console.log(params);
if (!params.cacheID || !params.stationID || !params.durchgefuehrterCacheID || !params.token) {
console.log("Mindestens 1 Parameter konnte nicht erkannt werden!");
let header = "Fehler!";
let message = "Der erkannte QR-Code ist fehlerhaft oder gehört nicht zu BuGa Geocaching.";
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: message, title: header, });
resolve(false);
} else if (isNaN(params.cacheID) || isNaN(params.stationID) || isNaN(params.durchgefuehrterCacheID)) {
console.log("Mindestens 1 Parameter ist fehlerhaft!");
let header = "Fehler!";
let message = "Der erkannte QR-Code ist fehlerhaft oder gehört nicht zu BuGa Geocaching.";
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: message, title: header, });
resolve(false);
} else {
this.$axios.put('/api/checkStation', null, { params })
@ -162,12 +168,12 @@
},
updateProps() {
console.log("emit result!")
console.log("emit result!");
this.$emit('result', this.params)
},
updateCameraState() {
console.log("Camera State:")
console.log(!this.askForPermission)
console.log("Camera State:");
console.log(!this.askForPermission);
this.$emit('camera', !this.askForPermission)
},

View File

@ -1,5 +1,5 @@
<template>
<q-layout view="hhh Lpr lFf">
<q-layout view="hhh Lpr lFf" @click.native="counter()">
<q-header id="qheader" class="bg-white text-grey-14" elevated>
<q-toolbar class="q-pa-md">
<q-img src="statics/buga_logo.svg" style="max-width: 40px;" class="q-mr-sm"/>
@ -162,6 +162,17 @@
<q-item-label>Login</q-item-label>
</q-item-section>
</q-item>
<!-- <q-item-->
<!-- disable-->
<!-- class="text-grey-5"-->
<!-- >-->
<!-- <q-item-section avatar>-->
<!-- </q-item-section>-->
<!-- <q-item-section>-->
<!-- <q-item-label>dev: {{ clickCounter }} clicks</q-item-label>-->
<!-- </q-item-section>-->
<!-- </q-item>-->
</q-list>
</q-drawer>
@ -196,6 +207,7 @@
data() {
return {
leftDrawerOpen: this.$q.platform.is.desktop,
clickCounter: 0,
};
},
computed: {
@ -238,7 +250,10 @@
//this.evalAuthentication();
},
methods: {
//openURL
counter() {
this.clickCounter++;
//console.log(this.clickCounter);
},
dialogClose() {
console.log("dialogClose(): ")
this.$store.commit('dialog/RESET_MESSAGE_DIALOG');

View File

@ -124,7 +124,7 @@
created: function () {
console.log("isNewCache: " + this.isNewCache);
console.log("Route Params: " + this.$route.params.id);
if (!this.isNewCache) {
if (!this.isNewCache && !this.$store.getters['cacheCollector/GET_LOCK']) {
this.$axios.get('/api/allCaches')
.then((response) => {
console.log("/api/allCaches");
@ -140,8 +140,8 @@
this.$store.commit('cacheCollector/SET_STATIONS', stations);
this.$store.commit('cacheCollector/SET_ENDSTATION', endstation);
})
}
this.$store.commit('cacheCollector/SET_LOCK', false);
},
beforeMount: function () {
},
@ -174,25 +174,22 @@
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});
} else {
// TODO Stationen bearbeitbar machen bevor sie abgeschickt werden. Am besten Station Objekt als Übergabe Parameter bei Router
this.$store.commit('cacheCollector/SET_TEMPSTATION', station);
this.$store.commit('cacheCollector/SET_LOCK', true);
this.$router.push({path: `/tempstation/${index}`}); // add parameter
}
},
deleteStation(index) {
// TODO wenn Station id hat, mit Backend abgleichen
this.$store.commit('cacheCollector/REMOVE_STATION', index);
},
saveCache() {
// commit to store, send to api, if success -> reset store
console.log("saveCache!");
let cache = JSON.parse(JSON.stringify(this.computedCache));
console.log(cache);
cache.stationen.push(this.computedEndstation);
console.log("isnewcache "+this.isNewCache)
if (this.isNewCache) {
console.log("CREATECACHE")
this.$axios.post('/api/createCache', cache)
.then((response) => {
console.log("POST api/createCache: " + response.statusText);
@ -217,6 +214,7 @@
this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: msg, title: title,});
})
} else {
console.log("EDITCACHE")
this.$axios.put('/api/editCache', cache)
.then((response) => {
console.log("POST api/editCache: " + response.statusText);

View File

@ -1,6 +1,6 @@
<template>
<div class="q-pa-md">
<form class="login">
<form class="login" @submit.prevent="login">
<div class="q-pa-md">
<p class="text-black text-h5"> Login </p>
<div class="column q-gutter-lg" style="">
@ -24,14 +24,13 @@
<div class="">
<div class="" style="max-width: 440px">
<q-btn
type="submit"
:outline="userAuthenticated"
:disabled="!loginValidation"
:loading="loading"
label="Login"
color="primary"
class="full-width"
@click="login"
@keyup.enter="login"
unelevated
>
<template v-slot:loading>
@ -114,7 +113,7 @@
let title;
if (error.response) {
title = "Fehler!";
msg = error.response.data;
msg = "E-Mail oder Passwort ist falsch. Bitte überprüfe deine Eingaben!";
} else if (error.request) {
title = "Verbindungsfehler!";
msg = "Es konnte keine Verbindung zum Server aufgebaut werden. Versuchen Sie es später noch einmal!"

View File

@ -21,6 +21,7 @@
<q-tab-panels v-model="tab" animated swipeable class="col">
<q-tab-panel name="startedCaches" class=" fit">
<p class="text-grey-4 text-h5 text-center" v-if="startedCaches.filter(cache => cache.cacheAccesDefinition.id === 0).length === 0">keine Einträge</p>
<q-list>
<q-card
class="q-mb-md"
@ -55,6 +56,7 @@
</q-tab-panel>
<q-tab-panel name="finishedCaches" class="fit">
<p class="text-grey-4 text-h5 text-center" v-if="startedCaches.filter(cache => cache.cacheAccesDefinition.id === 1).length === 0">keine Einträge</p>
<q-list>
<q-card class="q-mb-md"
v-for="finishedCache in startedCaches.filter(cache => cache.cacheAccesDefinition.id === 1)"

View File

@ -27,6 +27,7 @@
color="primary"
size="10em"
/>
<p class="text-grey-4 text-h5 text-center" v-if="caches.length === 0">keine Einträge</p>
<q-list v-if="render">
<q-card class="q-mb-md" v-for="cache in caches" :key="cache.id">
<q-expansion-item
@ -229,6 +230,7 @@
},
addCache() {
this.$store.commit('cacheCollector/RESET_NEW_CACHE');
this.$router.push({path: `/cache`})
},
editCache(cacheID) {

View File

@ -135,13 +135,17 @@
})
.catch((error) => {
let message;
let header = "Unbekannter Fehler...";
let header = "Unbekannter Fehler!";
if (error.response) {
console.log(error.response)
console.log(error.response);
if (error.response.status === 409) {
message = "Die E-Mail-Adresse wird bereits verwendet!";
header = "Anmeldedaten überprüfen!";
}
if (error.response.status === 500) {
message= "Der Anmeldeserver konnte die Daten nicht verarbeiten.";
header= "Fehler!";
}
} else if (error.request) {
console.log(error.request);
header = "Anfrage fehlgeschlagen!";

View File

@ -22,7 +22,7 @@
></q-img>
<div class="row q-col-gutter-md">
<q-input class="col" dense stack-label filled v-model="latlang" @input="separateLatlang"
label="Längengrad/Breitengrad"/>
label="Breitengrad/Längengrad"/>
<div class="col-shrink">
<q-btn unelevated color="primary" class="full-height" icon="my_location"/>
</div>
@ -97,13 +97,20 @@
saveStation() {
console.log("saveStation(): ");
console.log(this.station);
console.log(this.isNewStation);
console.log(this.$route.params.pos);
if (this.isNewStation) {
this.$store.commit('cacheCollector/ADD_STATION', this.station);
} else {
this.$store.commit('cacheCollector/EDIT_STATION', {index: this.$route.params.pos, station: this.station});
this.$store.commit('cacheCollector/SET_TEMPSTATION', null);
}
let cache = this.$store.getters['cacheCollector/GET_CACHE'];
if (cache.hasOwnProperty('id')) {
this.$router.push({path: `/cache/${cache.id}`});
} else {
this.$router.push({path: `/cache`});
}
console.log("station saved..");
},
dismiss() {

View File

@ -9,7 +9,7 @@
></q-img>
<div class="row q-col-gutter-md">
<q-input class="col" dense stack-label filled v-model="latlang" @input="separateLatlang"
label="Längengrad/Breitengrad"/>
label="Breitengrad/Längengrad"/>
<div class="col-shrink">
<q-btn unelevated color="primary" class="full-height" icon="my_location"/>
</div>

View File

@ -2,6 +2,10 @@ export const GET_CACHE = (state) => {
console.log("GET_CACHE: retrieve cache from store. ");
return state.newCache;
};
export const GET_LOCK = (state) => {
console.log("GET_LOCK: ");
return state.locked;
};
export const GET_TEMPSTATION = (state) => {
console.log("GET_TEMPSTATION: retrieve cache from store. ");
return state.tempStation;

View File

@ -1,7 +1,11 @@
export const SET_CACHE = (state, cache) => {
console.log("SET_CACHE: save cache to store. ")
console.log("SET_CACHE: save cache to store. ");
state.newCache = cache;
};
export const SET_LOCK = (state, bool) => {
console.log("SET_LOCK: ");
state.locked = bool;
};
export const SET_TEMPSTATION = (state, station) => {
console.log("SET_TEMPSTATION: add new station to cache: "+station);
state.tempStation = station;
@ -25,6 +29,7 @@ export const EDIT_STATION = (state, indexStation) => {
console.log("EDIT_STATION: "+index+" "+station);
state.newCache.stationen[index] = station;
console.log("EDIT_STATION: "+JSON.stringify(state.newCache.stationen[index]));
};
export const REMOVE_STATION = (state, index) => {
console.log("REMOVE_STATION: "+index);

View File

@ -1,4 +1,5 @@
export default {
locked: false,
newCache: {
name: "",
description: "",

View File

@ -72,98 +72,11 @@ public class Controller {
@ResponseBody
public ResponseEntity getAllCaches() {
logger.warn("API CALL: /api/allCaches");
logger.debug("/api/allCaches PARAMETERS: -");
return ResponseEntity.status(200).body(new Gson().toJson(cacheRepository.findAll()));
}
@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"),
@ -327,6 +240,8 @@ public class Controller {
@RequestMapping(value = "/api/createCache", method = RequestMethod.POST, produces = "application/json")
@ResponseBody
public ResponseEntity createCache(@RequestBody Cache cache) {
logger.warn("API CALL: api/createCache");
logger.debug("/api/allCaches PARAMETERS:\ncache: " + cache.getName());
return createCacheUtil(cache);
}
@ -340,7 +255,8 @@ public class Controller {
@RequestMapping(value = "/api/editCache", method = RequestMethod.PUT, produces = "application/json")
@ResponseBody
public ResponseEntity editCache(@RequestBody Cache newCache) {
logger.warn("API CALL: /api/editCache");
logger.debug("/api/editCache PARAMETERS:\nnewCache: " + newCache.getName());
return editCacheUtil(newCache);
}
@ -391,6 +307,7 @@ public class Controller {
@ResponseBody
public ResponseEntity getAllStations() {
logger.warn("API CALL: /api/getAllStations");
logger.debug("/api/getAllStations: PARAMETERS: -");
return ResponseEntity.status(200).body(new Gson().toJson(stationRepository.findAll()));
}
@ -399,10 +316,11 @@ public class Controller {
@ApiResponse(code = 404, message = "Database error")
})
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
@RequestMapping(value = "/api/deleteCache", method = {RequestMethod.DELETE, RequestMethod.GET}, produces = "application/json")
@RequestMapping(value = "/api/deleteCache", method = {RequestMethod.DELETE}, produces = "application/json")
@ResponseBody
public ResponseEntity deleteCache(@RequestParam String cacheID) {
logger.warn("API CALL: /api/deleteCache");
logger.debug("/api/deleteCache: PARAMETERS:\ncacheID: " + cacheID);
return deleteCacheUtil(cacheID);
}
@ -418,6 +336,7 @@ public class Controller {
public ResponseEntity getMyCaches(@RequestParam String token) {
logger.warn("API CALL: /api/getMyCaches");
logger.debug("/api/getMyCaches: PARAMETERS:\ntoken: " + token);
ResponseEntity verifyToken = VerificationUtil.verifyToken(token);
@ -465,6 +384,7 @@ public class Controller {
public ResponseEntity getRankingList() {
logger.warn("API CALL: /api/getRankingList");
logger.debug("/api/getRankingList: PARAMETERS: -");
List<RankingListHelper> sendBackUsers = new LinkedList<>();
@ -489,14 +409,21 @@ public class Controller {
@ResponseBody
public ResponseEntity getTeamRankingList() {
logger.warn("API CALL: /api/getTeamRankingList");
logger.debug("/api/getTeamRankingList: PARAMETERS: -");
List<TeamRankingListHelper> sendBackTeams = new LinkedList<>();
logger.debug("/api/getTeamRankingList Created List sendBackTeams");
List<Object[]> rankingTeams = userRepository.getTeamRankingList();
logger.debug("/api/getTeamRankingList Got Rankinglist in Format Object[]");
logger.debug("/api/getTeamRankingList Convert Object to TeamRankingListHelper");
for (Object[] obj : rankingTeams) {
BigDecimal i = (BigDecimal) obj[1];
TeamRankingListHelper tmp = new TeamRankingListHelper((String) obj[0], i.intValue());
System.out.println(tmp);
sendBackTeams.add(tmp);
}
logger.debug("/api/getTeamRankingList Send RankingList to Frontend");
return ResponseEntity.status(200).body(new Gson().toJson(sendBackTeams));
}
@ -511,25 +438,37 @@ public class Controller {
@ResponseBody
public ResponseEntity getUser(@RequestParam String token) {
logger.warn("API CALL: /api/getUser");
logger.debug("/api/getUser: PARAMETERS:\ntoken: " + token);
logger.debug("/api/getUser Trying to verify Token: " + token);
ResponseEntity verifyToken = VerificationUtil.verifyToken(token);
if (verifyToken.getStatusCodeValue() != 200) {
logger.debug("/api/getUser Error in Verification of Token: " + token);
return verifyToken;
}
logger.debug("/api/getUser Trying to get User");
Claims claims = (Claims) verifyToken.getBody();
logger.debug("/api/getUser Got Claim: " + new GsonBuilder().setPrettyPrinting().create().toJson(claims));
ResponseEntity getUser = FinderUtil.findUserFromClaim(claims);
if (getUser.getStatusCodeValue() != 200) {
logger.debug("/api/getUser Error getting User");
return getUser;
}
User user = (User) getUser.getBody();
logger.debug("/api/getUser Got User: " + user.getEmail());
if (user != null) {
logger.debug("/api/getUser User != null " + user.getEmail());
logger.debug("/api/getUser Send User to Frontend");
return ResponseEntity.status(200).body(new Gson().toJson(user));
} else {
logger.debug("Error in Getting User");
return ResponseEntity.status(404).body("Es gab einen Fehler. Bitte versuche es erneut oder kontaktiere einen Admin!e");
}
}
@ -721,6 +660,10 @@ public class Controller {
// löscht team, wenn keine teammitglieder mehr vorhanden
if (user_infos.size() == 0) {
List<TeamInvite> teamInvites = teamInviteRepository.findByTeam(team);
for (TeamInvite teamInvite : teamInvites) {
teamInviteRepository.delete(teamInvite);
}
teamRepository.delete(team);
}
@ -763,6 +706,10 @@ public class Controller {
if (invitedUser == null) {
return ResponseEntity.status(404).body("Es gibt keinen Benutzer mit dieser email.");
}
if (invitedUser == user) {
return ResponseEntity.status(404).body("Du kannst dich selbst nicht einladen.");
}
//----------------------

View File

@ -11,4 +11,5 @@ import java.util.List;
public interface TeamInviteRepository extends JpaRepository<TeamInvite, Integer> {
TeamInvite findByUserAndTeam(User user, Team team);
List<TeamInvite> findByUser(User user);
List<TeamInvite> findByTeam(Team team);
}

View File

@ -45,12 +45,14 @@ public class CacheConstructionUtil {
public static ResponseEntity createCacheUtil(Cache cache) {
// Stationen werden in die Datenbank eingetragen
int position = 1;
for (Station station : cache.getStationen()) {
ResponseEntity response = createStationUtil(station);
ResponseEntity response = createStationUtil(station, position);
if (response.getStatusCodeValue() == 400) {
deleteStationenUtil(cache);
return response;
}
position++;
}
// Caches werden in die Datenbank eingetragen
@ -81,18 +83,19 @@ public class CacheConstructionUtil {
return ResponseEntity.status(200).body(new Gson().toJson(cache));
}
public static ResponseEntity createStationUtil(Station station) {
public static ResponseEntity createStationUtil(Station station, int position) {
if (station.getDescription().length() == 0 || station.getLattitude() == 0.0 || station.getLongitude() == 0.0 /*|| station.getSolution().length() == 0*/) {
if (station.getDescription().length() == 0 /*|| station.getSolution().length() == 0*/) {
return ResponseEntity.status(400).body("Alle Felder müssen ausgefüllt werden!");
}
if (station.getLattitude() < 9 || station.getLattitude() > 10) {
return ResponseEntity.status(400).body("Die Lattitude ist außerhalb der Bundesgartenschau");
if (station.getLattitude() < 49 || station.getLattitude() > 50) {
return ResponseEntity.status(400).body("Der Breitengrad der Station " + position + " ist außerhalb der Bundesgartenschau. Dieser muss zwischen 49 und 50 liegen.");
}
if (station.getLongitude() < 49 || station.getLongitude() > 50) {
return ResponseEntity.status(400).body("Die Longitude ist außerhalb der Bundesgartenschau");
if (station.getLongitude() < 9 || station.getLongitude() > 10) {
return ResponseEntity.status(400).body("Der Längengrad der Station " + position + " ist außerhalb der Bundesgartenschau. Dieser muss zwischen 9 und 10 liegen.");
}
Random r = new Random();
@ -135,20 +138,21 @@ public class CacheConstructionUtil {
ResponseEntity response = new ResponseEntity(HttpStatus.ACCEPTED);
List<Station> newCreatedStationList = new ArrayList<Station>();
int position = 1;
for (Station station : cache.getStationen()) {
boolean stationIsNew = true;
for (Station oldStation : oldCache.getStationen()) {
// wenn Station schon vorher vorhanden war, wird diese mit den neuen Daten geupdatet
if (oldStation.getId() == station.getId()) {
response = createStationUtil(station);
response = createStationUtil(station, position);
stationIsNew = false;
break;
}
}
// wenn Station neu hinzugefügt wurde, wird die Station zusätzlich in die Datenbank gespeichert
// wenn Station neu hinzugefügt wurde, wirdcd die Station zusätzlich in die Datenbank gespeichert
if (stationIsNew) {
response = createStationUtil(station);
response = createStationUtil(station, position);
if (response.getStatusCodeValue() == 200) {
newCreatedStationList.add(station);
}
@ -163,6 +167,7 @@ public class CacheConstructionUtil {
deleteNewCreatedStationsUtil(newCreatedStationList);
return response;
}
position++;
}
// überprüft den Cache nach validen Daten