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

Add series issue 6 #81

Closed
wants to merge 68 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
0686385
Add new entity representing series of books.
kev711 Mar 11, 2021
c5d2ca8
Add new entity mapping series of books and books with a serial order …
kev711 Mar 11, 2021
3590469
Add bookSeriesMapping to Book
kev711 Mar 11, 2021
b8aed12
Add copyright text
kev711 Mar 14, 2021
e21db5a
Update BookSeries entity's member "seriesName"
kev711 Mar 14, 2021
75ccd9d
Update BookSeriesMapping entity - Unique constraint, Relationship fie…
kev711 Mar 14, 2021
e0718d1
Add tests for entities Book Series Mapping and Book Series.
kev711 Mar 14, 2021
2af638c
Add boilerplate code for entity repositories.
kev711 Mar 14, 2021
eee400e
Add repository methods for Book, BookSeriesMapping
kev711 Mar 21, 2021
370dc0b
Add test classes for BookSeries & BookSeriesMapping repository
kev711 Mar 21, 2021
d10d705
Add new tests for Book repository
kev711 Mar 21, 2021
8309e31
Update setup method to clear tables with Foreign Key dependencies first
kev711 Mar 21, 2021
fe14f80
Fix test issues due to merge
kev711 Mar 21, 2021
d238142
Remove wildcard imports & adhere to 100 char limit
knjk04 Mar 25, 2021
2208799
Extract create book code to method
knjk04 Mar 25, 2021
ca46272
Extract create book code to method
knjk04 Mar 25, 2021
8dc9835
Add missing copyright notice
knjk04 Mar 25, 2021
9b37d9d
Extract create book code to method
knjk04 Mar 25, 2021
d0cde5c
Find by title
knjk04 Mar 25, 2021
254c14b
Extract duplicate code to method
knjk04 Mar 25, 2021
c9cbb82
Add delete book mutation
knjk04 Mar 27, 2021
03299dd
Merge pull request #83 from Project-Books/delete-book-mutation-82
knjk04 Mar 27, 2021
1688866
Resolve for PR-81 comments
kev711 Mar 27, 2021
5ba90da
Add DDL for Flyway migration.
kev711 Mar 29, 2021
b9e9305
Add publisher entity
knjk04 Mar 30, 2021
071b289
Update expired Slack link
knjk04 Mar 30, 2021
cbf5b70
Add migrations
knjk04 Mar 30, 2021
88cec9c
Rename publisher_book foreign key constraints
knjk04 Mar 30, 2021
c7f17ff
Merge pull request #86 from Project-Books/publisher-entity-66
knjk04 Mar 30, 2021
67774cd
Update sample query
knjk04 Mar 30, 2021
f527576
Make the Author the owner side of the many-to-many relationship
knjk04 Mar 31, 2021
dae9e4b
Extract common create book code to new method
knjk04 Mar 31, 2021
59e45fc
Fix failing tests
knjk04 Mar 31, 2021
fba2ad4
Make Author take in a set of books
knjk04 Mar 31, 2021
20c7494
Add Author with an empty set in mutation
knjk04 Mar 31, 2021
8a875ab
Merge pull request #89 from Project-Books/author-owner-80
knjk04 Mar 31, 2021
9eabd49
Update sample query
knjk04 Mar 31, 2021
4fa6954
Add removeBooks() method
knjk04 Mar 31, 2021
15cdecc
Set ddl auto to create in dev setup
knjk04 Mar 31, 2021
caa2dad
Merge pull request #91 from Project-Books/fix-multiple-authors-saved-75
knjk04 Mar 31, 2021
ed1c2bd
Create stale.yml
knjk04 Mar 31, 2021
123b6f5
Merge pull request #96 from Project-Books/follow-up-pr-95
knjk04 Mar 31, 2021
ea26737
Remove publishername graphql file
knjk04 Mar 31, 2021
9fc3b12
Add missing Publisher schema file
knjk04 Mar 31, 2021
11057c4
Add new entity representing series of books.
kev711 Mar 11, 2021
a293078
Add new entity mapping series of books and books with a serial order …
kev711 Mar 11, 2021
11ff6e4
Rebase onto main
kev711 Mar 11, 2021
c3826fb
Add copyright text
kev711 Mar 14, 2021
ebebbd5
Update BookSeries entity's member "seriesName"
kev711 Mar 14, 2021
789e0bd
Update BookSeriesMapping entity - Unique constraint, Relationship fie…
kev711 Mar 14, 2021
58ebd53
Add tests for entities Book Series Mapping and Book Series.
kev711 Mar 14, 2021
89248b0
Add boilerplate code for entity repositories.
kev711 Mar 14, 2021
fe11c63
Add repository methods for Book, BookSeriesMapping
kev711 Mar 21, 2021
5b7dc1c
Add test classes for BookSeries & BookSeriesMapping repository
kev711 Mar 21, 2021
346f344
Rebase onto main
kev711 Mar 21, 2021
84a2e53
Update setup method to clear tables with Foreign Key dependencies first
kev711 Mar 21, 2021
42a6622
Fix test issues due to merge
kev711 Mar 21, 2021
a78fc25
Remove wildcard imports & adhere to 100 char limit
knjk04 Mar 25, 2021
b62559f
Extract create book code to method
knjk04 Mar 25, 2021
7863aad
Extract create book code to method
knjk04 Mar 25, 2021
4327b42
Add missing copyright notice
knjk04 Mar 25, 2021
06ec459
Extract create book code to method
knjk04 Mar 25, 2021
4866d66
Find by title
knjk04 Mar 25, 2021
bfcc19c
Extract duplicate code to method
knjk04 Mar 25, 2021
f4fedf8
Resolve for PR-81 comments
kev711 Mar 27, 2021
d76c2d5
Add DDL for Flyway migration.
kev711 Mar 29, 2021
e36fc6e
Update tests to new model
kev711 Apr 14, 2021
0e04fdb
Merge remote-tracking branch 'origin/add-series-issue-6' into add-ser…
kev711 Apr 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rebase onto main
kev711 committed Apr 14, 2021
commit 346f34416764d0cf98716a928aeb9bd0a3d1d3dd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Karan Kumar
* Copyright (C) 2020 Karan Kumar
*
* This program is free software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation, either version 3 of the
@@ -20,13 +20,17 @@
import com.karankumar.booksapi.model.Book;
import com.karankumar.booksapi.model.BookFormat;
import com.karankumar.booksapi.model.BookGenre;
import com.karankumar.booksapi.model.BookSeries;
import com.karankumar.booksapi.model.BookSeriesMapping;
import com.karankumar.booksapi.model.Language;
import com.karankumar.booksapi.model.Publisher;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashSet;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static com.karankumar.booksapi.repository.RepositoryTestUtils.createBook;
@@ -38,19 +42,27 @@
class BookRepositoryTest {
private static final String ISBN = "978-3-16-148410-0";
private static final String TITLE = "Harry Potter";
private static final String AUTHOR1_FULL_NAME = "Kevlin Henney";

private final BookRepository bookRepository;
private final AuthorRepository authorRepository;

private final BookSeriesRepository bookSeriesRepository;
private final BookSeriesMappingRepository bookSeriesMappingRepository;

@Autowired
BookRepositoryTest(BookRepository bookRepository, AuthorRepository authorRepository) {
BookRepositoryTest(BookRepository bookRepository, AuthorRepository authorRepository,
BookSeriesRepository bookSeriesRepository, BookSeriesMappingRepository bookSeriesMappingRepository) {
this.bookRepository = bookRepository;
this.authorRepository = authorRepository;
this.bookSeriesRepository = bookSeriesRepository;
this.bookSeriesMappingRepository = bookSeriesMappingRepository;
}
@BeforeEach
void setUp() {
bookSeriesMappingRepository.deleteAll();
authorRepository.deleteAll();
bookRepository.deleteAll();
bookSeriesRepository.deleteAll();
}

@Test
@@ -155,4 +167,87 @@ void findBookByTitleCaseInsensitive() {
// then
assertThat(result).isEqualTo(book);
}

private void saveAllAuthors(Author... authors) {
Arrays.stream(authors).forEach(authorRepository::save);
}

@Test
@DisplayName("find all Book Series for a Book")
void findBookSeriesForBook(){
List<BookSeries> assertion = addBookToSeries();
Book book = bookRepository.findBookByIsbn13("9781408810545");

List<BookSeries> result = bookRepository.getAllBookSeriesForBook(book);

assertThat(result).containsExactlyInAnyOrderElementsOf(assertion);
}

@Test
@DisplayName("find book position in Book Series")
void findBookPositionInSeries(){

// Get book and book series from repo
List <BookSeries> allSeries = addBookToSeries();
Book book = bookRepository.findBookByIsbn13("9781408810545");
BookSeries assertion = null;
for (BookSeries series : allSeries) {
if(series.getSeriesName().equals("Harry Potter Series")){
assertion = series;
break;
}
}

assertThat(bookRepository.getBookPositionInBookSeries(book, assertion)).isEqualTo(1);
}

// Utility method
private List<BookSeries> addBookToSeries(){

Author author = new Author("J.K.", "Rowling");
author.setAbout("A fantastic author");
authorRepository.save(author);

Book book1 = new Book(
"Harry Potter and the Philosopher's stone", new Author[]{author},
Language.ENGLISH, "Sample blurb value",
BookGenre.FANTASY, BookFormat.PAPERBACK
);
book1.setYearOfPublication(1997);
book1.setIsbn13("9781408810545");
book1.setPublishedBy(Publisher.BLOOMSBURY);
bookRepository.save(book1);

Book book2 = new Book(
"Harry Potter and the Chamber of Secrets",
new Author[]{author},
Language.ENGLISH,
"Sample blurb value",
BookGenre.FANTASY,
BookFormat.PAPERBACK
);
book2.setIsbn13("1234567898765");
book2.setGenre(BookGenre.FANTASY);
book2.setPublishedBy(Publisher.BLOOMSBURY);
book2.setFormat(BookFormat.PAPERBACK);
bookRepository.save(book2);

BookSeries bookSeries1 = new BookSeries("Harry Potter Series");
bookSeriesRepository.save(bookSeries1);

BookSeries bookSeries2 = new BookSeries("J.K. Rowling Specials");
bookSeriesRepository.save(bookSeries2);

bookSeriesMappingRepository.save(new BookSeriesMapping(bookSeries1, book1, 1));
bookSeriesMappingRepository.save(new BookSeriesMapping(bookSeries1, book2, 2));

bookSeriesMappingRepository.save(new BookSeriesMapping(bookSeries2, book1, 1));
bookSeriesMappingRepository.save(new BookSeriesMapping(bookSeries2, book2, 2));

List<BookSeries> bs = new ArrayList<>();
bs.add(bookSeries1);
bs.add(bookSeries2);

return bs;
}
}