added deleteTeamInvite API method

This commit is contained in:
Michael 2019-04-29 11:02:43 +02:00
parent 80510eb467
commit ac15616e22
2 changed files with 27 additions and 9 deletions

View File

@ -685,7 +685,7 @@ public class Controller {
Team team = (Team) getTeam.getBody();
if(teamInviteRepository.findByUserAndTeam(invitedUser, team) != null) {
if (teamInviteRepository.findByUserAndTeam(invitedUser, team) != null) {
return ResponseEntity.status(400).body("The user is already invited to this team");
}
@ -735,7 +735,7 @@ public class Controller {
@RequestMapping("/api/deleteTeamInvite")
@ResponseBody
public ResponseEntity deleteTeamInvite(@RequestParam String token,
@RequestParam ) {
@RequestParam String teamInviteID) {
// verify user
ResponseEntity verifyToken = VerificationUtil.verifyToken(token);
@ -743,16 +743,18 @@ public class Controller {
return verifyToken;
}
//get User
Claims claims = (Claims) verifyToken.getBody();
// get teaminvite
ResponseEntity getTeamInvite = FinderUtil.findTeamInviteByID(teamInviteID);
ResponseEntity getUser = FinderUtil.findUserFromClaim(claims);
if (getUser.getStatusCodeValue() != 200) {
return getUser;
if (getTeamInvite.getStatusCodeValue() != 200) {
return getTeamInvite;
}
User user = (User) getUser.getBody();
TeamInvite teamInvite = (TeamInvite) getTeamInvite.getBody();
teamInviteRepository.delete(teamInvite);
return ResponseEntity.status(200).body("OK");
}
@RequestMapping("/api/hello")

View File

@ -31,6 +31,8 @@ public class FinderUtil {
static User_InfoRepository user_infoRepository;
static TeamInviteRepository teamInviteRepository;
@Autowired
public void setCacheRepository(CacheRepository cacheRepository) {
@ -72,6 +74,11 @@ public class FinderUtil {
FinderUtil.user_infoRepository = user_infoRepository;
}
@Autowired
public void setTeamInviteRepository(TeamInviteRepository teamInviteRepository) {
FinderUtil.teamInviteRepository = teamInviteRepository;
}
public static ResponseEntity findCacheById(String cacheID) {
@ -161,4 +168,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);
}
}
}