Skip to content

Commit

Permalink
V5 should be done now.
Browse files Browse the repository at this point in the history
  • Loading branch information
DxsSucuk committed Nov 1, 2024
1 parent bfd7a8a commit 00fb96c
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public Mono<GenericObjectResponse<LeaderboardContainer>> retrieveLeaderboardVoic
return new GenericObjectResponse<>(true, leaderboardContainer, "Leaderboard retrieved!");
}).block();
})
.orElse(new GenericObjectResponse<>(false, null, "Could not retrieve")));
.orElse(new GenericObjectResponse<>(false, null, "Could not retrieve!")));
}

@GetMapping(value = "/{guildId}/leaderboard/chat", produces = MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -214,7 +214,7 @@ public Mono<GenericObjectResponse<LeaderboardContainer>> retrieveLeaderboardChat
return new GenericObjectResponse<>(true, leaderboardContainer, "Leaderboard retrieved!");
}).block();
})
.orElse(new GenericObjectResponse<>(false, null, "Could not retrieve")));
.orElse(new GenericObjectResponse<>(false, null, "Could not retrieve!")));
}

//endregion
Expand All @@ -224,7 +224,7 @@ public Mono<GenericObjectResponse<LeaderboardContainer>> retrieveLeaderboardChat
@GetMapping(value = "/{guildId}/stats", produces = MediaType.APPLICATION_JSON_VALUE)
public Mono<GenericObjectResponse<GuildStatsContainer>> retrieveStats(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) {
return guildService.getStats(sessionIdentifier, guildId)
.map(x -> new GenericObjectResponse<>(true, x.orElse(null), x.isPresent() ? "Retrieved" : "Failed to retrieved"));
.map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(null), x.isPresent() ? "Retrieved" : "Failed to retrieve!"));
}

//endregion
Expand All @@ -234,7 +234,7 @@ public Mono<GenericObjectResponse<GuildStatsContainer>> retrieveStats(@RequestHe
@GetMapping(value = "/{guildId}/chatrole", produces = MediaType.APPLICATION_JSON_VALUE)
public Mono<GenericObjectResponse<List<RoleLevelContainer>>> retrieveChatRoles(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) {
return guildService.getChatAutoRoles(sessionIdentifier, guildId)
.map(x -> new GenericObjectResponse<>(true, x.orElse(Collections.emptyList()), x.isPresent() ? "Retrieved!" : "Could not retrieve!"));
.map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(Collections.emptyList()), x.isPresent() ? "Retrieved!" : "Could not retrieve!"));
}

@PostMapping(value = "/{guildId}/chatrole/remove", produces = MediaType.APPLICATION_JSON_VALUE)
Expand Down Expand Up @@ -262,7 +262,7 @@ public Mono<GenericResponse> addChatAutoRole(@RequestHeader(name = "X-Session-Au
@GetMapping(value = "/{guildId}/voicerole", produces = MediaType.APPLICATION_JSON_VALUE)
public Mono<GenericObjectResponse<List<RoleLevelContainer>>> retrieveVoiceRoles(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) {
return guildService.getVoiceAutoRoles(sessionIdentifier, guildId)
.map(x -> new GenericObjectResponse<>(true, x.orElse(Collections.emptyList()), x.isPresent() ? "Retrieved!" : "Could not retrieve!"));
.map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(Collections.emptyList()), x.isPresent() ? "Retrieved!" : "Could not retrieve!"));
}

@PostMapping(value = "/{guildId}/voicerole/remove", produces = MediaType.APPLICATION_JSON_VALUE)
Expand Down Expand Up @@ -290,7 +290,7 @@ public Mono<GenericResponse> addVoiceAutoRole(@RequestHeader(name = "X-Session-A
@GetMapping(value = "/recording", produces = MediaType.APPLICATION_JSON_VALUE)
public Mono<GenericObjectResponse<RecordContainer>> retrieveRecording(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @RequestParam(name = "recordId") String recordId) {
return guildService.getRecordingContainer(sessionIdentifier, recordId)
.map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(null), x.isPresent() ? "Retrieved" : "Failed to retrieved"));
.map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(null), x.isPresent() ? "Retrieved" : "Failed to retrieve!"));
}

@GetMapping(value = "/recording/download", produces = MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -315,7 +315,7 @@ public Mono<ResponseEntity<Resource>> downloadRecording(@RequestHeader(name = "X
@GetMapping(value = "/{guildId}/welcome", produces = MediaType.APPLICATION_JSON_VALUE)
public Mono<GenericObjectResponse<ChannelContainer>> retrieveWelcomeChannel(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) {
return guildService.getWelcomeChannel(sessionIdentifier, guildId)
.map(x -> new GenericObjectResponse<>(true, x.orElse(null), x.isPresent() ? "Retrieved" : "Failed to retrieved"));
.map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(null), x.isPresent() ? "Retrieved" : "Failed to retrieve!"));
}

@PostMapping(value = "/{guildId}/welcome/remove", produces = MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -337,7 +337,7 @@ public Mono<GenericResponse> addWelcomeChannel(@RequestHeader(name = "X-Session-
@GetMapping(value = "/{guildId}/log", produces = MediaType.APPLICATION_JSON_VALUE)
public Mono<GenericObjectResponse<ChannelContainer>> retrieveLogChannel(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) {
return guildService.getLogChannel(sessionIdentifier, guildId)
.map(x -> new GenericObjectResponse<>(true, x.orElse(null), x.isPresent() ? "Retrieved" : "Failed to retrieved"));
.map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(null), x.isPresent() ? "Retrieved" : "Failed to retrieve!"));
}

@PostMapping(value = "/{guildId}/log/remove", produces = MediaType.APPLICATION_JSON_VALUE)
Expand Down Expand Up @@ -484,7 +484,7 @@ public Mono<GenericResponse> addInstagramNotifier(@RequestHeader(name = "X-Sessi
@GetMapping(value = "/{guildId}/temporalvoice", produces = MediaType.APPLICATION_JSON_VALUE)
public Mono<GenericObjectResponse<ChannelContainer>> retrieveTemporalVoice(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) {
return guildService.getTemporalVoice(sessionIdentifier, guildId)
.map(x -> new GenericObjectResponse<>(true, x.orElse(null), x.isPresent() ? "Retrieved" : "Failed to retrieved"));
.map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(null), x.isPresent() ? "Retrieved" : "Failed to retrieve!"));
}


Expand Down Expand Up @@ -534,7 +534,7 @@ public Mono<GenericResponse> optOut(@RequestHeader(name = "X-Session-Authenticat
@GetMapping(value = "/{guildId}/tickets", produces = MediaType.APPLICATION_JSON_VALUE)
public Mono<GenericObjectResponse<TicketContainer>> retrieveTicket(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) {
return guildService.getTicket(sessionIdentifier, guildId)
.map(x -> new GenericObjectResponse<>(true, x.orElse(null), x.isPresent() ? "Retrieved" : "Failed to retrieved"));
.map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(null), x.isPresent() ? "Retrieved" : "Failed to retrieve!"));
}

@PostMapping(value = "/{guildId}/tickets/remove", produces = MediaType.APPLICATION_JSON_VALUE)
Expand All @@ -556,7 +556,7 @@ public Mono<GenericResponse> addTicket(@RequestHeader(name = "X-Session-Authenti
@GetMapping(value = "/{guildId}/suggestions", produces = MediaType.APPLICATION_JSON_VALUE)
public Mono<GenericObjectResponse<ChannelContainer>> retrieveSuggestion(@RequestHeader(name = "X-Session-Authenticator") String sessionIdentifier, @PathVariable(name = "guildId") long guildId) {
return guildService.getSuggestion(sessionIdentifier, guildId)
.map(x -> new GenericObjectResponse<>(true, x.orElse(null), x.isPresent() ? "Retrieved" : "Failed to retrieved"));
.map(x -> new GenericObjectResponse<>(x.isPresent(), x.orElse(null), x.isPresent() ? "Retrieved" : "Failed to retrieve!"));
}

@PostMapping(value = "/{guildId}/suggestions/remove", produces = MediaType.APPLICATION_JSON_VALUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ public Mono<GenericObjectResponse<List<Setting>>> retrieveSettings(@RequestHeade
}

return SQLSession.getSqlConnector().getSqlWorker().getAllSettings(guildId)
.map(settings -> new GenericObjectResponse<>(true, settings, null)).block();
.map(settings -> {
if (settings.isEmpty()) {
return new GenericObjectResponse<>(false,
SettingsManager.getSettings().stream()
.map(x -> new Setting(guildId, x.getName(), x.getDisplayName(), x.getValue())).toList(),
null);
}

return new GenericObjectResponse<>(true, settings, null);
}).block();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ public Mono<Optional<ChannelContainer>> getLogChannel(String sessionIdentifier,
ChannelContainer errorReturnValue = null;
return sessionService.retrieveGuild(sessionIdentifier, guildId, true).publishOn(Schedulers.boundedElastic()).mapNotNull(guildOptional -> {
if (guildOptional.isEmpty()) {
return Optional.ofNullable(errorReturnValue);
return Optional.empty();
}

GuildContainer guildContainer = guildOptional.get();

return SQLSession.getSqlConnector().getSqlWorker().getLogWebhook(guildId).publishOn(Schedulers.boundedElastic()).mapNotNull(webhookLogOptional -> {
if (webhookLogOptional.isEmpty()) {
return Optional.ofNullable(errorReturnValue);
return Optional.ofNullable(ChannelContainer.DEFAULT);
}

WebhookLog webhook = webhookLogOptional.get();
Expand Down Expand Up @@ -169,14 +169,14 @@ public Mono<Optional<ChannelContainer>> getWelcomeChannel(String sessionIdentifi
ChannelContainer errorReturnValue = null;
return sessionService.retrieveGuild(sessionIdentifier, guildId, true).publishOn(Schedulers.boundedElastic()).mapNotNull(guildOptional -> {
if (guildOptional.isEmpty()) {
return Optional.ofNullable(errorReturnValue);
return Optional.empty();
}

GuildContainer guildContainer = guildOptional.get();

return SQLSession.getSqlConnector().getSqlWorker().getWelcomeWebhook(guildId).publishOn(Schedulers.boundedElastic()).mapNotNull(webhookLogOptional -> {
if (webhookLogOptional.isEmpty()) {
return Optional.ofNullable(errorReturnValue);
return Optional.ofNullable(ChannelContainer.DEFAULT);
}

WebhookWelcome webhook = webhookLogOptional.get();
Expand Down Expand Up @@ -676,7 +676,7 @@ public Mono<Optional<ChannelContainer>> getTemporalVoice(String sessionIdentifie
.getEntity(new TemporalVoicechannel(), "FROM TemporalVoicechannel WHERE guildChannelId.guildId=:gid", Map.of("gid", guildId))
.map(temporalVoicechannelOptional -> temporalVoicechannelOptional
.map(temporalVoicechannel -> guildContainerOptional.get().getChannelById(temporalVoicechannel.getVoiceChannelId()))
.or(Optional::empty)).block();
.or(() -> Optional.ofNullable(ChannelContainer.DEFAULT))).block();
});
}

Expand Down Expand Up @@ -765,20 +765,19 @@ public Mono<Optional<String>> optOut(String sessionIdentifier, long guildId) {
//region Ticket

public Mono<Optional<TicketContainer>> getTicket(String sessionIdentifier, long guildId) {
TicketContainer errorReturnValue = null;
return sessionService.retrieveGuild(sessionIdentifier, guildId, true, false)
.publishOn(Schedulers.boundedElastic())
.mapNotNull(guildContainerOptional -> {
if (guildContainerOptional.isEmpty()) {
return Optional.ofNullable(errorReturnValue);
return Optional.empty();
}

GuildContainer guildContainer = guildContainerOptional.get();

return SQLSession.getSqlConnector().getSqlWorker().getEntity(new Tickets(), "FROM Tickets WHERE guildId=:gid", Map.of("gid", guildId))
.map(ticketOptional -> {
if (ticketOptional.isEmpty()) {
return Optional.ofNullable(errorReturnValue);
return Optional.ofNullable(TicketContainer.DEFAULT);
}

Tickets tickets = ticketOptional.get();
Expand Down Expand Up @@ -932,7 +931,7 @@ public Mono<Optional<ChannelContainer>> getSuggestion(String sessionIdentifier,
return SQLSession.getSqlConnector().getSqlWorker().getEntity(new Suggestions(),
"FROM Suggestions WHERE guildChannelId.guildId = :id", Map.of("id", guildId))
.map(suggestionOptional -> suggestionOptional
.map(x -> guildContainer.getChannelById(suggestionOptional.get().getChannelId())).or(Optional::empty))
.map(x -> guildContainer.getChannelById(suggestionOptional.get().getChannelId())).or(() -> Optional.of(ChannelContainer.DEFAULT)))
.block();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class ChannelContainer {
String name;
ChannelType type;

public static ChannelContainer DEFAULT = new ChannelContainer(-1, -1, "None", ChannelType.TEXT);

public ChannelContainer(StandardGuildMessageChannel guildChannel) {
this.id = guildChannel.getIdLong();
this.guildId = guildChannel.getGuild().getIdLong();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
@AllArgsConstructor
public class TicketContainer {

public static TicketContainer DEFAULT = new TicketContainer(null, null, 0, null, "", "");

public ChannelContainer channel;

public ChannelContainer category;
Expand Down
Loading

0 comments on commit 00fb96c

Please sign in to comment.