added joinTeam
This commit is contained in:
parent
a8b0b1bbb4
commit
b10226b5b9
@ -473,6 +473,54 @@ public class Controller {
|
|||||||
return ResponseEntity.status(200).body(new Gson().toJson(team));
|
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) {
|
||||||
|
ResponseEntity verifyToken = VerificationUtil.verifyToken(token);
|
||||||
|
|
||||||
|
if (verifyToken.getStatusCodeValue() != 200) {
|
||||||
|
return verifyToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
user_info.setTeam(team);
|
||||||
|
|
||||||
|
return ResponseEntity.status(200).body(team);
|
||||||
|
}
|
||||||
|
|
||||||
@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));
|
||||||
|
|||||||
@ -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