From 2cd22ab2db21f286632bdda175941c639798ae13 Mon Sep 17 00:00:00 2001 From: SebClem Date: Fri, 10 Jun 2022 17:24:20 +0200 Subject: [PATCH] :hammer: Add setting description endpoint --- .../Api/Controllers/SettingController.java | 26 ++++ .../Api/Data/Settings/SettingDescriber.java | 16 +++ .../Api/Data/Settings/SettingGroup.java | 13 ++ .../Broken/Api/Services/SettingService.java | 115 ++++++++++++++++++ 4 files changed, 170 insertions(+) create mode 100644 src/main/java/net/Broken/Api/Controllers/SettingController.java create mode 100644 src/main/java/net/Broken/Api/Data/Settings/SettingDescriber.java create mode 100644 src/main/java/net/Broken/Api/Data/Settings/SettingGroup.java create mode 100644 src/main/java/net/Broken/Api/Services/SettingService.java diff --git a/src/main/java/net/Broken/Api/Controllers/SettingController.java b/src/main/java/net/Broken/Api/Controllers/SettingController.java new file mode 100644 index 0000000..10e5360 --- /dev/null +++ b/src/main/java/net/Broken/Api/Controllers/SettingController.java @@ -0,0 +1,26 @@ +package net.Broken.Api.Controllers; + +import net.Broken.Api.Data.Settings.SettingGroup; +import net.Broken.Api.Services.SettingService; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping("/api/v2/setting") +@CrossOrigin(origins = "*", maxAge = 3600) +public class SettingController { + public final SettingService settingService; + + public SettingController(SettingService settingService) { + this.settingService = settingService; + } + + @GetMapping("description") + public List getSettingDescription(){ + return settingService.getSettingDescription(); + } +} diff --git a/src/main/java/net/Broken/Api/Data/Settings/SettingDescriber.java b/src/main/java/net/Broken/Api/Data/Settings/SettingDescriber.java new file mode 100644 index 0000000..16dc5f8 --- /dev/null +++ b/src/main/java/net/Broken/Api/Data/Settings/SettingDescriber.java @@ -0,0 +1,16 @@ +package net.Broken.Api.Data.Settings; + +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public record SettingDescriber( + String id, + String name, + String description, + TYPE type +) { + + public enum TYPE { + BOOL, LIST, STRING, ROLE, TEXT_CHANNEL, VOICE_CHANNEL + } +} diff --git a/src/main/java/net/Broken/Api/Data/Settings/SettingGroup.java b/src/main/java/net/Broken/Api/Data/Settings/SettingGroup.java new file mode 100644 index 0000000..a10180a --- /dev/null +++ b/src/main/java/net/Broken/Api/Data/Settings/SettingGroup.java @@ -0,0 +1,13 @@ +package net.Broken.Api.Data.Settings; + +import com.fasterxml.jackson.annotation.JsonInclude; + +import java.util.List; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public record SettingGroup( + String name, + SettingDescriber mainField, + List fields +) { +} diff --git a/src/main/java/net/Broken/Api/Services/SettingService.java b/src/main/java/net/Broken/Api/Services/SettingService.java new file mode 100644 index 0000000..fc00ac9 --- /dev/null +++ b/src/main/java/net/Broken/Api/Services/SettingService.java @@ -0,0 +1,115 @@ +package net.Broken.Api.Services; + +import net.Broken.Api.Data.Settings.SettingDescriber; +import net.Broken.Api.Data.Settings.SettingGroup; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class SettingService { + + public List getSettingDescription() { + List toReturn = new ArrayList<>(); + toReturn.add(getWelcomeGroup()); + toReturn.add(getDefaultRoleGroup()); + toReturn.add(getDailyGroup()); + toReturn.add(getAutoVoiceChannelGroup()); + return toReturn; + } + + private SettingGroup getWelcomeGroup() { + SettingDescriber mainField = new SettingDescriber( + "welcome_enable", + "Enable Welcome Message", + null, + SettingDescriber.TYPE.BOOL + ); + + List fields = new ArrayList<>(); + fields.add(new SettingDescriber( + "welcome_chanel_id", + "Welcome Message chanel", + null, + SettingDescriber.TYPE.TEXT_CHANNEL + )); + fields.add(new SettingDescriber( + "welcome_message", + "Welcome Message", + null, + SettingDescriber.TYPE.STRING + )); + + + return new SettingGroup( + "Welcome Message", + mainField, + fields); + } + + private SettingGroup getDefaultRoleGroup() { + SettingDescriber mainField = new SettingDescriber( + "default_role", + "Enable Default Role", + null, + SettingDescriber.TYPE.BOOL + ); + + List fields = new ArrayList<>(); + fields.add(new SettingDescriber( + "default_role_id", + "Default Role", + null, + SettingDescriber.TYPE.ROLE + )); + + return new SettingGroup( + "Default Role", + mainField, + fields); + } + + private SettingGroup getDailyGroup() { + List fields = new ArrayList<>(); + fields.add(new SettingDescriber( + "daily_madame", + "[NSFW] Enable Daily Madame Message", + null, + SettingDescriber.TYPE.BOOL + )); + + return new SettingGroup( + "Daily", + null, + fields); + } + + private SettingGroup getAutoVoiceChannelGroup() { + SettingDescriber mainField = new SettingDescriber( + "auto_voice", + "Enable Auto Create Voice Chanel", + "Auto create voice channel on join.", + SettingDescriber.TYPE.BOOL + ); + + List fields = new ArrayList<>(); + fields.add(new SettingDescriber( + "auto_voice_base_channel", + "Base Voice Channel For Auto Create", + "If someone joint this channel, a new voice channel will be created with the same settings.", + SettingDescriber.TYPE.VOICE_CHANNEL + )); + fields.add(new SettingDescriber( + "auto_voice_channel_title", + "Auto Created Voice Channel title", + "Auto created voice channel will use this title, @count will be replaced by the channel count.", + SettingDescriber.TYPE.VOICE_CHANNEL + )); + + return new SettingGroup( + "Auto Voice Channel", + mainField, + fields); + } +}