fixed merge conflicts
This commit is contained in:
commit
30d90b2a21
@ -49,6 +49,9 @@ public class Controller {
|
||||
@Autowired
|
||||
User_InfoRepository user_infoRepository;
|
||||
|
||||
@Autowired
|
||||
TeamInviteRepository teamInviteRepository;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
fetchPublicKey();
|
||||
@ -557,7 +560,7 @@ public class Controller {
|
||||
|
||||
user_infoRepository.save(user_info);
|
||||
|
||||
return ResponseEntity.status(200).body(team);
|
||||
return ResponseEntity.status(200).body(new Gson().toJson(team));
|
||||
}
|
||||
|
||||
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||
@ -627,8 +630,197 @@ public class Controller {
|
||||
}
|
||||
|
||||
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||
@RequestMapping("/api/hello")
|
||||
@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
|
||||
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();
|
||||
|
||||
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
|
||||
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();
|
||||
team.setTeamStatus(teamStatus);
|
||||
|
||||
teamRepository.save(team);
|
||||
|
||||
return ResponseEntity.status(200).body(new Gson().toJson(teamStatus));
|
||||
}
|
||||
|
||||
@RequestMapping("/api/getTeam")
|
||||
public ResponseEntity getTeam(@RequestParam String name){
|
||||
ResponseEntity responseEntity = FinderUtil.findTeamByName(name);
|
||||
|
||||
return responseEntity;
|
||||
}
|
||||
|
||||
@RequestMapping("/api/getTeamMembers")
|
||||
public ResponseEntity getTeamMembers(@RequestParam String name){
|
||||
return FinderUtil.findTeammemberByTeamName(name);
|
||||
}
|
||||
|
||||
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||
@RequestMapping("/api/hello")
|
||||
public ResponseEntity hello(@RequestParam String name) {
|
||||
return ResponseEntity.status(200).body(userRepository.getRankingPlaceFromUser(name));
|
||||
}
|
||||
|
||||
@ -14,6 +14,8 @@ public class Team {
|
||||
|
||||
private String name;
|
||||
|
||||
private String teamStatus;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
@ -29,4 +31,12 @@ public class Team {
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getTeamStatus() {
|
||||
return teamStatus;
|
||||
}
|
||||
|
||||
public void setTeamStatus(String teamStatus) {
|
||||
this.teamStatus = teamStatus;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,42 @@
|
||||
package hhn.labsw.bugageocaching.entities;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table
|
||||
public class TeamInvite {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private int id;
|
||||
|
||||
@OneToOne
|
||||
private User user;
|
||||
|
||||
@OneToOne
|
||||
private Team team;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public Team getTeam() {
|
||||
return team;
|
||||
}
|
||||
|
||||
public void setTeam(Team team) {
|
||||
this.team = team;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package hhn.labsw.bugageocaching.repositories;
|
||||
|
||||
import hhn.labsw.bugageocaching.entities.Cache;
|
||||
import hhn.labsw.bugageocaching.entities.Team;
|
||||
import hhn.labsw.bugageocaching.entities.TeamInvite;
|
||||
import hhn.labsw.bugageocaching.entities.User;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface TeamInviteRepository extends JpaRepository<TeamInvite, Integer> {
|
||||
TeamInvite findByUserAndTeam(User user, Team team);
|
||||
}
|
||||
@ -1,8 +1,28 @@
|
||||
package hhn.labsw.bugageocaching.repositories;
|
||||
|
||||
import hhn.labsw.bugageocaching.entities.Team;
|
||||
import hhn.labsw.bugageocaching.entities.User;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TeamRepository extends JpaRepository<Team, Integer> {
|
||||
|
||||
Team findByName(String name);
|
||||
|
||||
@Query(value = "SELECT *\n" +
|
||||
"FROM user\n" +
|
||||
"WHERE id = (\n" +
|
||||
" SELECT user_id\n" +
|
||||
" FROM user_info\n" +
|
||||
" WHERE team_id = (SELECT team_id\n" +
|
||||
" FROM team\n" +
|
||||
" WHERE name = ?1\n" +
|
||||
" )\n" +
|
||||
")", nativeQuery = true)
|
||||
List<Object[]> getTeammembers(String name);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ import org.springframework.data.repository.CrudRepository;
|
||||
import java.util.List;
|
||||
|
||||
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" +
|
||||
"FROM user u,\n" +
|
||||
|
||||
@ -10,6 +10,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@ -31,47 +33,7 @@ public class FinderUtil {
|
||||
|
||||
static User_InfoRepository user_infoRepository;
|
||||
|
||||
|
||||
@Autowired
|
||||
public void setCacheRepository(CacheRepository cacheRepository) {
|
||||
FinderUtil.cacheRepository= cacheRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setRewardRepository(RewardRepository rewardRepository) {
|
||||
FinderUtil.rewardRepository = rewardRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setStationRepository(StationRepository stationRepository) {
|
||||
FinderUtil.stationRepository = stationRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setBearbeitetRepository(BearbeitetRepository bearbeitetRepository) {
|
||||
FinderUtil.bearbeitetRepository = bearbeitetRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setCacheAccesDefinitionRepository(CacheAccesDefinitionRepository cacheAccesDefinitionRepository) {
|
||||
FinderUtil.cacheAccesDefinitionRepository = cacheAccesDefinitionRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTeamRepository(TeamRepository teamRepository) {
|
||||
FinderUtil.teamRepository = teamRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setUserRepository(UserRepository userRepository) {
|
||||
FinderUtil.userRepository = userRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setUser_infoRepository(User_InfoRepository user_infoRepository) {
|
||||
FinderUtil.user_infoRepository = user_infoRepository;
|
||||
}
|
||||
|
||||
static TeamInviteRepository teamInviteRepository;
|
||||
|
||||
public static ResponseEntity findCacheById(String cacheID) {
|
||||
|
||||
@ -104,16 +66,6 @@ public class FinderUtil {
|
||||
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) {
|
||||
Optional<CacheAccesDefinition> cacheAccesDefinitionOptional = cacheAccesDefinitionRepository.findById(Integer.valueOf(cacheAccesDefinitionID));
|
||||
if (cacheAccesDefinitionOptional.isPresent()) {
|
||||
@ -161,4 +113,88 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
public static ResponseEntity findTeamByName(String name) {
|
||||
|
||||
Team team = teamRepository.findByName(name);
|
||||
if (team != null) {
|
||||
return ResponseEntity.status(200).body(team);
|
||||
} else {
|
||||
return ResponseEntity.status(404).body("Couldnt find Team with name " + name);
|
||||
}
|
||||
}
|
||||
|
||||
public static ResponseEntity findTeammemberByTeamName(String name) {
|
||||
|
||||
List<Object[]> list = teamRepository.getTeammembers(name);
|
||||
if (list != null) {
|
||||
|
||||
List<User> sendBack = new LinkedList<>();
|
||||
|
||||
for (Object[] obj :
|
||||
list) {
|
||||
User tmp = new User();
|
||||
tmp.setUsername((String) obj[3]);
|
||||
sendBack.add(tmp);
|
||||
}
|
||||
|
||||
return ResponseEntity.status(200).body(sendBack);
|
||||
} else {
|
||||
return ResponseEntity.status(404).body("Couldnt find Team member of Team " + name);
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setCacheRepository(CacheRepository cacheRepository) {
|
||||
FinderUtil.cacheRepository = cacheRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setRewardRepository(RewardRepository rewardRepository) {
|
||||
FinderUtil.rewardRepository = rewardRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setStationRepository(StationRepository stationRepository) {
|
||||
FinderUtil.stationRepository = stationRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setBearbeitetRepository(BearbeitetRepository bearbeitetRepository) {
|
||||
FinderUtil.bearbeitetRepository = bearbeitetRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setCacheAccesDefinitionRepository(CacheAccesDefinitionRepository cacheAccesDefinitionRepository) {
|
||||
FinderUtil.cacheAccesDefinitionRepository = cacheAccesDefinitionRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTeamRepository(TeamRepository teamRepository) {
|
||||
FinderUtil.teamRepository = teamRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setUserRepository(UserRepository userRepository) {
|
||||
FinderUtil.userRepository = userRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setUser_infoRepository(User_InfoRepository user_infoRepository) {
|
||||
FinderUtil.user_infoRepository = user_infoRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setTeamInviteRepository(TeamInviteRepository teamInviteRepository) {
|
||||
FinderUtil.teamInviteRepository = teamInviteRepository;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user