mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-14 03:45:57 +00:00
added more specific exceptions
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package dev.sheldan.abstracto.utility.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
|
||||
import dev.sheldan.abstracto.core.models.AServerAChannelAUser;
|
||||
@@ -12,6 +11,7 @@ import dev.sheldan.abstracto.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.scheduling.service.SchedulerService;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.utility.exception.ReminderNotFoundException;
|
||||
import dev.sheldan.abstracto.utility.models.database.Reminder;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.reminder.ExecutedReminderModel;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.reminder.ReminderModel;
|
||||
@@ -98,7 +98,7 @@ public class RemindServiceBean implements ReminderService {
|
||||
@Override
|
||||
@Transactional
|
||||
public void executeReminder(Long reminderId) {
|
||||
Reminder reminderToRemindFor = reminderManagementService.loadReminder(reminderId).orElseThrow(() -> new AbstractoRunTimeException(String.format("Could not find reminder with id %s", reminderId)));
|
||||
Reminder reminderToRemindFor = reminderManagementService.loadReminder(reminderId).orElseThrow(() -> new ReminderNotFoundException(reminderId));
|
||||
if(reminderToRemindFor.isReminded()) {
|
||||
return;
|
||||
}
|
||||
@@ -140,7 +140,7 @@ public class RemindServiceBean implements ReminderService {
|
||||
}
|
||||
reminderManagementService.saveReminder(reminder);
|
||||
} else {
|
||||
throw new AbstractoRunTimeException("Reminder does not exist, was already reminded or does not belong to you.");
|
||||
throw new ReminderNotFoundException(reminderId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.sheldan.abstracto.utility.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.exception.ChannelNotFoundException;
|
||||
import dev.sheldan.abstracto.core.exception.UserInServerNotFoundException;
|
||||
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.PostTargetManagement;
|
||||
import dev.sheldan.abstracto.core.models.AServerAChannelMessage;
|
||||
@@ -103,8 +103,8 @@ public class StarboardServiceBean implements StarboardService {
|
||||
|
||||
@Transactional
|
||||
public void persistPost(CachedMessage message, List<Long> userExceptAuthorIds, List<CompletableFuture<Message>> completableFutures, Long starboardChannelId, Long starredUserId, Long userReactingId) {
|
||||
AUserInAServer innerStarredUser = userInServerManagementService.loadUser(starredUserId).orElseThrow(() -> new AbstractoRunTimeException(String.format("Cannnot find user with id %s", starredUserId)));
|
||||
AUserInAServer innerUserReacting = userInServerManagementService.loadUser(userReactingId).orElseThrow(() -> new AbstractoRunTimeException(String.format("Cannnot find user with id %s", userReactingId)));
|
||||
AUserInAServer innerStarredUser = userInServerManagementService.loadUser(starredUserId).orElseThrow(() -> new UserInServerNotFoundException(starredUserId));
|
||||
AUserInAServer innerUserReacting = userInServerManagementService.loadUser(userReactingId).orElseThrow(() -> new UserInServerNotFoundException(userReactingId));
|
||||
try {
|
||||
AChannel starboardChannel = channelManagementService.loadChannel(starboardChannelId).orElseThrow(() -> new ChannelNotFoundException(starboardChannelId, message.getServerId()));
|
||||
Message message1 = completableFutures.get(0).get();
|
||||
@@ -116,7 +116,7 @@ public class StarboardServiceBean implements StarboardService {
|
||||
.build();
|
||||
StarboardPost starboardPost = starboardPostManagementService.createStarboardPost(message, innerStarredUser, innerUserReacting, aServerAChannelMessage);
|
||||
userExceptAuthorIds.forEach(aLong -> {
|
||||
AUserInAServer user = userInServerManagementService.loadUser(aLong).orElseThrow(() -> new AbstractoRunTimeException(String.format("Could not find user with id %s", aLong)));
|
||||
AUserInAServer user = userInServerManagementService.loadUser(aLong).orElseThrow(() -> new UserInServerNotFoundException(aLong));
|
||||
starboardPostReactorManagementService.addReactor(starboardPost, user);
|
||||
});
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package dev.sheldan.abstracto.utility.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.templating.model.MessageToSend;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
@@ -8,6 +7,7 @@ import dev.sheldan.abstracto.core.service.MessageService;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import dev.sheldan.abstracto.core.utils.MessageUtils;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import dev.sheldan.abstracto.utility.exception.SuggestionNotFoundException;
|
||||
import dev.sheldan.abstracto.utility.models.database.Suggestion;
|
||||
import dev.sheldan.abstracto.utility.models.SuggestionState;
|
||||
import dev.sheldan.abstracto.utility.models.template.commands.SuggestionLog;
|
||||
@@ -65,7 +65,7 @@ public class SuggestionServiceBean implements SuggestionService {
|
||||
if(guildById != null) {
|
||||
List<CompletableFuture<Message>> completableFutures = postTargetService.sendEmbedInPostTarget(messageToSend, SUGGESTIONS_TARGET, guildId);
|
||||
CompletableFuture.allOf(completableFutures.toArray(new CompletableFuture[0])).thenAccept(aVoid -> {
|
||||
Suggestion innerSuggestion = suggestionManagementService.getSuggestion(suggestionId).orElseThrow(() -> new AbstractoRunTimeException(String.format("Could not find suggestion with id %s", suggestionId)));
|
||||
Suggestion innerSuggestion = suggestionManagementService.getSuggestion(suggestionId).orElseThrow(() -> new SuggestionNotFoundException(suggestionId));
|
||||
try {
|
||||
Message message = completableFutures.get(0).get();
|
||||
suggestionManagementService.setPostedMessage(innerSuggestion, message);
|
||||
@@ -85,7 +85,7 @@ public class SuggestionServiceBean implements SuggestionService {
|
||||
|
||||
@Override
|
||||
public void acceptSuggestion(Long suggestionId, String text, SuggestionLog suggestionLog) {
|
||||
Suggestion suggestion = suggestionManagementService.getSuggestion(suggestionId).orElseThrow(() -> new AbstractoRunTimeException(String.format("Could not find suggestion with id %s", suggestionId)));
|
||||
Suggestion suggestion = suggestionManagementService.getSuggestion(suggestionId).orElseThrow(() -> new SuggestionNotFoundException(suggestionId));
|
||||
suggestionManagementService.setSuggestionState(suggestion, SuggestionState.ACCEPTED);
|
||||
updateSuggestion(text, suggestionLog, suggestion);
|
||||
}
|
||||
@@ -130,7 +130,7 @@ public class SuggestionServiceBean implements SuggestionService {
|
||||
|
||||
@Override
|
||||
public void rejectSuggestion(Long suggestionId, String text, SuggestionLog log) {
|
||||
Suggestion suggestion = suggestionManagementService.getSuggestion(suggestionId).orElseThrow(() -> new AbstractoRunTimeException(String.format("Could not find suggestion with id %s", suggestionId)));
|
||||
Suggestion suggestion = suggestionManagementService.getSuggestion(suggestionId).orElseThrow(() -> new SuggestionNotFoundException(suggestionId));
|
||||
suggestionManagementService.setSuggestionState(suggestion, SuggestionState.REJECTED);
|
||||
updateSuggestion(text, log, suggestion);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user