feat: Add book deletion functionality to BookEditingService
This commit is contained in:
@@ -12,5 +12,6 @@ public interface BookEditingService {
|
||||
void updateBookRating(BotUser user, String newRating);
|
||||
void handleEditDate(BotUser user);
|
||||
void updateBookDate(BotUser user, String newDate);
|
||||
void deleteBook(BotUser user) throws ServiceException;
|
||||
void handleRestartMessage(BotUser botUser);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,33 @@ public class BookEditingServiceImpl implements BookEditingService {
|
||||
private final BookRepository bookRepository;
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@Override
|
||||
public void deleteBook(BotUser user) throws ServiceException {
|
||||
try {
|
||||
var bookCache = bookCacheService.getBookEditCache(user.getId());
|
||||
if (bookCache == null || bookCache.getBookId() == null) {
|
||||
throw new ServiceException("Не найдена книга для удаления");
|
||||
}
|
||||
|
||||
Long bookId = bookCache.getBookId();
|
||||
Optional<Book> book = bookRepository.findByIdAndBotUser(bookId, user);
|
||||
|
||||
if (book.isPresent()) {
|
||||
bookRepository.deleteById(bookId);
|
||||
bookCacheService.clearBookEditCache(user.getId());
|
||||
telegramClientService.sendMessage(
|
||||
user,
|
||||
"Книга успешно удалена \uD83D\uDDD1️",
|
||||
KeyboardHelper.getBookMenuKeyboard()
|
||||
);
|
||||
} else {
|
||||
throw new ServiceException(Constants.ERROR_BOOK_NOT_FOUND);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ServiceException("Ошибка при удалении книги: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void processBookSelection(BotUser user, Long bookId) {
|
||||
try {
|
||||
Optional<Book> book = bookRepository.findByIdAndBotUser(bookId, user);
|
||||
|
||||
Reference in New Issue
Block a user