added createTeam
This commit is contained in:
parent
479173de84
commit
a8b0b1bbb4
@ -48,7 +48,6 @@ public class Controller {
|
||||
@Autowired
|
||||
User_InfoRepository user_infoRepository;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
fetchPublicKey();
|
||||
@ -424,6 +423,56 @@ 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) {
|
||||
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");
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@RequestMapping("/api/hello")
|
||||
public ResponseEntity hello(@RequestParam String name) {
|
||||
return ResponseEntity.status(200).body(userRepository.getRankingPlaceFromUser(name));
|
||||
|
||||
@ -13,7 +13,6 @@ public class Team {
|
||||
private int id;
|
||||
|
||||
private String name;
|
||||
private int rankingPoints;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
@ -30,12 +29,4 @@ public class Team {
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getRankingPoints() {
|
||||
return rankingPoints;
|
||||
}
|
||||
|
||||
public void setRankingPoints(int rankingPoints) {
|
||||
this.rankingPoints = rankingPoints;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user