This repository has been archived by the owner on Mar 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Add series issue 6 #98
Closed
Closed
Changes from 47 commits
Commits
Show all changes
92 commits
Select commit
Hold shift + click to select a range
0686385
Add new entity representing series of books.
kev711 c5d2ca8
Add new entity mapping series of books and books with a serial order …
kev711 3590469
Add bookSeriesMapping to Book
kev711 b8aed12
Add copyright text
kev711 e21db5a
Update BookSeries entity's member "seriesName"
kev711 75ccd9d
Update BookSeriesMapping entity - Unique constraint, Relationship fie…
kev711 e0718d1
Add tests for entities Book Series Mapping and Book Series.
kev711 2af638c
Add boilerplate code for entity repositories.
kev711 eee400e
Add repository methods for Book, BookSeriesMapping
kev711 370dc0b
Add test classes for BookSeries & BookSeriesMapping repository
kev711 d10d705
Add new tests for Book repository
kev711 8309e31
Update setup method to clear tables with Foreign Key dependencies first
kev711 fe14f80
Fix test issues due to merge
kev711 d238142
Remove wildcard imports & adhere to 100 char limit
knjk04 2208799
Extract create book code to method
knjk04 ca46272
Extract create book code to method
knjk04 8dc9835
Add missing copyright notice
knjk04 9b37d9d
Extract create book code to method
knjk04 d0cde5c
Find by title
knjk04 254c14b
Extract duplicate code to method
knjk04 1688866
Resolve for PR-81 comments
kev711 5ba90da
Add DDL for Flyway migration.
kev711 11057c4
Add new entity representing series of books.
kev711 a293078
Add new entity mapping series of books and books with a serial order …
kev711 11ff6e4
Rebase onto main
kev711 c3826fb
Add copyright text
kev711 ebebbd5
Update BookSeries entity's member "seriesName"
kev711 789e0bd
Update BookSeriesMapping entity - Unique constraint, Relationship fie…
kev711 58ebd53
Add tests for entities Book Series Mapping and Book Series.
kev711 89248b0
Add boilerplate code for entity repositories.
kev711 fe11c63
Add repository methods for Book, BookSeriesMapping
kev711 5b7dc1c
Add test classes for BookSeries & BookSeriesMapping repository
kev711 346f344
Rebase onto main
kev711 84a2e53
Update setup method to clear tables with Foreign Key dependencies first
kev711 42a6622
Fix test issues due to merge
kev711 a78fc25
Remove wildcard imports & adhere to 100 char limit
knjk04 b62559f
Extract create book code to method
knjk04 7863aad
Extract create book code to method
knjk04 4327b42
Add missing copyright notice
knjk04 06ec459
Extract create book code to method
knjk04 4866d66
Find by title
knjk04 bfcc19c
Extract duplicate code to method
knjk04 f4fedf8
Resolve for PR-81 comments
kev711 d76c2d5
Add DDL for Flyway migration.
kev711 e36fc6e
Update tests to new model
kev711 0e04fdb
Merge remote-tracking branch 'origin/add-series-issue-6' into add-ser…
kev711 896946b
Use constants
knjk04 7ce51f1
Use constants for input arguments
knjk04 743b14e
Use Dgs constants
knjk04 fcd1008
Remove dependency in test
knjk04 719a313
Add book series to GraphQL schema
knjk04 690df7d
Remove unused variables
knjk04 bb3ca70
Remove BookRepository dependency
knjk04 33ba1fe
Merge branch 'main' of https://github.com/Project-Books/books-api int…
knjk04 0c8a58b
Use ID instead of Long
knjk04 bd97e70
Test findAllBooks()
knjk04 55054fb
Test findBookByIsbn13()
knjk04 0af57f1
Make findBookByIsbn13() nullable
knjk04 778096d
Test findByTitle() when title not matched
knjk04 bfb35fd
Remove comments
knjk04 afaa49e
Update query
knjk04 f44b0d0
Merge pull request #100 from Project-Books/codegen-63
knjk04 87fe614
Update to non-expiring Slack link
knjk04 0efc126
Test AuthorService
knjk04 c64ce11
Test Book Service
knjk04 2eecb66
Fix publisher book not saved
knjk04 9611f80
Merge pull request #106 from Project-Books/empty-publisher-book-table…
knjk04 dd067a0
Add new entity representing series of books.
kev711 28d3e3f
Add new entity mapping series of books and books with a serial order …
kev711 f206601
Rebase onto main
kev711 a204d88
Add copyright text
kev711 67f4009
Update BookSeries entity's member "seriesName"
kev711 5e29ba8
Update BookSeriesMapping entity - Unique constraint, Relationship fie…
kev711 ecb3100
Add tests for entities Book Series Mapping and Book Series.
kev711 2255b07
Add boilerplate code for entity repositories.
kev711 2144a9f
Add repository methods for Book, BookSeriesMapping
kev711 d3debb2
Add test classes for BookSeries & BookSeriesMapping repository
kev711 2bfae37
Rebase onto main
kev711 69e65ff
Fix test issues due to merge
kev711 58ae260
Remove wildcard imports & adhere to 100 char limit
knjk04 db84fa0
Extract create book code to method
knjk04 be0ee0b
Extract create book code to method
knjk04 6bd042c
Add missing copyright notice
knjk04 de6a3a7
Extract create book code to method
knjk04 530fe66
Find by title
knjk04 afad689
Extract duplicate code to method
knjk04 22a5c12
Resolve for PR-81 comments
kev711 2695743
Add DDL for Flyway migration.
kev711 9820824
Update tests to new model
kev711 cd3c9da
rebase from main (upstream)
kev711 166ec56
Resolve for PR-81 comments
kev711 517ccd8
Merge remote-tracking branch 'origin/add-series-issue-6' into add-ser…
kev711 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
51 changes: 51 additions & 0 deletions
51
src/main/java/com/karankumar/booksapi/model/BookSeries.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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 lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.NonNull; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.OneToMany; | ||
import java.util.List; | ||
|
||
@Entity | ||
@Getter | ||
@Setter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class BookSeries { | ||
@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; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/com/karankumar/booksapi/model/BookSeriesMapping.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
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"} | ||
), | ||
@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 seriesPosition; | ||
|
||
public BookSeriesMapping(@NonNull BookSeries bookSeries, @NonNull Book bookInSeries, | ||
@NonNull Integer seriesPosition) { | ||
this.bookSeries = bookSeries; | ||
this.book = bookInSeries; | ||
this.seriesPosition = seriesPosition; | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
src/main/java/com/karankumar/booksapi/repository/BookSeriesMappingRepository.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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> { | ||
@Query("SELECT a.book FROM BookSeriesMapping a WHERE a.bookSeries = ?1") | ||
List<Book> getAllBooksByBookSeries(BookSeries bookSeries); | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/karankumar/booksapi/repository/BookSeriesRepository.java
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
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> { | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CREATE TABLE `book_series` | ||
( | ||
`id` BIGINT NOT NULL AUTO_INCREMENT, | ||
`series_name` varchar(255) NOT NULL, | ||
|
||
PRIMARY KEY (`id`) | ||
|
||
) ENGINE=InnoDB |
15 changes: 15 additions & 0 deletions
15
src/main/resources/db/migration/V011_CREATE_BOOK_TO_BOOK_SERIES_MAPPING.sql
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
CREATE TABLE `book_to_book_series_mapping` | ||
( | ||
`id` bigint NOT NULL AUTO_INCREMENT, | ||
`serial_number` int NOT NULL, | ||
`book_id` bigint NOT NULL, | ||
`book_series_id` bigint NOT NULL, | ||
|
||
PRIMARY KEY (`id`), | ||
|
||
UNIQUE KEY `UK_bookSeriesId_bookId` (`book_series_id`,`book_id`), | ||
UNIQUE KEY `UK_bookSeriesId_serialNumber` (`book_series_id`,`serial_number`), | ||
CONSTRAINT `FK_book_id` FOREIGN KEY (`book_id`) REFERENCES `book` (`id`), | ||
CONSTRAINT `FK_book_series_id` FOREIGN KEY (`book_series_id`) REFERENCES `book_series` (`id`) | ||
|
||
) ENGINE=InnoDB |
67 changes: 67 additions & 0 deletions
67
src/test/java/com/karankumar/booksapi/model/BookSeriesMappingTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* 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") | ||
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"); | ||
Book book = createBook(); | ||
|
||
assertThatExceptionOfType(NullPointerException.class) | ||
.isThrownBy(() -> new BookSeriesMapping(bookSeries, book, null)); | ||
} | ||
|
||
private Book createBook() { | ||
Book book = new Book( | ||
"Harry Potter and the Philosopher's stone", | ||
Language.ENGLISH, | ||
"Sample blurb value", | ||
BookGenre.FANTASY, | ||
BookFormat.PAPERBACK | ||
); | ||
book.setYearOfPublication(1997); | ||
book.setIsbn13("9781408810545"); | ||
return book; | ||
} | ||
|
||
@Test | ||
@DisplayName("throw a Null Pointer Exception on an attempt to create with Null Book") | ||
void notAcceptNullBook() { | ||
|
||
BookSeries bookSeries = new BookSeries("Harry Potter Series"); | ||
|
||
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() { | ||
Book book = createBook(); | ||
|
||
assertThatExceptionOfType(NullPointerException.class) | ||
.isThrownBy(() -> new BookSeriesMapping(null, book, 1)); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/test/java/com/karankumar/booksapi/model/BookSeriesTest.java
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
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") | ||
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)); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a corresponding query to the GraphQL schema?