Skip to content

Commit

Permalink
Some missing documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
DxsSucuk committed Jun 7, 2023
1 parent 3c7efaa commit 96b0b5d
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* Controller for the Error Controller.
*/
@RestController
public class ErrorControllerImpl implements ErrorController {

/**
* Error Attributes in the Application
*/
Expand All @@ -25,13 +29,23 @@ public ErrorControllerImpl(ErrorAttributes errorAttributes) {
this.errorAttributes = errorAttributes;
}

/**
* Handle received Error.
* @param request Request that was sent.
* @return Generic Response with the Error Message.
*/
@RequestMapping(value = "/error", produces = MediaType.APPLICATION_JSON_VALUE)
public GenericResponse handleError(HttpServletRequest request) {
HttpStatus httpStatus = getStatus(request);

return new GenericResponse(false, httpStatus.getReasonPhrase());
}

/**
* Return the HTTP Status.
* @param request Request that was sent.
* @return HTTP Status.
*/
private HttpStatus getStatus(HttpServletRequest request) {
Integer statusCode = (Integer)request.getAttribute("jakarta.servlet.error.status_code");
if (statusCode == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,34 @@

import java.util.List;

/**
* Controller meant to handle Sessions.
*/
@RestController
@RequestMapping("/auth")
public class SessionController {

/**
* Session Service to handle Sessions.
*/
private final SessionService sessionService;

/**
* Controller for the Session Controller.
* @param sessionService Session Service to handle Sessions.
*/
@Autowired
public SessionController(SessionService sessionService) {
this.sessionService = sessionService;
}

//region Session Auth


/**
* Create a new Session.
* @param sessionIdentifier Session Identifier to identify the Session.
* @return Generic Object Response with the Session.
*/
@GetMapping(value = "/check", produces = MediaType.APPLICATION_JSON_VALUE)
public GenericObjectResponse<SessionContainer> checkSession(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier) {
try {
Expand All @@ -45,7 +59,12 @@ public GenericObjectResponse<SessionContainer> checkSession(@RequestHeader(name

//region Discord Auth


/**
* Create a new Session.
* @param code Code to create the Session.
* @param state State to create the Session.
* @return Generic Object Response with the Session.
*/
@GetMapping(value = "/discord", produces = MediaType.APPLICATION_JSON_VALUE)
public GenericObjectResponse<SessionContainer> completeSession(@RequestParam(name = "code") String code, @RequestParam(name = "state") String state) {
try {
Expand All @@ -55,7 +74,10 @@ public GenericObjectResponse<SessionContainer> completeSession(@RequestParam(nam
}
}


/**
* Create a new Session.
* @return Redirect View to the Discord OAuth2 Page.
*/
@GetMapping(value = "/discord/request")
public RedirectView createSession() {
return new RedirectView(Server.getInstance().getOAuth2Client().generateAuthorizationURL(
Expand All @@ -70,7 +92,11 @@ public RedirectView createSession() {

//region Twitch Auth


/**
* Create a new Twitch Session.
* @param sessionIdentifier Session Identifier to identify the Session.
* @return Generic Object Response with the Session.
*/
@GetMapping(value = "/twitch/request")
public RedirectView createTwitch(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier) {
try {
Expand All @@ -86,7 +112,12 @@ public RedirectView createTwitch(@RequestHeader(name = "X-Session-Authenticator"
}
}


/**
* Create a new Twitch Session.
* @param sessionIdentifier Session Identifier to identify the Session.
* @param code Code to create the Session.
* @return Generic Object Response with the Session.
*/
@GetMapping(value = "/twitch", produces = MediaType.APPLICATION_JSON_VALUE)
public GenericResponse authenticateTwitch(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @RequestParam(name = "code") String code) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,35 @@
import java.util.Collections;
import java.util.List;

/**
* Controller meant to handle Settings.
*/
@RestController
@RequestMapping("/settings/{guildId}")
public class SettingsController {

/**
* Session Service to handle Sessions.
*/
private final SessionService sessionService;

/**
* Controller for the Settings Controller.
* @param sessionService Session Service to handle Sessions.
*/
@Autowired
public SettingsController(SessionService sessionService) {
this.sessionService = sessionService;
}

//region Settings Retrieve


/**
* Retrieve all Settings for a Guild.
* @param sessionIdentifier Session Identifier to identify the Session.
* @param guildId Guild ID to identify the Guild.
* @return Generic Object Response with the Settings.
*/
@GetMapping(value = "/", produces = MediaType.APPLICATION_JSON_VALUE)
public GenericObjectResponse<List<Setting>> retrieveSettings(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier,
@PathVariable(name = "guildId") String guildId) {
Expand All @@ -40,7 +55,13 @@ public GenericObjectResponse<List<Setting>> retrieveSettings(@RequestHeader(name
}
}


/**
* Retrieve a Setting for a Guild.
* @param sessionIdentifier Session Identifier to identify the Session.
* @param guildId Guild ID to identify the Guild.
* @param settingName Setting Name to identify the Setting.
* @return Generic Object Response with the Setting.
*/
@GetMapping(value = "/{settingName}", produces = MediaType.APPLICATION_JSON_VALUE)
public GenericObjectResponse<Setting> retrieveSetting(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier,
@PathVariable(name = "guildId") String guildId,
Expand All @@ -57,7 +78,14 @@ public GenericObjectResponse<Setting> retrieveSetting(@RequestHeader(name = "X-S

//region Settings Update


/**
* Update a Setting for a Guild.
* @param sessionIdentifier Session Identifier to identify the Session.
* @param guildId Guild ID to identify the Guild.
* @param settingName Setting Name to identify the Setting.
* @param request Generic Value Request with the new Value.
* @return Generic Object Response with the updated Setting.
*/
@PostMapping(value = "/{settingName}/update", produces = MediaType.APPLICATION_JSON_VALUE)
public GenericObjectResponse<Setting> updateSetting(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier,
@PathVariable(name = "guildId") String guildId,
Expand All @@ -77,7 +105,13 @@ public GenericObjectResponse<Setting> updateSetting(@RequestHeader(name = "X-Ses

//region Setting Delete


/**
* Delete a Setting for a Guild.
* @param sessionIdentifier Session Identifier to identify the Session.
* @param guildId Guild ID to identify the Guild.
* @param settingName Setting Name to identify the Setting.
* @return Generic Response with the result.
*/
@GetMapping(value = "/{settingName}/delete", produces = MediaType.APPLICATION_JSON_VALUE)
public GenericResponse deleteSetting(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier,
@PathVariable(name = "guildId") String guildId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,18 @@
import java.util.Collections;
import java.util.List;

/**
* Service meant to handle Sessions.
*/
@Service
public class SessionService {

/**
* Retrieve a Session from the Identifier.
* @param identifier Identifier to identify the Session.
* @return Session Container with the Session.
* @throws IllegalAccessException If the Session could not be found.
*/
public SessionContainer retrieveSession(String identifier) throws IllegalAccessException {
try {
// Try retrieving the Session from the Identifier.
Expand All @@ -42,6 +51,13 @@ public SessionContainer retrieveSession(String identifier) throws IllegalAccessE
}
}

/**
* Create a new Session.
* @param code Code to create the Session.
* @param state State to create the Session.
* @return Session Container with the Session.
* @throws IllegalAccessException If the Session could not be created.
*/
public SessionContainer createSession(String code, String state) throws IllegalAccessException {
// Generate a secure Base64 String for the Identifier.
String identifier = RandomUtils.getRandomBase64String(128);
Expand Down Expand Up @@ -70,14 +86,38 @@ public SessionContainer createSession(String code, String state) throws IllegalA
}
}

/**
* Retrieve a Guild from the Identifier and the Guild ID.
* @param identifier Identifier to identify the Session.
* @param guildId Guild ID to identify the Guild.
* @return Guild Container with the Guild.
* @throws IllegalAccessException If the Guild could not be found.
*/
public GuildContainer retrieveGuild(String identifier, String guildId) throws IllegalAccessException {
return retrieveGuild(identifier, guildId, false);
}

/**
* Retrieve a Guild from the Identifier and the Guild ID.
* @param identifier Identifier to identify the Session.
* @param guildId Guild ID to identify the Guild.
* @param retrieveChannels If the Channels should be retrieved.
* @return Guild Container with the Guild.
* @throws IllegalAccessException If the Guild could not be found.
*/
public GuildContainer retrieveGuild(String identifier, String guildId, boolean retrieveChannels) throws IllegalAccessException {
return retrieveGuild(identifier, guildId, retrieveChannels, false);
}

/**
* Retrieve a Guild from the Identifier and the Guild ID.
* @param identifier Identifier to identify the Session.
* @param guildId Guild ID to identify the Guild.
* @param retrieveChannels If the Channels should be retrieved.
* @param retrieveRoles If the Roles should be retrieved.
* @return Guild Container with the Guild.
* @throws IllegalAccessException If the Guild could not be found.
*/
public GuildContainer retrieveGuild(String identifier, String guildId, boolean retrieveChannels, boolean retrieveRoles) throws IllegalAccessException {
SessionContainer sessionContainer = retrieveSession(identifier);

Expand Down Expand Up @@ -109,10 +149,23 @@ public GuildContainer retrieveGuild(String identifier, String guildId, boolean r
throw new IllegalAccessException("Not enough permissions!");
}

/**
* Retrieve a Guild from the Guild ID.
* @param guildId Guild ID to identify the Guild.
* @return Guild Container with the Guild.
* @throws IllegalAccessException If the Guild could not be found.
*/
public GuildContainer retrieveGuild(String guildId) throws IllegalAccessException {
return retrieveGuild(guildId, false);
}

/**
* Retrieve a Guild from the Guild ID.
* @param guildId Guild ID to identify the Guild.
* @param retrieveChannels If the Channels should be retrieved.
* @return Guild Container with the Guild.
* @throws IllegalAccessException If the Guild could not be found.
*/
public GuildContainer retrieveGuild(String guildId, boolean retrieveChannels) throws IllegalAccessException {

// Retrieve the Guild by its giving ID.
Expand All @@ -124,10 +177,23 @@ public GuildContainer retrieveGuild(String guildId, boolean retrieveChannels) th
return new GuildContainer(guild, retrieveChannels);
}

/**
* Retrieve a List of Guilds from the Identifier.
* @param identifier Identifier to identify the Session.
* @return List of Guild Containers with the Guilds.
* @throws IllegalAccessException If the Guilds could not be found.
*/
public List<GuildContainer> retrieveGuilds(String identifier) throws IllegalAccessException {
return retrieveGuilds(identifier, true);
}

/**
* Retrieve a List of Guilds from the Identifier.
* @param identifier Identifier to identify the Session.
* @param permissionFilter If the Guilds should be filtered by the Permission.
* @return List of Guild Containers with the Guilds.
* @throws IllegalAccessException If the Guilds could not be found.
*/
public List<GuildContainer> retrieveGuilds(String identifier, boolean permissionFilter) throws IllegalAccessException {
SessionContainer sessionContainer = retrieveSession(identifier);
List<OAuth2Guild> guilds = Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
package de.presti.ree6.backend.utils.data.container.api;

/**
* Request for the Custom Command.
* @param name Name of the Command.
* @param message Message of the Command.
* @param embedJson Embed of the Command.
* @param channelId Channel ID of the Command.
*/
public record CustomCommandRequest(String name, String message, String embedJson, String channelId) {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
package de.presti.ree6.backend.utils.data.container.api;

/**
* Request for the Generic Notifier.
* @param channelId Channel ID of the Notifier.
* @param message Message of the Notifier.
* @param name Name of the Notifier.
*/
public record GenericNotifierRequest(String channelId, String message, String name) {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package de.presti.ree6.backend.utils.data.container.api;

/**
* Request for the Generic Value.
* @param value Value of the Value.
*/
public record GenericValueRequest(String value) {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
package de.presti.ree6.backend.utils.data.container.api;

/**
* Request for the Level Auto Role.
* @param level Level of the Auto Role.
* @param roleId Role ID of the Auto Role.
*/
public record LevelAutoRoleRequest(long level, String roleId) {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
package de.presti.ree6.backend.utils.data.container.api;

/**
* Request for the Punishments.
* @param neededWarnings Needed Warnings of the Punishments.
* @param action Action of the Punishments.
* @param roleId Role ID of the Punishments.
* @param timeoutTime Timeout Time of the Punishments.
*/
public record PunishmentsRequest(String neededWarnings, String action, String roleId, String timeoutTime) {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
package de.presti.ree6.backend.utils.data.container.api;

/**
* Request for the Reaction Role Delete.
* @param messageId Message ID of the Reaction Role.
* @param emojiId Emoji ID of the Reaction Role.
*/
public record ReactionRoleDeleteRequest(String messageId, String emojiId) {
}
Loading

0 comments on commit 96b0b5d

Please sign in to comment.