Created
August 1, 2022 11:20
-
-
Save atesibrahim/136030f86a2a6c3d72a2a4a28bf1bba7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller | |
@AllArgsConstructor | |
public class BookMutation { | |
BookRepository bookRepository; | |
@MutationMapping | |
public BookOutput newBook(@Argument("input") NewBook newBook){ | |
Book book = Book.builder().authorName(newBook.getAuthorName()).title(newBook.getTitle()).build(); | |
Book book1 = bookRepository.save(book); | |
return BookOutput.builder().authorName(book1.getAuthorName()).title(book1.getTitle()).build(); | |
} | |
@MutationMapping | |
public BookOutput deleteBook(@Argument("input") BookInput bookInput){ | |
Book deleteBook = new Book(); | |
Optional<Book> findBook = bookRepository.findById(bookInput.getId()); | |
if(findBook.isPresent()){ | |
bookRepository.delete(findBook.get()); | |
deleteBook = findBook.get(); | |
} | |
return BookOutput.builder().id(deleteBook.getId()).title(deleteBook.getTitle()).authorName(deleteBook.getAuthorName()).build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment