improved sendTeamInvite
This commit is contained in:
parent
06e2b54aef
commit
80510eb467
@ -685,6 +685,10 @@ public class Controller {
|
|||||||
|
|
||||||
Team team = (Team) getTeam.getBody();
|
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 teamInvite = new TeamInvite();
|
||||||
teamInvite.setUser(invitedUser);
|
teamInvite.setUser(invitedUser);
|
||||||
teamInvite.setTeam(team);
|
teamInvite.setTeam(team);
|
||||||
@ -718,8 +722,8 @@ public class Controller {
|
|||||||
|
|
||||||
List<TeamInvite> teamInvitesList = new ArrayList<>();
|
List<TeamInvite> teamInvitesList = new ArrayList<>();
|
||||||
|
|
||||||
for(TeamInvite teamInvite : teamInviteRepository.findAll()) {
|
for (TeamInvite teamInvite : teamInviteRepository.findAll()) {
|
||||||
if(teamInvite.getUser() == user) {
|
if (teamInvite.getUser() == user) {
|
||||||
teamInvitesList.add(teamInvite);
|
teamInvitesList.add(teamInvite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -727,6 +731,30 @@ public class Controller {
|
|||||||
return ResponseEntity.status(200).body(teamInvitesList);
|
return ResponseEntity.status(200).body(teamInvitesList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||||
|
@RequestMapping("/api/deleteTeamInvite")
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseEntity deleteTeamInvite(@RequestParam String token,
|
||||||
|
@RequestParam ) {
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
|
|
||||||
@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));
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
package hhn.labsw.bugageocaching.repositories;
|
package hhn.labsw.bugageocaching.repositories;
|
||||||
|
|
||||||
import hhn.labsw.bugageocaching.entities.Cache;
|
import hhn.labsw.bugageocaching.entities.Cache;
|
||||||
|
import hhn.labsw.bugageocaching.entities.Team;
|
||||||
import hhn.labsw.bugageocaching.entities.TeamInvite;
|
import hhn.labsw.bugageocaching.entities.TeamInvite;
|
||||||
import hhn.labsw.bugageocaching.entities.User;
|
import hhn.labsw.bugageocaching.entities.User;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
public interface TeamInviteRepository extends JpaRepository<TeamInvite, Integer> {
|
public interface TeamInviteRepository extends JpaRepository<TeamInvite, Integer> {
|
||||||
|
TeamInvite findByUserAndTeam(User user, Team team);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user