-
{{ data.cacheName }}
+
{{ cache.name }}
Station {{ showCacheProgress }}
-
{{ data.station.description }}
+
{{ station.description }}
@@ -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
diff --git a/frontend/src/pages/qr-scanner.vue b/frontend/src/pages/qr-scanner.vue
index 087cb71..e111c73 100644
--- a/frontend/src/pages/qr-scanner.vue
+++ b/frontend/src/pages/qr-scanner.vue
@@ -1,6 +1,6 @@
-
-
+
+
Um den QR-Code scannen zu können, müssen Sie den Zugriff auf Ihre Kamera erlauben.
{
- 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() {
diff --git a/frontend/src/router/routes.js b/frontend/src/router/routes.js
index 1a1e7ff..6a39f45 100644
--- a/frontend/src/router/routes.js
+++ b/frontend/src/router/routes.js
@@ -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") }]
}
];
diff --git a/frontend/src/store/cacheCollector/getters.js b/frontend/src/store/cacheCollector/getters.js
index d2bea70..a09722a 100644
--- a/frontend/src/store/cacheCollector/getters.js
+++ b/frontend/src/store/cacheCollector/getters.js
@@ -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;
+};
diff --git a/frontend/src/store/cacheCollector/mutations.js b/frontend/src/store/cacheCollector/mutations.js
index 72f58e1..fb9ae86 100644
--- a/frontend/src/store/cacheCollector/mutations.js
+++ b/frontend/src/store/cacheCollector/mutations.js
@@ -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) => {
diff --git a/frontend/src/store/cacheCollector/state.js b/frontend/src/store/cacheCollector/state.js
index 0f32de1..aef4926 100644
--- a/frontend/src/store/cacheCollector/state.js
+++ b/frontend/src/store/cacheCollector/state.js
@@ -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: "",
},
}
diff --git a/frontend/src/store/currentCache/actions.js b/frontend/src/store/currentCache/actions.js
new file mode 100644
index 0000000..4787a5f
--- /dev/null
+++ b/frontend/src/store/currentCache/actions.js
@@ -0,0 +1,4 @@
+/*
+export function someAction (context) {
+}
+*/
diff --git a/frontend/src/store/currentCache/getters.js b/frontend/src/store/currentCache/getters.js
new file mode 100644
index 0000000..cc054a3
--- /dev/null
+++ b/frontend/src/store/currentCache/getters.js
@@ -0,0 +1,4 @@
+/*
+export function someGetter (state) {
+}
+*/
diff --git a/frontend/src/store/currentCache/index.js b/frontend/src/store/currentCache/index.js
new file mode 100644
index 0000000..b41a219
--- /dev/null
+++ b/frontend/src/store/currentCache/index.js
@@ -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
+}
diff --git a/frontend/src/store/currentCache/mutations.js b/frontend/src/store/currentCache/mutations.js
new file mode 100644
index 0000000..63131e2
--- /dev/null
+++ b/frontend/src/store/currentCache/mutations.js
@@ -0,0 +1,4 @@
+/*
+export function someMutation (state) {
+}
+*/
diff --git a/frontend/src/store/currentCache/state.js b/frontend/src/store/currentCache/state.js
new file mode 100644
index 0000000..dbc1d63
--- /dev/null
+++ b/frontend/src/store/currentCache/state.js
@@ -0,0 +1,5 @@
+export default {
+ cache: {},
+ currentCacheID: null,
+ currentStationID: null,
+}
diff --git a/frontend/src/store/dialog/mutations.js b/frontend/src/store/dialog/mutations.js
index 8994399..4a14ffa 100644
--- a/frontend/src/store/dialog/mutations.js
+++ b/frontend/src/store/dialog/mutations.js
@@ -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.";
diff --git a/frontend/src/store/index.js b/frontend/src/store/index.js
index 58a40f8..9a7a3b2 100644
--- a/frontend/src/store/index.js
+++ b/frontend/src/store/index.js
@@ -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
diff --git a/src/main/java/hhn/labsw/bugageocaching/Application.java b/src/main/java/hhn/labsw/bugageocaching/Application.java
index 75f1fb0..f835849 100644
--- a/src/main/java/hhn/labsw/bugageocaching/Application.java
+++ b/src/main/java/hhn/labsw/bugageocaching/Application.java
@@ -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();
+ }
}
diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java
index ac8fd0e..abd7b33 100644
--- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java
+++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java
@@ -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 sendBackUsers = new LinkedList<>();
List