Merge branch 'develop' into frontend/robin
This commit is contained in:
commit
93e5a150cd
@ -40,7 +40,7 @@ dependencies {
|
|||||||
|
|
||||||
compile 'org.springframework.boot:spring-boot-starter-tomcat'
|
compile 'org.springframework.boot:spring-boot-starter-tomcat'
|
||||||
//compile 'org.springframework.boot:spring-boot-starter-security'
|
//compile 'org.springframework.boot:spring-boot-starter-security'
|
||||||
//compile 'org.springframework.boot:spring-boot-starter-actuator'
|
compile 'org.springframework.boot:spring-boot-starter-actuator'
|
||||||
//compile 'org.springframework.boot:spring-boot-starter-aop'
|
//compile 'org.springframework.boot:spring-boot-starter-aop'
|
||||||
//ompile group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version: '1.2.0.RELEASE'
|
//ompile group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version: '1.2.0.RELEASE'
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package hhn.labsw.bugageocaching.controller;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import hhn.labsw.bugageocaching.entities.*;
|
import hhn.labsw.bugageocaching.entities.*;
|
||||||
import hhn.labsw.bugageocaching.helper.RankingListHelper;
|
import hhn.labsw.bugageocaching.helper.RankingListHelper;
|
||||||
|
import hhn.labsw.bugageocaching.helper.TeamRankingListHelper;
|
||||||
import hhn.labsw.bugageocaching.repositories.*;
|
import hhn.labsw.bugageocaching.repositories.*;
|
||||||
import hhn.labsw.bugageocaching.util.FinderUtil;
|
import hhn.labsw.bugageocaching.util.FinderUtil;
|
||||||
import hhn.labsw.bugageocaching.util.VerificationUtil;
|
import hhn.labsw.bugageocaching.util.VerificationUtil;
|
||||||
@ -48,7 +49,6 @@ public class Controller {
|
|||||||
@Autowired
|
@Autowired
|
||||||
User_InfoRepository user_infoRepository;
|
User_InfoRepository user_infoRepository;
|
||||||
|
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
fetchPublicKey();
|
fetchPublicKey();
|
||||||
@ -390,12 +390,28 @@ public class Controller {
|
|||||||
List<RankingListHelper> sendBackUsers = new LinkedList<>();
|
List<RankingListHelper> sendBackUsers = new LinkedList<>();
|
||||||
List<Object[]> rankingUsers = userRepository.getRankingList();
|
List<Object[]> rankingUsers = userRepository.getRankingList();
|
||||||
for (Object[] obj : rankingUsers) {
|
for (Object[] obj : rankingUsers) {
|
||||||
RankingListHelper tmp = new RankingListHelper((String) obj[1], (int) obj[2]);
|
RankingListHelper tmp = new RankingListHelper((String) obj[1], (Integer) obj[2]);
|
||||||
|
System.out.println(tmp);
|
||||||
sendBackUsers.add(tmp);
|
sendBackUsers.add(tmp);
|
||||||
}
|
}
|
||||||
return ResponseEntity.status(200).body(new Gson().toJson(sendBackUsers));
|
return ResponseEntity.status(200).body(new Gson().toJson(sendBackUsers));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||||
|
@RequestMapping("/api/getTeamRankingList")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseEntity getTeamRankingList() {
|
||||||
|
|
||||||
|
List<TeamRankingListHelper> sendBackTeams = new LinkedList<>();
|
||||||
|
List<Object[]> rankingTeams = userRepository.getTeamRankingList();
|
||||||
|
for (Object[] obj : rankingTeams) {
|
||||||
|
TeamRankingListHelper tmp = new TeamRankingListHelper((String) obj[0], (Integer) obj[1]);
|
||||||
|
System.out.println(tmp);
|
||||||
|
sendBackTeams.add(tmp);
|
||||||
|
}
|
||||||
|
return ResponseEntity.status(200).body(new Gson().toJson(sendBackTeams));
|
||||||
|
}
|
||||||
|
|
||||||
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||||
@RequestMapping("/api/getUser")
|
@RequestMapping("/api/getUser")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@ -424,6 +440,192 @@ public class Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||||
|
@RequestMapping("/api/createTeam")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseEntity createTeam(@RequestParam String token,
|
||||||
|
@RequestParam String name) {
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
//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();
|
||||||
|
//----------------------
|
||||||
|
if (user_info.getTeam() != null) {
|
||||||
|
return ResponseEntity.status(400).body("You already have a team");
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkt, ob der name bereits vorhanden ist
|
||||||
|
for (Team team : teamRepository.findAll()) {
|
||||||
|
if (team.getName().equals(name)) {
|
||||||
|
return ResponseEntity.status(400).body("The teamname is already taken");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Team team = new Team();
|
||||||
|
team.setName(name);
|
||||||
|
teamRepository.save(team);
|
||||||
|
|
||||||
|
user_info.setTeam(team);
|
||||||
|
user_infoRepository.save(user_info);
|
||||||
|
|
||||||
|
return ResponseEntity.status(200).body(new Gson().toJson(team));
|
||||||
|
}
|
||||||
|
|
||||||
|
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||||
|
@RequestMapping("/api/joinTeam")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseEntity joinTeam(@RequestParam String token,
|
||||||
|
@RequestParam String teamID) {
|
||||||
|
// 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();
|
||||||
|
|
||||||
|
//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();
|
||||||
|
//----------------------
|
||||||
|
if (user_info.getTeam() != null) {
|
||||||
|
return ResponseEntity.status(400).body("You already have a team");
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get team
|
||||||
|
ResponseEntity getTeam = FinderUtil.findTeamById(teamID);
|
||||||
|
|
||||||
|
if (getTeam.getStatusCodeValue() != 200) {
|
||||||
|
return getTeam;
|
||||||
|
}
|
||||||
|
|
||||||
|
Team team = (Team) getTeam.getBody();
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
// zählt teammitglieder
|
||||||
|
for (User_Info userInfo1 : user_infoRepository.findAll()) {
|
||||||
|
if (userInfo1.getTeam().equals(team)) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// wenn maximalanzahl der teammitglieder erreicht...
|
||||||
|
if (i >= 10) {
|
||||||
|
return ResponseEntity.status(400).body("The team already has 10 members");
|
||||||
|
}
|
||||||
|
|
||||||
|
// tritt dem team bei
|
||||||
|
user_info.setTeam(team);
|
||||||
|
|
||||||
|
user_infoRepository.save(user_info);
|
||||||
|
|
||||||
|
return ResponseEntity.status(200).body(team);
|
||||||
|
}
|
||||||
|
|
||||||
|
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||||
|
@RequestMapping("/api/leaveTeam")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseEntity leaveTeam(@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();
|
||||||
|
|
||||||
|
//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();
|
||||||
|
//----------------------
|
||||||
|
if (user_info.getTeam() == null) {
|
||||||
|
return ResponseEntity.status(400).body("You aren´t in any team");
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get team
|
||||||
|
ResponseEntity getTeam = FinderUtil.findTeamById(String.valueOf(user_info.getTeam().getId()));
|
||||||
|
|
||||||
|
if (getTeam.getStatusCodeValue() != 200) {
|
||||||
|
return getTeam;
|
||||||
|
}
|
||||||
|
|
||||||
|
Team team = (Team) getTeam.getBody();
|
||||||
|
|
||||||
|
// verlässt team
|
||||||
|
user_info.setTeam(null);
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
// zählt teammitglieder
|
||||||
|
for (User_Info userInfo1 : user_infoRepository.findAll()) {
|
||||||
|
if (userInfo1.getTeam().equals(team)) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// löscht team, wenn keine teammitglieder mehr vorhanden
|
||||||
|
if (i == 0) {
|
||||||
|
teamRepository.delete(team);
|
||||||
|
}
|
||||||
|
|
||||||
|
user_infoRepository.save(user_info);
|
||||||
|
|
||||||
|
return ResponseEntity.status(200).body("Ok");
|
||||||
|
}
|
||||||
|
|
||||||
@RequestMapping("/api/hello")
|
@RequestMapping("/api/hello")
|
||||||
public ResponseEntity hello(@RequestParam String name) {
|
public ResponseEntity hello(@RequestParam String name) {
|
||||||
return ResponseEntity.status(200).body(userRepository.getRankingPlaceFromUser(name));
|
return ResponseEntity.status(200).body(userRepository.getRankingPlaceFromUser(name));
|
||||||
|
|||||||
@ -13,7 +13,6 @@ public class Team {
|
|||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private int rankingPoints;
|
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
@ -30,12 +29,4 @@ public class Team {
|
|||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRankingPoints() {
|
|
||||||
return rankingPoints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRankingPoints(int rankingPoints) {
|
|
||||||
this.rankingPoints = rankingPoints;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,11 +3,11 @@ package hhn.labsw.bugageocaching.helper;
|
|||||||
public class RankingListHelper {
|
public class RankingListHelper {
|
||||||
|
|
||||||
private String username;
|
private String username;
|
||||||
private int ranking_Points;
|
private int rankingPointsSum;
|
||||||
|
|
||||||
public RankingListHelper(String username, int ranking_Points) {
|
public RankingListHelper(String username, int ranking_Points) {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.ranking_Points = ranking_Points;
|
this.rankingPointsSum = ranking_Points;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
@ -19,10 +19,15 @@ public class RankingListHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getRanking_Points() {
|
public int getRanking_Points() {
|
||||||
return ranking_Points;
|
return rankingPointsSum;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRanking_Points(int ranking_Points) {
|
public void setRanking_Points(int ranking_Points) {
|
||||||
this.ranking_Points = ranking_Points;
|
this.rankingPointsSum = ranking_Points;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "( " + username + " | " + rankingPointsSum + " )";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,34 @@
|
|||||||
|
package hhn.labsw.bugageocaching.helper;
|
||||||
|
|
||||||
|
public class TeamRankingListHelper {
|
||||||
|
|
||||||
|
private String teamname;
|
||||||
|
private int rankingPointsSum;
|
||||||
|
|
||||||
|
public TeamRankingListHelper(String teamname, int ranking_Points) {
|
||||||
|
this.teamname = teamname;
|
||||||
|
this.rankingPointsSum = ranking_Points;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTeamname() {
|
||||||
|
return teamname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTeamname(String teamname) {
|
||||||
|
this.teamname = teamname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRanking_Points() {
|
||||||
|
return rankingPointsSum;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRanking_Points(int ranking_Points) {
|
||||||
|
this.rankingPointsSum = ranking_Points;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "( " + teamname + " | " + rankingPointsSum + " )";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -16,7 +16,7 @@ public interface UserRepository extends CrudRepository<User, Integer> {
|
|||||||
"WHERE u.id = ui.user_id\n" +
|
"WHERE u.id = ui.user_id\n" +
|
||||||
"AND u.id = ur.user_id\n" +
|
"AND u.id = ur.user_id\n" +
|
||||||
"order by ranking_points_sum DESC\n" +
|
"order by ranking_points_sum DESC\n" +
|
||||||
"LIMIT 100;", nativeQuery = true)
|
"LIMIT 10;", nativeQuery = true)
|
||||||
List<Object[]> getRankingList();
|
List<Object[]> getRankingList();
|
||||||
|
|
||||||
@Query(value = "SELECT Rang\n" +
|
@Query(value = "SELECT Rang\n" +
|
||||||
@ -35,4 +35,18 @@ public interface UserRepository extends CrudRepository<User, Integer> {
|
|||||||
"WHERE Name = ?1", nativeQuery = true)
|
"WHERE Name = ?1", nativeQuery = true)
|
||||||
int getRankingPlaceFromUser(String username);
|
int getRankingPlaceFromUser(String username);
|
||||||
|
|
||||||
|
@Query(value = "SELECT DISTINCT t.name AS teamname, SUM(ui.ranking_points_sum) AS Ranglistenpunkte\n" +
|
||||||
|
"FROM user u,\n" +
|
||||||
|
" user_info ui,\n" +
|
||||||
|
" user_roles ur,\n" +
|
||||||
|
" team t\n" +
|
||||||
|
"WHERE u.id = ui.user_id\n" +
|
||||||
|
" AND u.id = ur.user_id\n" +
|
||||||
|
" AND t.id = ui.team_id\n" +
|
||||||
|
" AND ui.team_id IS NOT NULL\n" +
|
||||||
|
"GROUP BY teamname\n" +
|
||||||
|
"ORDER by ranking_points_sum DESC" +
|
||||||
|
"LIMIT 10;", nativeQuery = true)
|
||||||
|
List<Object[]> getTeamRankingList();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -152,4 +152,13 @@ public class FinderUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ResponseEntity findTeamById(String teamID) {
|
||||||
|
Optional<Team> teamOptional = teamRepository.findById(Integer.valueOf(teamID));
|
||||||
|
if (teamOptional.isPresent()) {
|
||||||
|
return ResponseEntity.status(200).body(teamOptional.get());
|
||||||
|
} else {
|
||||||
|
return ResponseEntity.status(404).body("Couldnt find User_Info " + teamID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user