Adding get guilds

This commit is contained in:
Sebastien 2018-04-26 12:01:47 +02:00
parent cd511e5eea
commit 8d33c41847
3 changed files with 45 additions and 15 deletions

View File

@ -0,0 +1,11 @@
package net.Broken.RestApi.Data.UserManager;
public class GuildInfo {
public String name;
public String id;
public GuildInfo(String name, String id) {
this.name = name;
this.id = id;
}
}

View File

@ -46,7 +46,7 @@ public class MusicWebAPIController {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST); return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
} }
else{ else{
logger.info("currentMusicInfo for " + guild.getName()); logger.trace("currentMusicInfo for " + guild.getName());
} }
Music musicCommande = (Music) MainBot.commandes.get("music"); Music musicCommande = (Music) MainBot.commandes.get("music");
@ -74,7 +74,7 @@ public class MusicWebAPIController {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST); return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
} }
else{ else{
logger.info("getPlaylist for " + guild.getName()); logger.trace("getPlaylist for " + guild.getName());
} }
List<UserAudioTrackData> list = null; List<UserAudioTrackData> list = null;
@ -82,6 +82,7 @@ public class MusicWebAPIController {
return new ResponseEntity<>(new PlaylistData(list), HttpStatus.OK); return new ResponseEntity<>(new PlaylistData(list), HttpStatus.OK);
} }
// TODO change token to cookie
@RequestMapping(value = "/command", method = RequestMethod.POST) @RequestMapping(value = "/command", method = RequestMethod.POST)
public ResponseEntity<CommandResponseData> command(@RequestBody CommandPostData data, HttpServletRequest request, @RequestParam(value = "guild") String guildId){ public ResponseEntity<CommandResponseData> command(@RequestBody CommandPostData data, HttpServletRequest request, @RequestParam(value = "guild") String guildId){
@ -128,7 +129,7 @@ public class MusicWebAPIController {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST); return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
} }
else{ else{
logger.info("getPlaylist for " + guild.getName()); logger.trace("getPlaylist for " + guild.getName());
} }
List<ChanelData> temp = new ArrayList<>(); List<ChanelData> temp = new ArrayList<>();
for(VoiceChannel aChanel : FindGeneral.find(guild).getVoiceChannels()){ for(VoiceChannel aChanel : FindGeneral.find(guild).getVoiceChannels()){

View File

@ -4,25 +4,22 @@ import net.Broken.DB.Entity.PendingUserEntity;
import net.Broken.DB.Entity.UserEntity; import net.Broken.DB.Entity.UserEntity;
import net.Broken.DB.Repository.PendingUserRepository; import net.Broken.DB.Repository.PendingUserRepository;
import net.Broken.DB.Repository.UserRepository; import net.Broken.DB.Repository.UserRepository;
import net.Broken.RestApi.Data.UserManager.CheckResposeData; import net.Broken.MainBot;
import net.Broken.RestApi.Data.UserManager.ConfirmData; import net.Broken.RestApi.Data.UserManager.*;
import net.Broken.RestApi.Data.UserManager.UserConnectionData; import net.Broken.Tools.UserManager.Exceptions.*;
import net.Broken.RestApi.Data.UserManager.UserInfoData;
import net.Broken.Tools.UserManager.Exceptions.PasswordNotMatchException;
import net.Broken.Tools.UserManager.Exceptions.TokenNotMatch;
import net.Broken.Tools.UserManager.Exceptions.UserAlreadyRegistered;
import net.Broken.Tools.UserManager.Exceptions.UserNotFoundException;
import net.Broken.Tools.UserManager.UserUtils; import net.Broken.Tools.UserManager.UserUtils;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.User;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import java.util.ArrayList;
import org.springframework.web.bind.annotation.RestController; import java.util.List;
/** /**
@ -97,5 +94,26 @@ public class UserManagerAPIController {
} }
} }
@RequestMapping(value = "/getGuilds", method = RequestMethod.GET)
public ResponseEntity<List<GuildInfo>> getGuilds(@CookieValue("token") String token){
logger.debug(token);
try {
UserEntity userE = userUtils.getUserWithApiToken(userRepository, token);
User user = MainBot.jda.getUserById(userE.getJdaId());
List<GuildInfo> temp = new ArrayList<>();
for (Guild guild : user.getMutualGuilds()){
temp.add(new GuildInfo(guild.getName(), guild.getId()));
}
return new ResponseEntity<>(temp, HttpStatus.OK);
} catch (UnknownTokenException e) {
logger.catching(e);
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
}
}
} }