implemented getStationPOIS

This commit is contained in:
Michael 2019-05-03 19:10:03 +02:00
parent c86ce22d27
commit 6ca87f84fc
2 changed files with 72 additions and 8 deletions

View File

@ -2,6 +2,7 @@ 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.*;
@ -971,10 +972,66 @@ public class Controller {
return ResponseEntity.status(200).body(userRepository.getRankingPlaceFromUser(user.getUsername()));
}
@ApiOperation(value = "Returns startstations and all other stations he 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/getRankingPlace", method = RequestMethod.GET, produces = "application/json")
public ResponseEntity getMyMap() {
@RequestMapping(value = "/api/getStationPOIS", method = RequestMethod.GET, produces = "application/json")
public ResponseEntity getStationPOIS(@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);
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);
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 = "Test method (Changes its purpose often)")

View File

@ -7,6 +7,13 @@ public class POI {
private float Longitude;
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;
}