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
Show file tree
Hide file tree
Changes from 13 commits
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
9 changes: 7 additions & 2 deletions src/main/java/com/karankumar/booksapi/model/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Entity
Expand Down Expand Up @@ -75,8 +77,11 @@ public class Book {
@Column(nullable = false)
private BookFormat format;

public Book(@NonNull String title, @NonNull Author[] authors, @NonNull Language language,
@NonNull String blurb, @NonNull BookGenre genre, @NonNull BookFormat format) {
@OneToMany(mappedBy = "book")
private List<BookSeriesMapping> bookSeriesMapping;

public Book(@NonNull String title, @NonNull Author[] authors, @NonNull Language language, @NonNull String blurb,
@NonNull BookGenre genre, @NonNull BookFormat format) {
this.title = title;
Arrays.stream(authors).forEach(this::addAuthor);
this.language = language;
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/com/karankumar/booksapi/model/BookSeries.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
The book project lets a user keep track of different books they would like to read, are currently reading, have read or did not finish.
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
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program.
If not, see <https://www.gnu.org/licenses/>.
*/

package com.karankumar.booksapi.model;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.NonNull;

import javax.persistence.*;
import java.util.List;

@Entity
@Getter
@Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class BookSeries {
knjk04 marked this conversation as resolved.
Show resolved Hide resolved
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Setter(AccessLevel.NONE)
private Long id;

@Column(nullable = false, name = "series_name")
private String seriesName;

@OneToMany(mappedBy = "bookSeries")
private List<BookSeriesMapping> bookSeriesMapping;

public BookSeries(@NonNull String seriesName){
this.seriesName = seriesName;
}
}
53 changes: 53 additions & 0 deletions src/main/java/com/karankumar/booksapi/model/BookSeriesMapping.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
The book project lets a user keep track of different books they would like to read, are currently reading, have read or did not finish.
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
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program.
If not, see <https://www.gnu.org/licenses/>.
*/

package com.karankumar.booksapi.model;

import lombok.*;

import javax.persistence.*;

@Getter @Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity
@Table(
name="Book_To_BookSeries_Mapping",
uniqueConstraints = {
@UniqueConstraint( name = "UK_bookSeriesId_bookId", columnNames = {"book_series_id","book_id"} ),
knjk04 marked this conversation as resolved.
Show resolved Hide resolved
@UniqueConstraint( name = "UK_bookSeriesId_serialNumber", columnNames = {"book_series_id","serial_number"} )
}
)

public class BookSeriesMapping {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Setter(AccessLevel.NONE)
private Long id;

@ManyToOne(optional = false)
private BookSeries bookSeries;

@ManyToOne(optional = false)
private Book book;

@Column(nullable = false, name="serial_number")
private Integer serialNumber;
kev711 marked this conversation as resolved.
Show resolved Hide resolved

public BookSeriesMapping(@NonNull BookSeries bookSeries, @NonNull Book bookInSeries, @NonNull Integer serialNumber) {
this.bookSeries = bookSeries;
this.book = bookInSeries;
this.serialNumber = serialNumber;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package com.karankumar.booksapi.repository;

import com.karankumar.booksapi.model.Book;
import com.karankumar.booksapi.model.BookSeries;
import com.karankumar.booksapi.model.BookSeriesMapping;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

Expand All @@ -32,4 +34,13 @@ public interface BookRepository extends CrudRepository<Book, Long> {
Book findBookByIsbn13(String isbn13);

Book findByTitleIgnoreCase(String title);

// Lists all BookSeries for a Book entry
@Query("SELECT a.bookSeries FROM BookSeriesMapping a WHERE a.book = ?1")
List<BookSeries> getAllBookSeriesForBook(Book book);

// Returns position of a book in a Book Series
@Query("SELECT a.serialNumber FROM BookSeriesMapping a WHERE a.book = ?1 AND a.bookSeries = ?2")
Integer getBookPositionInBookSeries(Book book, BookSeries bookSeries);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2021 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
* License, or (at your option) any later version.

* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.

* You should have received a copy of the GNU General Public License along with this program.
* If not, see <https://www.gnu.org/licenses/>.
*/

package com.karankumar.booksapi.repository;

import com.karankumar.booksapi.model.Book;
import com.karankumar.booksapi.model.BookSeries;
import com.karankumar.booksapi.model.BookSeriesMapping;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface BookSeriesMappingRepository extends CrudRepository<BookSeriesMapping, Long> {

// Lists all Books in a Book Series
@Query("SELECT a.book FROM BookSeriesMapping a WHERE a.bookSeries = ?1")
List<Book> getAllBooksByBookSeries(BookSeries bookSeries);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2021 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
* License, or (at your option) any later version.

* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.

* You should have received a copy of the GNU General Public License along with this program.
* If not, see <https://www.gnu.org/licenses/>.
*/

package com.karankumar.booksapi.repository;

import com.karankumar.booksapi.model.BookSeries;
import org.springframework.data.repository.CrudRepository;

public interface BookSeriesRepository extends CrudRepository<BookSeries, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright (C) 2021 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
* License, or (at your option) any later version.

* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.

* You should have received a copy of the GNU General Public License along with this program.
* If not, see <https://www.gnu.org/licenses/>.
*/

package com.karankumar.booksapi.model;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

@DisplayName("Book Series Mapping should")
public class BookSeriesMappingTest {

@Test
@DisplayName("throw a Null Pointer Exception on an attempt to create with Null Serial Number")
void notAcceptNullSerialNumber(){

BookSeries bookSeries = new BookSeries("Harry Potter Series");

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

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

assertThatExceptionOfType(NullPointerException.class)
.isThrownBy(()->new BookSeriesMapping(bookSeries, book, null));
}

@Test
@DisplayName("throw a Null Pointer Exception on an attempt to create with Null Book")
void notAcceptNullBook(){

BookSeries bookSeries = new BookSeries("Harry Potter Series");

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

assertThatExceptionOfType(NullPointerException.class)
.isThrownBy(()->new BookSeriesMapping(bookSeries, null, 1));
}

@Test
@DisplayName("throw a Null Pointer Exception on an attempt to create with Null Book Series.")
void notAcceptNullBookSeries(){

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

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

assertThatExceptionOfType(NullPointerException.class)
.isThrownBy(()->new BookSeriesMapping(null, book, 1));
}
}
33 changes: 33 additions & 0 deletions src/test/java/com/karankumar/booksapi/model/BookSeriesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2021 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
* License, or (at your option) any later version.

* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.

* You should have received a copy of the GNU General Public License along with this program.
* If not, see <https://www.gnu.org/licenses/>.
*/

package com.karankumar.booksapi.model;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

@DisplayName("Book series should")
public class BookSeriesTest {

@Test
@DisplayName("throw a null pointer exception on an attempt to create with a null Series Name.")
void notAcceptNullSeriesName(){
assertThatExceptionOfType(NullPointerException.class)
.isThrownBy( ()->new BookSeries(null) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ class AuthorRepositoryTest {

private final BookRepository bookRepository;
private final AuthorRepository authorRepository;
private final BookSeriesMappingRepository bookSeriesMappingRepository;

@Autowired
AuthorRepositoryTest(BookRepository bookRepository, AuthorRepository authorRepository) {
AuthorRepositoryTest(BookRepository bookRepository, AuthorRepository authorRepository, BookSeriesMappingRepository bookSeriesMappingRepository) {
this.bookRepository = bookRepository;
this.authorRepository = authorRepository;
this.bookSeriesMappingRepository = bookSeriesMappingRepository;
}

@BeforeEach
void setUp() {
bookSeriesMappingRepository.deleteAll();
authorRepository.deleteAll();
bookRepository.deleteAll();
}
Expand Down
Loading