fixed previous merge conflict mistakes
This commit is contained in:
parent
ea006b3915
commit
800c9d96cd
@ -48,6 +48,9 @@ public class Controller {
|
|||||||
@Autowired
|
@Autowired
|
||||||
User_InfoRepository user_infoRepository;
|
User_InfoRepository user_infoRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
TeamInviteRepository teamInviteRepository;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
fetchPublicKey();
|
fetchPublicKey();
|
||||||
@ -543,7 +546,7 @@ public class Controller {
|
|||||||
|
|
||||||
user_infoRepository.save(user_info);
|
user_infoRepository.save(user_info);
|
||||||
|
|
||||||
return ResponseEntity.status(200).body(team);
|
return ResponseEntity.status(200).body(new Gson().toJson(team));
|
||||||
}
|
}
|
||||||
|
|
||||||
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
|
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
|
||||||
@ -606,6 +609,172 @@ public class Controller {
|
|||||||
return ResponseEntity.status(200).body("Ok");
|
return ResponseEntity.status(200).body("Ok");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||||
|
@RequestMapping("/api/sendTeamInvite")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseEntity sendTeamInvite(@RequestParam String token,
|
||||||
|
@RequestParam String invitedUserEmail) {
|
||||||
|
// 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 InvitedUser
|
||||||
|
|
||||||
|
User invitedUser = userRepository.findByEmail(invitedUserEmail);
|
||||||
|
|
||||||
|
if (invitedUser == null) {
|
||||||
|
return ResponseEntity.status(404).body("There isnt any user with that email");
|
||||||
|
}
|
||||||
|
//----------------------
|
||||||
|
|
||||||
|
|
||||||
|
//Get User_Info
|
||||||
|
User_Info user_info = user_infoRepository.findUser_InfoByUser(user);
|
||||||
|
//----------------------
|
||||||
|
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();
|
||||||
|
|
||||||
|
if (teamInviteRepository.findByUserAndTeam(invitedUser, team) != null) {
|
||||||
|
return ResponseEntity.status(400).body("The user is already invited to this team");
|
||||||
|
}
|
||||||
|
|
||||||
|
TeamInvite teamInvite = new TeamInvite();
|
||||||
|
teamInvite.setUser(invitedUser);
|
||||||
|
teamInvite.setTeam(team);
|
||||||
|
|
||||||
|
teamInviteRepository.save(teamInvite);
|
||||||
|
|
||||||
|
return ResponseEntity.status(200).body("OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||||
|
@RequestMapping("/api/getMyTeamInvites")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseEntity getMyTeamInvites(@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();
|
||||||
|
|
||||||
|
List<TeamInvite> teamInvitesList = new ArrayList<>();
|
||||||
|
|
||||||
|
for (TeamInvite teamInvite : teamInviteRepository.findAll()) {
|
||||||
|
if (teamInvite.getUser() == user) {
|
||||||
|
teamInvitesList.add(teamInvite);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResponseEntity.status(200).body(new Gson().toJson(teamInvitesList));
|
||||||
|
}
|
||||||
|
|
||||||
|
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||||
|
@RequestMapping("/api/deleteTeamInvite")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseEntity deleteTeamInvite(@RequestParam String token,
|
||||||
|
@RequestParam String teamInviteID) {
|
||||||
|
// verify user
|
||||||
|
ResponseEntity verifyToken = VerificationUtil.verifyToken(token);
|
||||||
|
|
||||||
|
if (verifyToken.getStatusCodeValue() != 200) {
|
||||||
|
return verifyToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get teaminvite
|
||||||
|
ResponseEntity getTeamInvite = FinderUtil.findTeamInviteByID(teamInviteID);
|
||||||
|
|
||||||
|
if (getTeamInvite.getStatusCodeValue() != 200) {
|
||||||
|
return getTeamInvite;
|
||||||
|
}
|
||||||
|
|
||||||
|
TeamInvite teamInvite = (TeamInvite) getTeamInvite.getBody();
|
||||||
|
|
||||||
|
teamInviteRepository.delete(teamInvite);
|
||||||
|
|
||||||
|
return ResponseEntity.status(200).body("OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||||
|
@RequestMapping("/api/setTeamStatus")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseEntity setTeamStatus(@RequestParam String token,
|
||||||
|
@RequestParam String teamStatus) {
|
||||||
|
// 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
|
||||||
|
User_Info user_info = user_infoRepository.findUser_InfoByUser(user);
|
||||||
|
//----------------------
|
||||||
|
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();
|
||||||
|
team.setTeamStatus(teamStatus);
|
||||||
|
|
||||||
|
teamRepository.save(team);
|
||||||
|
|
||||||
|
return ResponseEntity.status(200).body(new Gson().toJson(teamStatus));
|
||||||
|
}
|
||||||
|
|
||||||
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
|
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
|
||||||
@RequestMapping("/api/getCurrentStation")
|
@RequestMapping("/api/getCurrentStation")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import org.springframework.data.repository.CrudRepository;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface UserRepository extends CrudRepository<User, Integer> {
|
public interface UserRepository extends CrudRepository<User, Integer> {
|
||||||
User findByUsername(String username);
|
User findByEmail(String email);
|
||||||
|
|
||||||
@Query(value = "SELECT DISTINCT u.id AS ID, SUBSTRING_INDEX(u.email, '@', 1) AS Name, ui.ranking_points_sum AS Ranglistenpunkte\n" +
|
@Query(value = "SELECT DISTINCT u.id AS ID, SUBSTRING_INDEX(u.email, '@', 1) AS Name, ui.ranking_points_sum AS Ranglistenpunkte\n" +
|
||||||
"FROM user u,\n" +
|
"FROM user u,\n" +
|
||||||
|
|||||||
@ -32,6 +32,8 @@ public class FinderUtil {
|
|||||||
|
|
||||||
static User_InfoRepository user_infoRepository;
|
static User_InfoRepository user_infoRepository;
|
||||||
|
|
||||||
|
static TeamInviteRepository teamInviteRepository;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void setCacheRepository(CacheRepository cacheRepository) {
|
public void setCacheRepository(CacheRepository cacheRepository) {
|
||||||
@ -73,6 +75,11 @@ public class FinderUtil {
|
|||||||
FinderUtil.user_infoRepository = user_infoRepository;
|
FinderUtil.user_infoRepository = user_infoRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public void setTeamInviteRepository(TeamInviteRepository teamInviteRepository) {
|
||||||
|
FinderUtil.teamInviteRepository = teamInviteRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static ResponseEntity findCacheById(String cacheID) {
|
public static ResponseEntity findCacheById(String cacheID) {
|
||||||
|
|
||||||
@ -105,16 +112,6 @@ public class FinderUtil {
|
|||||||
return ResponseEntity.status(404).body("The user has not started this cache yet");
|
return ResponseEntity.status(404).body("The user has not started this cache yet");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResponseEntity findUserByUsername(String username) {
|
|
||||||
|
|
||||||
User user = userRepository.findByUsername(username);
|
|
||||||
if (user != null) {
|
|
||||||
return ResponseEntity.status(200).body(user);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ResponseEntity.status(404).body("Couldnt find user with username " + username);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ResponseEntity findCacheAccesDefinitionById(String cacheAccesDefinitionID) {
|
public static ResponseEntity findCacheAccesDefinitionById(String cacheAccesDefinitionID) {
|
||||||
Optional<CacheAccesDefinition> cacheAccesDefinitionOptional = cacheAccesDefinitionRepository.findById(Integer.valueOf(cacheAccesDefinitionID));
|
Optional<CacheAccesDefinition> cacheAccesDefinitionOptional = cacheAccesDefinitionRepository.findById(Integer.valueOf(cacheAccesDefinitionID));
|
||||||
if (cacheAccesDefinitionOptional.isPresent()) {
|
if (cacheAccesDefinitionOptional.isPresent()) {
|
||||||
@ -153,4 +150,13 @@ public class FinderUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ResponseEntity findTeamInviteByID(String teamInviteID) {
|
||||||
|
Optional<TeamInvite> teamInviteOptional = teamInviteRepository.findById(Integer.valueOf(teamInviteID));
|
||||||
|
if (teamInviteOptional.isPresent()) {
|
||||||
|
return ResponseEntity.status(200).body(teamInviteOptional.get());
|
||||||
|
} else {
|
||||||
|
return ResponseEntity.status(404).body("Couldnt find User_Info " + teamInviteID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user