Some changes

This commit is contained in:
Maximilian Leopold 2019-04-29 17:35:50 +02:00
parent bd811fbe99
commit 9816cdf488
8 changed files with 118 additions and 100 deletions

View File

@ -109,7 +109,7 @@ module.exports = function (ctx) {
API: JSON.stringify('http://localhost:8080') API: JSON.stringify('http://localhost:8080')
} }
: { // Base URL for API-Calls: PRODUCTION (build) : { // Base URL for API-Calls: PRODUCTION (build)
//API: JSON.stringify('http://seserver.se.hs-heilbronn.de:8090/buga19geocaching') //API: JSON.stringify('http://seserver.se.hs-heilbronn.de:9080/buga19geocaching')
API: JSON.stringify('http://localhost:8080') API: JSON.stringify('http://localhost:8080')
} }
}, },

View File

@ -97,7 +97,8 @@
params.cacheID = this.result.split('/')[0]; params.cacheID = this.result.split('/')[0];
params.stationID = this.result.split('/')[1]; params.stationID = this.result.split('/')[1];
params.durchgefuehrterCacheID = this.cacheID; 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')) { if (localStorage.getItem('userToken')) {
params.token = JSON.parse(localStorage.getItem('userToken')).token; params.token = JSON.parse(localStorage.getItem('userToken')).token;
} }

View File

@ -110,7 +110,7 @@
console.log("POST /api/register/ - json: " + JSON.stringify(data)); console.log("POST /api/register/ - json: " + JSON.stringify(data));
const token = JSON.parse(localStorage.getItem('registerToken')).token; const token = JSON.parse(localStorage.getItem('registerToken')).token;
this.$axios.post('http://www.se.hs-heilbronn.de:8090/buga19usermanagement/account/register', data,{ this.$axios.post('http://www.se.hs-heilbronn.de:9080/buga19usermanagement/account/register', data,{
headers: { headers: {
'Authorization': 'Bearer ' + token, 'Authorization': 'Bearer ' + token,
} }
@ -167,7 +167,7 @@
console.log("GET /api/login/ - json: " + JSON.stringify(logindata)); console.log("GET /api/login/ - json: " + JSON.stringify(logindata));
this.$axios.post('http://www.se.hs-heilbronn.de:8090/buga19usermanagement/account/login', logindata) this.$axios.post('http://www.se.hs-heilbronn.de:9080/buga19usermanagement/account/login', logindata)
.then((response) => { .then((response) => {
localStorage.setItem('registerToken', JSON.stringify(response.data)); localStorage.setItem('registerToken', JSON.stringify(response.data));
}) })

View File

@ -167,7 +167,8 @@
let params = {}; let params = {};
params.cacheID = this.result.split('/')[0]; params.cacheID = this.result.split('/')[0];
params.stationID = this.result.split('/')[1]; params.stationID = this.result.split('/')[1];
params.durchgefuehrterCacheID = this.cacheID; params.durchgefuehrterCacheID = params.cacheID;
console.log(params.durchgefuehrterCacheID);
console.log(params.cacheID + " und " + params.stationID); console.log(params.cacheID + " und " + params.stationID);
if (localStorage.getItem('userToken')) { if (localStorage.getItem('userToken')) {
params.token = JSON.parse(localStorage.getItem('userToken')).token; params.token = JSON.parse(localStorage.getItem('userToken')).token;

View File

@ -16,7 +16,6 @@ import javax.annotation.PostConstruct;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Optional;
import static hhn.labsw.bugageocaching.util.CacheConstructionUtil.createCacheUtil; import static hhn.labsw.bugageocaching.util.CacheConstructionUtil.createCacheUtil;
import static hhn.labsw.bugageocaching.util.CacheConstructionUtil.deleteCacheUtil; import static hhn.labsw.bugageocaching.util.CacheConstructionUtil.deleteCacheUtil;
@ -61,88 +60,88 @@ public class Controller {
return ResponseEntity.status(200).body(new Gson().toJson(cacheRepository.findAll())); return ResponseEntity.status(200).body(new Gson().toJson(cacheRepository.findAll()));
} }
// alte startCache-methode
// @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
// @RequestMapping("/api/startCache") @RequestMapping("/api/startCache")
// @ResponseBody @ResponseBody
// public ResponseEntity startCache(@RequestParam(value = "token", defaultValue = "-1") String token, public ResponseEntity startCache(@RequestParam(value = "token", defaultValue = "-1") String token,
// @RequestParam String cacheID) { @RequestParam String cacheID) {
//
// if (!token.equals("-1")) { // ein angemeldeter user startet den cache(es werden zwei parameter übergeben) if (!token.equals("-1")) { // ein angemeldeter user startet den cache(es werden zwei parameter übergeben)
//
// Bearbeitet bearbeitet = new Bearbeitet(); Bearbeitet bearbeitet = new Bearbeitet();
//
//
// //---------------------- //----------------------
// //Verify token //Verify token
// ResponseEntity tokenVerification = VerificationUtil.verifyToken(token); ResponseEntity tokenVerification = VerificationUtil.verifyToken(token);
//
// //Error in token verification //Error in token verification
// if (tokenVerification.getStatusCodeValue() != 200) { if (tokenVerification.getStatusCodeValue() != 200) {
// return tokenVerification; return tokenVerification;
// } }
//
// Claims claims = (Claims) tokenVerification.getBody(); Claims claims = (Claims) tokenVerification.getBody();
//
// ResponseEntity getUser = FinderUtil.findUserFromClaim(claims); ResponseEntity getUser = FinderUtil.findUserFromClaim(claims);
//
// if (getUser.getStatusCodeValue() != 200) { if (getUser.getStatusCodeValue() != 200) {
// return getUser; return getUser;
// } }
//
// User user = (User) getUser.getBody(); User user = (User) getUser.getBody();
//
// bearbeitet.setUser(user); bearbeitet.setUser(user);
//
// //---------------------- //----------------------
// //Get Cache //Get Cache
// ResponseEntity getCache = FinderUtil.findCacheById(cacheID); ResponseEntity getCache = FinderUtil.findCacheById(cacheID);
//
// if (getCache.getStatusCodeValue() != 200) { if (getCache.getStatusCodeValue() != 200) {
// return getCache; return getCache;
// } }
//
// Cache cache = (Cache) getCache.getBody(); Cache cache = (Cache) getCache.getBody();
// //---------------------- //----------------------
//
// if (bearbeitetRepository.findByUserAndCache(user, cache) != null) { if (bearbeitetRepository.findByUserAndCache(user, cache) != null) {
// Bearbeitet bearbeitet1 = bearbeitetRepository.findByUserAndCache(user, cache); Bearbeitet bearbeitet1 = bearbeitetRepository.findByUserAndCache(user, cache);
// return ResponseEntity.status(200).body(bearbeitet1); return ResponseEntity.status(200).body(bearbeitet1);
// } }
//
// bearbeitet.setCache(cache); bearbeitet.setCache(cache);
//
// Station startStation = cache.getStationen().get(0); Station startStation = cache.getStationen().get(0);
// bearbeitet.setAktuelleStation(startStation); bearbeitet.setAktuelleStation(startStation);
//
// //Get CacheAccesDefinition //Get CacheAccesDefinition
// ResponseEntity getCacheAccesDefinition = FinderUtil.findCacheAccesDefinitionById("0"); ResponseEntity getCacheAccesDefinition = FinderUtil.findCacheAccesDefinitionById("0");
//
// if (getCacheAccesDefinition.getStatusCodeValue() != 200) { if (getCacheAccesDefinition.getStatusCodeValue() != 200) {
// return getCacheAccesDefinition; return getCacheAccesDefinition;
// } }
//
// CacheAccesDefinition cacheAccesDefinition = (CacheAccesDefinition) getCacheAccesDefinition.getBody(); CacheAccesDefinition cacheAccesDefinition = (CacheAccesDefinition) getCacheAccesDefinition.getBody();
// //---------------------- //----------------------
// bearbeitet.setCacheAccesDefinition(cacheAccesDefinition); bearbeitet.setCacheAccesDefinition(cacheAccesDefinition);
//
// bearbeitetRepository.save(bearbeitet); //bearbeitetRepository.save(bearbeitet);
//
// return ResponseEntity.status(201).body(new Gson().toJson(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) } else { // kein angemeldeter User startet den cache(es wird nur der cache als parameter übergeben)
//
// ResponseEntity getCache = FinderUtil.findCacheById(cacheID); ResponseEntity getCache = FinderUtil.findCacheById(cacheID);
//
// if (getCache.getStatusCodeValue() != 200) { if (getCache.getStatusCodeValue() != 200) {
// return getCache; return getCache;
// } }
//
// Cache cache = (Cache) getCache.getBody(); Cache cache = (Cache) getCache.getBody();
//
// return ResponseEntity.status(200).body(new Gson().toJson(cache)); return ResponseEntity.status(200).body(new Gson().toJson(cache));
// } }
// } }
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
@RequestMapping("/api/checkStation") @RequestMapping("/api/checkStation")
@ -205,8 +204,11 @@ public class Controller {
Station station = (Station) getStation.getBody(); Station station = (Station) getStation.getBody();
//---------------------- //----------------------
if (cache != durchgefuehrterCache) { System.out.println(cache.getName());
return ResponseEntity.status(400).body("The scanned station isn´t the correct following station"); 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)) { if (!cache.getStationen().contains(station)) {
@ -220,6 +222,7 @@ public class Controller {
if (getBearbeitet.getStatusCodeValue() != 200) { if (getBearbeitet.getStatusCodeValue() != 200) {
if (cache.getStationen().get(0).equals(station)) { if (cache.getStationen().get(0).equals(station)) {
// start Cache // start Cache
System.out.println("Startstation");
Bearbeitet bearbeitet = new Bearbeitet(); Bearbeitet bearbeitet = new Bearbeitet();
bearbeitet.setUser(user); bearbeitet.setUser(user);
bearbeitet.setCache(cache); bearbeitet.setCache(cache);
@ -256,7 +259,7 @@ public class Controller {
int i = cache.getStationen().indexOf(station); int i = cache.getStationen().indexOf(station);
if (i == 0) { 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)) { if (cache.getStationen().get(i - 1).equals(aktuelleStation)) {
@ -274,6 +277,7 @@ public class Controller {
//---------------------- //----------------------
bearbeitet.setCacheAccesDefinition(cacheAccesDefinition); bearbeitet.setCacheAccesDefinition(cacheAccesDefinition);
//Get User_Info //Get User_Info
System.out.println(String.valueOf(user.getId()));
ResponseEntity getUser_Info = FinderUtil.findUser_InfoByID(String.valueOf(user.getId())); ResponseEntity getUser_Info = FinderUtil.findUser_InfoByID(String.valueOf(user.getId()));
if (getUser_Info.getStatusCodeValue() != 200) { if (getUser_Info.getStatusCodeValue() != 200) {
@ -282,13 +286,13 @@ public class Controller {
User_Info user_info = (User_Info) getUser_Info.getBody(); User_Info user_info = (User_Info) getUser_Info.getBody();
//---------------------- //----------------------
user_info.setRankingPointsSum(user_info.getRankingPointsSum() + cache.getRankingPoints()); //user_info.setRankingPointsSum(user_info.getRankingPointsSum() + cache.getRankingPoints());
user_infoRepository.save(user_info); user_infoRepository.save(user_info);
} }
bearbeitetRepository.save(bearbeitet); bearbeitetRepository.save(bearbeitet);
return ResponseEntity.status(200).body(new Gson().toJson(bearbeitet)); return ResponseEntity.status(200).body(new Gson().toJson(bearbeitet));
} else { } 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)");
} }
} }

View File

@ -2,6 +2,7 @@ package hhn.labsw.bugageocaching.entities;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import javax.annotation.Generated;
import javax.persistence.*; import javax.persistence.*;
import java.io.Serializable; import java.io.Serializable;
@ -15,6 +16,8 @@ public class User_Info implements Serializable {
private User user; private User user;
@Id @Id
private int id;
private int rankingPointsSum; private int rankingPointsSum;
@ManyToOne @ManyToOne
@ -47,4 +50,5 @@ public class User_Info implements Serializable {
public void setTeam(Team team) { public void setTeam(Team team) {
this.team = team; this.team = team;
} }
} }

View File

@ -1,8 +1,16 @@
package hhn.labsw.bugageocaching.repositories; package hhn.labsw.bugageocaching.repositories;
import hhn.labsw.bugageocaching.entities.User;
import hhn.labsw.bugageocaching.entities.User_Info; import hhn.labsw.bugageocaching.entities.User_Info;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository; 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 findByUser(User user);
@Query(value = "SELECT * FROM user_info WHERE user_id = ?1", nativeQuery = true)
User_Info findUser_InfoByUserId(int UserId);
} }

View File

@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Optional; import java.util.Optional;
@Component @Component
@ -124,12 +125,11 @@ public class FinderUtil {
} }
public static ResponseEntity findUser_InfoByID(String infoID) { public static ResponseEntity findUser_InfoByID(String infoID) {
Optional<User_Info> user_InfoOptional = user_infoRepository.findById(Integer.valueOf(infoID)); User_Info user_info = user_infoRepository.findUser_InfoByUserId(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); return ResponseEntity.status(200).body(user_info);
}
} }
public static ResponseEntity findUserFromClaim(Claims claims) { public static ResponseEntity findUserFromClaim(Claims claims) {