Skip to content
This repository was archived by the owner on Mar 25, 2023. It is now read-only.

#17 - Add derived query for ISBN#29

Merged
knjk04 merged 9 commits intoProject-Books:mainfrom
ahsanbagwan:jpa-query-isbn-17
Jan 3, 2021
Merged

#17 - Add derived query for ISBN#29
knjk04 merged 9 commits intoProject-Books:mainfrom
ahsanbagwan:jpa-query-isbn-17

Conversation

@ahsanbagwan
Copy link
Contributor

@ahsanbagwan ahsanbagwan commented Dec 7, 2020

Summary of change

  • Added derived query to fetch by ISBN13
  • Added test data
  • Added JUnit test

Related issue

Closes #17

Pull request checklist

Please keep this checklist in & ensure you have done the following:

  • Read, understood and adhered to our contributing document.

    • Ensure that you were first assigned to a relevant issue before creating this pull request
    • Ensure code changes pass all tests
  • Read, understood and adhered to our style guide. A lot of our code reviews are spent on ensuring compliance with our style guide, so it would save a lot of time if this was adhered to from the outset.

  • Filled in the summary, context (if applicable) and related issue section. Replace the square brackets and its placeholder content with your contents. For an example, see any merged in pull request

  • Created a branch that has a descriptive name (what your branch is for in a few words and includes the issue number at the end, e.g. test-reading-goal-123

  • Set this pull request to 'draft' if you are still working on it

  • Resolved any merge conflicts

For any of the optional checkboxes (e.g. the screenshots one), still check it if it does not apply.

If in doubt, get in touch with us via our Slack workspace

@knjk04
Copy link
Member

knjk04 commented Dec 7, 2020

@ahsanbagwan Thanks for working on this. As per our contributing guidelines, we only accept PRs where you have first been assigned to the issue. Could you please request to be assigned to the issue? Also, I've added the PR checklist back in -- could you please fill it in?

Copy link
Member

@knjk04 knjk04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! I've left some comments for you to address

Comment on lines 28 to 29
@Query("SELECT DISTINCT b FROM Book b LEFT JOIN FETCH b.authors WHERE b.isbn13=:isbn")
Book findBookByISBN(String isbn);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please remove the JPQL query?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean could you elaborate?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line:

@Query("SELECT DISTINCT b FROM Book b LEFT JOIN FETCH b.authors WHERE b.isbn13=:isbn") 

bookRepository.save(book);

Book result = bookRepository.findBookByISBN("978-3-16-148410-0");
Assertions.assertEquals(book,result);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per our style guide, we're using AssertJ assertions, not JUnit. Could you please change this?


private Book createBookwithISBN() {
Book book = new Book("Game of APIs", new Author[]{author1, author2} , Language.ENGLISH);
book.setIsbn13("978-3-16-148410-0");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having the ISBN literal twice, could you please extract this to a field?

@knjk04
Copy link
Member

knjk04 commented Dec 12, 2020

Thanks for making the changes. Could you also please add to the query.graphqls file so that we can access it from the playground?

@knjk04
Copy link
Member

knjk04 commented Dec 14, 2020

Thanks for making the change.

Does this work for you? This is the stack trace I get when I run this: https://gist.github.com/knjk04/d5fa917e9da9bd27d302e294fdaf570c

@knjk04
Copy link
Member

knjk04 commented Dec 28, 2020

@ahsanbagwan Just following up. Did you manage to get a chance to see the message above?

@ahsanbagwan
Copy link
Contributor Author

ahsanbagwan commented Dec 28, 2020 via email

@knjk04 knjk04 marked this pull request as draft December 29, 2020 17:50
@knjk04
Copy link
Member

knjk04 commented Dec 29, 2020

Let us know when you're ready for another review

@ahsanbagwan
Copy link
Contributor Author

I'm no longer getting the graphql schema error on running the application...

Snip
2020-12-29 23:31:29.985 INFO 27712 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2020-12-29 23:31:29.987 INFO 27712 --- [ restartedMain] DeferredRepositoryInitializationListener : Triggering deferred initialization of Spring Data repositories…
2020-12-29 23:31:30.856 INFO 27712 --- [ restartedMain] DeferredRepositoryInitializationListener : Spring Data repositories initialized!
2020-12-29 23:31:30.893 INFO 27712 --- [ restartedMain] c.k.booksapi.BooksApiApplication : Started BooksApiApplication in 18.509 seconds (JVM running for 21.016)

Could you please go ahead and add review comments if required?

@knjk04 knjk04 marked this pull request as ready for review December 29, 2020 18:37
Copy link
Member

@knjk04 knjk04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

@knjk04 knjk04 merged commit 6d4722d into Project-Books:main Jan 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add derived query to find books by ISBN 13

2 participants