From 0255cac5427057121216aee35075ec1387e69fd8 Mon Sep 17 00:00:00 2001 From: SebClem Date: Fri, 10 Jun 2022 21:25:12 +0200 Subject: [PATCH] :hammer: Add getRole endpoint --- .../Broken/Api/Controllers/GuildController.java | 15 +++++++++++---- .../net/Broken/Api/Data/{ => Guild}/Channel.java | 2 +- .../net/Broken/Api/Data/{ => Guild}/Guild.java | 2 +- src/main/java/net/Broken/Api/Data/Guild/Role.java | 4 ++++ .../net/Broken/Api/Services/GuildService.java | 14 ++++++++++++-- 5 files changed, 29 insertions(+), 8 deletions(-) rename src/main/java/net/Broken/Api/Data/{ => Guild}/Channel.java (59%) rename src/main/java/net/Broken/Api/Data/{ => Guild}/Guild.java (65%) create mode 100644 src/main/java/net/Broken/Api/Data/Guild/Role.java diff --git a/src/main/java/net/Broken/Api/Controllers/GuildController.java b/src/main/java/net/Broken/Api/Controllers/GuildController.java index 8e9e20b..20b49ad 100644 --- a/src/main/java/net/Broken/Api/Controllers/GuildController.java +++ b/src/main/java/net/Broken/Api/Controllers/GuildController.java @@ -1,8 +1,9 @@ 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.Channel; +import net.Broken.Api.Data.Guild.Channel; import net.Broken.Api.Security.Data.JwtPrincipal; import net.Broken.Api.Services.GuildService; import net.Broken.MainBot; @@ -40,12 +41,18 @@ public class GuildController { @GetMapping("/{guildId}/voiceChannels") @PreAuthorize("isInGuild(#guildId)") public List getVoiceChannels(@PathVariable String guildId){ - return guildService.getVoiceChannel(String.valueOf(guildId)); + return guildService.getVoiceChannel(guildId); } @GetMapping("/{guildId}/textChannels") @PreAuthorize("isInGuild(#guildId)") public List getTextChannels(@PathVariable String guildId){ - return guildService.getTextChannel(String.valueOf(guildId)); + return guildService.getTextChannel(guildId); + } + + @GetMapping("/{guildId}/roles") + @PreAuthorize("isInGuild(#guildId)") + public List getRoles(@PathVariable String guildId){ + return guildService.getRole(guildId); } } diff --git a/src/main/java/net/Broken/Api/Data/Channel.java b/src/main/java/net/Broken/Api/Data/Guild/Channel.java similarity index 59% rename from src/main/java/net/Broken/Api/Data/Channel.java rename to src/main/java/net/Broken/Api/Data/Guild/Channel.java index 69ac82d..557c2bb 100644 --- a/src/main/java/net/Broken/Api/Data/Channel.java +++ b/src/main/java/net/Broken/Api/Data/Guild/Channel.java @@ -1,4 +1,4 @@ -package net.Broken.Api.Data; +package net.Broken.Api.Data.Guild; public record Channel(String id, String name) { } diff --git a/src/main/java/net/Broken/Api/Data/Guild.java b/src/main/java/net/Broken/Api/Data/Guild/Guild.java similarity index 65% rename from src/main/java/net/Broken/Api/Data/Guild.java rename to src/main/java/net/Broken/Api/Data/Guild/Guild.java index c7cf482..c5c880d 100644 --- a/src/main/java/net/Broken/Api/Data/Guild.java +++ b/src/main/java/net/Broken/Api/Data/Guild/Guild.java @@ -1,4 +1,4 @@ -package net.Broken.Api.Data; +package net.Broken.Api.Data.Guild; public record Guild(String id, String name, String iconUrl) { } diff --git a/src/main/java/net/Broken/Api/Data/Guild/Role.java b/src/main/java/net/Broken/Api/Data/Guild/Role.java new file mode 100644 index 0000000..473eedd --- /dev/null +++ b/src/main/java/net/Broken/Api/Data/Guild/Role.java @@ -0,0 +1,4 @@ +package net.Broken.Api.Data.Guild; + +public record Role(String id, String name) { +} diff --git a/src/main/java/net/Broken/Api/Services/GuildService.java b/src/main/java/net/Broken/Api/Services/GuildService.java index d263044..ff0624a 100644 --- a/src/main/java/net/Broken/Api/Services/GuildService.java +++ b/src/main/java/net/Broken/Api/Services/GuildService.java @@ -1,7 +1,8 @@ package net.Broken.Api.Services; -import net.Broken.Api.Data.Guild; -import net.Broken.Api.Data.Channel; +import net.Broken.Api.Data.Guild.Guild; +import net.Broken.Api.Data.Guild.Channel; +import net.Broken.Api.Data.Guild.Role; import net.Broken.DB.Entity.UserEntity; import net.Broken.MainBot; import net.Broken.Tools.CacheTools; @@ -43,4 +44,13 @@ public class GuildService { return voiceChannels; } + public List getRole(String guildId){ + net.dv8tion.jda.api.entities.Guild guild = MainBot.jda.getGuildById(guildId); + List roles = new ArrayList<>(); + for(net.dv8tion.jda.api.entities.Role role : guild.getRoles()){ + roles.add(new Role(role.getId(), role.getName())); + } + return roles; + } + }