Merge branch 'develop' into frontend/timo

This commit is contained in:
Timo Volkmann 2019-05-16 14:41:19 +02:00
commit ab213517b7
5 changed files with 53 additions and 100 deletions

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>

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

@ -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);
@ -448,7 +367,7 @@ public class Controller {
}
}*/
List<Bearbeitet> bearbeitetList = bearbeitetRepository.findByUser(user);
logger.debug("/api/getMyCaches Got all bearbeitet entreis of user: " +user.getEmail());
logger.debug("/api/getMyCaches Got all bearbeitet entreis of user: " + user.getEmail());
return ResponseEntity.status(200).body(new Gson().toJson(bearbeitetList));
} else {
return ResponseEntity.status(404).body("Es gab einen Fehler. Bitte versuche es erneut oder kontaktiere einen Admin!");
@ -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.getSolution().length() == 0*/) {
return ResponseEntity.status(400).body("Alle Felder müssen ausgefüllt werden!");
}
if (station.getLattitude() < 49 || station.getLattitude() > 50) {
return ResponseEntity.status(400).body("Der Breitengrad einer Station ist außerhalb der Bundesgartenschau");
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() < 9 || station.getLongitude() > 10) {
return ResponseEntity.status(400).body("Der Längengrad einer Station ist außerhalb der Bundesgartenschau");
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