🔨 Add setting description endpoint

This commit is contained in:
SebClem 2022-06-10 17:24:20 +02:00
parent 3f5225bef1
commit 2cd22ab2db
Signed by: sebclem
GPG Key ID: 5A4308F6A359EA50
4 changed files with 170 additions and 0 deletions

View File

@ -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<SettingGroup> getSettingDescription(){
return settingService.getSettingDescription();
}
}

View File

@ -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
}
}

View File

@ -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<SettingDescriber> fields
) {
}

View File

@ -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<SettingGroup> getSettingDescription() {
List<SettingGroup> 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<SettingDescriber> 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<SettingDescriber> 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<SettingDescriber> 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<SettingDescriber> 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);
}
}