🔨 Add getRole endpoint

This commit is contained in:
SebClem 2022-06-10 21:25:12 +02:00
parent 2cd22ab2db
commit 0255cac542
Signed by: sebclem
GPG Key ID: 5A4308F6A359EA50
5 changed files with 29 additions and 8 deletions

View File

@ -1,8 +1,9 @@
package net.Broken.Api.Controllers; package net.Broken.Api.Controllers;
import net.Broken.Api.Data.Guild; import net.Broken.Api.Data.Guild.Guild;
import net.Broken.Api.Data.Guild.Role;
import net.Broken.Api.Data.InviteLink; import net.Broken.Api.Data.InviteLink;
import net.Broken.Api.Data.Channel; import net.Broken.Api.Data.Guild.Channel;
import net.Broken.Api.Security.Data.JwtPrincipal; import net.Broken.Api.Security.Data.JwtPrincipal;
import net.Broken.Api.Services.GuildService; import net.Broken.Api.Services.GuildService;
import net.Broken.MainBot; import net.Broken.MainBot;
@ -40,12 +41,18 @@ public class GuildController {
@GetMapping("/{guildId}/voiceChannels") @GetMapping("/{guildId}/voiceChannels")
@PreAuthorize("isInGuild(#guildId)") @PreAuthorize("isInGuild(#guildId)")
public List<Channel> getVoiceChannels(@PathVariable String guildId){ public List<Channel> getVoiceChannels(@PathVariable String guildId){
return guildService.getVoiceChannel(String.valueOf(guildId)); return guildService.getVoiceChannel(guildId);
} }
@GetMapping("/{guildId}/textChannels") @GetMapping("/{guildId}/textChannels")
@PreAuthorize("isInGuild(#guildId)") @PreAuthorize("isInGuild(#guildId)")
public List<Channel> getTextChannels(@PathVariable String guildId){ public List<Channel> getTextChannels(@PathVariable String guildId){
return guildService.getTextChannel(String.valueOf(guildId)); return guildService.getTextChannel(guildId);
}
@GetMapping("/{guildId}/roles")
@PreAuthorize("isInGuild(#guildId)")
public List<Role> getRoles(@PathVariable String guildId){
return guildService.getRole(guildId);
} }
} }

View File

@ -1,4 +1,4 @@
package net.Broken.Api.Data; package net.Broken.Api.Data.Guild;
public record Channel(String id, String name) { public record Channel(String id, String name) {
} }

View File

@ -1,4 +1,4 @@
package net.Broken.Api.Data; package net.Broken.Api.Data.Guild;
public record Guild(String id, String name, String iconUrl) { public record Guild(String id, String name, String iconUrl) {
} }

View File

@ -0,0 +1,4 @@
package net.Broken.Api.Data.Guild;
public record Role(String id, String name) {
}

View File

@ -1,7 +1,8 @@
package net.Broken.Api.Services; package net.Broken.Api.Services;
import net.Broken.Api.Data.Guild; import net.Broken.Api.Data.Guild.Guild;
import net.Broken.Api.Data.Channel; import net.Broken.Api.Data.Guild.Channel;
import net.Broken.Api.Data.Guild.Role;
import net.Broken.DB.Entity.UserEntity; import net.Broken.DB.Entity.UserEntity;
import net.Broken.MainBot; import net.Broken.MainBot;
import net.Broken.Tools.CacheTools; import net.Broken.Tools.CacheTools;
@ -43,4 +44,13 @@ public class GuildService {
return voiceChannels; return voiceChannels;
} }
public List<Role> getRole(String guildId){
net.dv8tion.jda.api.entities.Guild guild = MainBot.jda.getGuildById(guildId);
List<Role> roles = new ArrayList<>();
for(net.dv8tion.jda.api.entities.Role role : guild.getRoles()){
roles.add(new Role(role.getId(), role.getName()));
}
return roles;
}
} }