Added map api call for the last station you visited from a cache
This commit is contained in:
parent
e64b607276
commit
8ba109427c
@ -62,6 +62,13 @@ dependencies {
|
|||||||
// https://mvnrepository.com/artifact/com.mashape.unirest/unirest-java
|
// https://mvnrepository.com/artifact/com.mashape.unirest/unirest-java
|
||||||
compile group: 'com.mashape.unirest', name: 'unirest-java', version: '1.3.1'
|
compile group: 'com.mashape.unirest', name: 'unirest-java', version: '1.3.1'
|
||||||
|
|
||||||
|
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
|
||||||
|
compile group: 'org.slf4j', name:'slf4j-api', version: '1.7.2'
|
||||||
|
compile group: 'ch.qos.logback', name:'logback-classic', version: '1.0.9'
|
||||||
|
compile group: 'ch.qos.logback', name:'logback-core', version: '1.0.9'
|
||||||
|
|
||||||
|
testCompile group: 'junit', name: 'junit', version: '4.+'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
node {
|
node {
|
||||||
|
|||||||
@ -12,7 +12,10 @@ import io.jsonwebtoken.Claims;
|
|||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import io.swagger.annotations.ApiResponse;
|
import io.swagger.annotations.ApiResponse;
|
||||||
import io.swagger.annotations.ApiResponses;
|
import io.swagger.annotations.ApiResponses;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@ -56,6 +59,8 @@ public class Controller {
|
|||||||
@Autowired
|
@Autowired
|
||||||
TeamInviteRepository teamInviteRepository;
|
TeamInviteRepository teamInviteRepository;
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(Controller.class);
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init(){
|
public void init(){
|
||||||
fetchPublicKey();
|
fetchPublicKey();
|
||||||
@ -985,7 +990,7 @@ public class Controller {
|
|||||||
Cache cache = (Cache) getCache.getBody();
|
Cache cache = (Cache) getCache.getBody();
|
||||||
//----------------------
|
//----------------------
|
||||||
|
|
||||||
return ResponseEntity.status(200).body(bearbeitetRepository.findByUserAndCache(user, cache));
|
return ResponseEntity.status(200).body(new Gson().toJson(bearbeitetRepository.findByUserAndCache(user, cache)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Returns the ranking place on the leaderboard for a specific user")
|
@ApiOperation(value = "Returns the ranking place on the leaderboard for a specific user")
|
||||||
@ -1006,7 +1011,7 @@ public class Controller {
|
|||||||
@ApiResponse(code = 401, message = "JWT Token expired"),
|
@ApiResponse(code = 401, message = "JWT Token expired"),
|
||||||
@ApiResponse(code = 400, message = "Something went wrong at verification")
|
@ApiResponse(code = 400, message = "Something went wrong at verification")
|
||||||
})
|
})
|
||||||
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
|
||||||
@RequestMapping(value = "/api/getMyStationPOIS", method = RequestMethod.GET, produces = "application/json")
|
@RequestMapping(value = "/api/getMyStationPOIS", method = RequestMethod.GET, produces = "application/json")
|
||||||
public ResponseEntity getMyStationPOIS(@RequestParam String token) {
|
public ResponseEntity getMyStationPOIS(@RequestParam String token) {
|
||||||
// verify user
|
// verify user
|
||||||
@ -1072,7 +1077,7 @@ public class Controller {
|
|||||||
@ApiResponse(code = 401, message = "JWT Token expired"),
|
@ApiResponse(code = 401, message = "JWT Token expired"),
|
||||||
@ApiResponse(code = 400, message = "Something went wrong at verification")
|
@ApiResponse(code = 400, message = "Something went wrong at verification")
|
||||||
})
|
})
|
||||||
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
|
||||||
@RequestMapping(value = "/api/getTeamOfUser", method = RequestMethod.GET, produces = "application/json")
|
@RequestMapping(value = "/api/getTeamOfUser", method = RequestMethod.GET, produces = "application/json")
|
||||||
public ResponseEntity getTeamOfUser(@RequestParam String token) {
|
public ResponseEntity getTeamOfUser(@RequestParam String token) {
|
||||||
|
|
||||||
@ -1099,6 +1104,75 @@ public class Controller {
|
|||||||
return ResponseEntity.status(200).body(user_info.getTeam());
|
return ResponseEntity.status(200).body(user_info.getTeam());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "Returns the Team of a 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/getCurrentStationMap", method = RequestMethod.GET, produces = "application/json")
|
||||||
|
public ResponseEntity getCurrentStationMap(@RequestParam String token, @RequestParam String cacheID){
|
||||||
|
|
||||||
|
logger.warn("API CALL: /api/getCurrentStationMap");
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
logger.debug("User verificated: " + user.getEmail());
|
||||||
|
|
||||||
|
//----------------------
|
||||||
|
//Get Cache
|
||||||
|
ResponseEntity getCache = FinderUtil.findCacheById(cacheID);
|
||||||
|
|
||||||
|
if (getCache.getStatusCodeValue() != 200) {
|
||||||
|
return getCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
Cache cache = (Cache) getCache.getBody();
|
||||||
|
|
||||||
|
logger.debug("Cache: " + cache.getName());
|
||||||
|
//----------------------
|
||||||
|
|
||||||
|
ResponseEntity responseBearbeitet = FinderUtil.findBearbeitetByUserAndCache(user, cache);
|
||||||
|
|
||||||
|
if (responseBearbeitet.getStatusCodeValue() != 200){
|
||||||
|
return responseBearbeitet;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bearbeitet bearbeitet = (Bearbeitet) responseBearbeitet.getBody();
|
||||||
|
logger.debug("Got Bearbeitet:\n User: " + bearbeitet.getUser().getEmail() + "\nCache: " + bearbeitet.getCache().getName());
|
||||||
|
|
||||||
|
Station nextStation = bearbeitet.getAktuelleStation();
|
||||||
|
logger.debug("Got Station from bearbeitet: " + nextStation.getDescription());
|
||||||
|
|
||||||
|
int index = cache.getStationen().indexOf(nextStation);
|
||||||
|
logger.debug("Index of Station " + nextStation.getDescription() + " in Cache " + cache.getName() + " : " + index);
|
||||||
|
|
||||||
|
Station lastStation = cache.getStationen().get(index - 1);
|
||||||
|
logger.debug("Station before: " + lastStation.getDescription());
|
||||||
|
|
||||||
|
POI poi = new POI(cache.getName() + "_Station" + (index - 1.0), (float) lastStation.getLattitude(), (float) lastStation.getLongitude(), 201);
|
||||||
|
logger.debug("Created POI: " + poi.toString());
|
||||||
|
|
||||||
|
return ResponseEntity.status(200).body(new Gson().toJson(poi));
|
||||||
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Test method (Changes its purpose often)")
|
@ApiOperation(value = "Test method (Changes its purpose often)")
|
||||||
@ApiResponses(value = {
|
@ApiResponses(value = {
|
||||||
@ApiResponse(code = 404, message = "Database error"),
|
@ApiResponse(code = 404, message = "Database error"),
|
||||||
|
|||||||
@ -45,4 +45,9 @@ public class POI {
|
|||||||
public void setCategoryID(int categoryID) {
|
public void setCategoryID(int categoryID) {
|
||||||
CategoryID = categoryID;
|
CategoryID = categoryID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Name: " + getName() + "; Latitude " + getLatitude() + "; Longitude " + getLongitude() + "; categoryID " + getLongitude();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user