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

Add series issue 6 #98

Closed
wants to merge 92 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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 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
1688866
Resolve for PR-81 comments
kev711 Mar 27, 2021
5ba90da
Add DDL for Flyway migration.
kev711 Mar 29, 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
896946b
Use constants
knjk04 Apr 21, 2021
7ce51f1
Use constants for input arguments
knjk04 Apr 21, 2021
743b14e
Use Dgs constants
knjk04 Apr 21, 2021
fcd1008
Remove dependency in test
knjk04 Apr 27, 2021
719a313
Add book series to GraphQL schema
knjk04 Apr 27, 2021
690df7d
Remove unused variables
knjk04 Apr 27, 2021
bb3ca70
Remove BookRepository dependency
knjk04 Apr 28, 2021
33ba1fe
Merge branch 'main' of https://github.com/Project-Books/books-api int…
knjk04 Apr 28, 2021
0c8a58b
Use ID instead of Long
knjk04 Apr 28, 2021
bd97e70
Test findAllBooks()
knjk04 Apr 28, 2021
55054fb
Test findBookByIsbn13()
knjk04 Apr 28, 2021
0af57f1
Make findBookByIsbn13() nullable
knjk04 Apr 28, 2021
778096d
Test findByTitle() when title not matched
knjk04 Apr 28, 2021
bfb35fd
Remove comments
knjk04 Apr 29, 2021
afaa49e
Update query
knjk04 Apr 29, 2021
f44b0d0
Merge pull request #100 from Project-Books/codegen-63
knjk04 Apr 29, 2021
87fe614
Update to non-expiring Slack link
knjk04 May 7, 2021
0efc126
Test AuthorService
knjk04 May 9, 2021
c64ce11
Test Book Service
knjk04 May 9, 2021
2eecb66
Fix publisher book not saved
knjk04 May 18, 2021
9611f80
Merge pull request #106 from Project-Books/empty-publisher-book-table…
knjk04 May 18, 2021
dd067a0
Add new entity representing series of books.
kev711 Mar 11, 2021
28d3e3f
Add new entity mapping series of books and books with a serial order …
kev711 Mar 11, 2021
f206601
Rebase onto main
kev711 Mar 11, 2021
a204d88
Add copyright text
kev711 Mar 14, 2021
67f4009
Update BookSeries entity's member "seriesName"
kev711 Mar 14, 2021
5e29ba8
Update BookSeriesMapping entity - Unique constraint, Relationship fie…
kev711 Mar 14, 2021
ecb3100
Add tests for entities Book Series Mapping and Book Series.
kev711 Mar 14, 2021
2255b07
Add boilerplate code for entity repositories.
kev711 Mar 14, 2021
2144a9f
Add repository methods for Book, BookSeriesMapping
kev711 Mar 21, 2021
d3debb2
Add test classes for BookSeries & BookSeriesMapping repository
kev711 Mar 21, 2021
2bfae37
Rebase onto main
kev711 Mar 21, 2021
69e65ff
Fix test issues due to merge
kev711 Mar 21, 2021
58ae260
Remove wildcard imports & adhere to 100 char limit
knjk04 Mar 25, 2021
db84fa0
Extract create book code to method
knjk04 Mar 25, 2021
be0ee0b
Extract create book code to method
knjk04 Mar 25, 2021
6bd042c
Add missing copyright notice
knjk04 Mar 25, 2021
de6a3a7
Extract create book code to method
knjk04 Mar 25, 2021
530fe66
Find by title
knjk04 Mar 25, 2021
afad689
Extract duplicate code to method
knjk04 Mar 25, 2021
22a5c12
Resolve for PR-81 comments
kev711 Mar 27, 2021
2695743
Add DDL for Flyway migration.
kev711 Mar 29, 2021
9820824
Update tests to new model
kev711 Apr 14, 2021
cd3c9da
rebase from main (upstream)
kev711 Mar 21, 2021
166ec56
Resolve for PR-81 comments
kev711 Mar 27, 2021
517ccd8
Merge remote-tracking branch 'origin/add-series-issue-6' into add-ser…
kev711 May 23, 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<img src="https://codecov.io/gh/Project-Books/books-api/branch/main/graph/badge.svg?token=5OF8MVDZW7"/>
</a>

<a href="https://join.slack.com/t/teambookproject/shared_invite/zt-ojsgamu9-O4v~714y6G1_0o7HtTZDqw">
<a href="https://join.slack.com/t/teambookproject/shared_invite/zt-punc8os7-Iz9PTCAkYcO_0S~XwtO5_A">
<img src="https://img.shields.io/badge/slack-teambookproject-4A154B?logo=slack" alt="Slack" />
</a>

Expand Down
10 changes: 8 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
buildscript {
dependencies {
classpath 'com.netflix.graphql.dgs.codegen:graphql-dgs-codegen-gradle:4.5.2'
}
}

plugins {
id 'org.springframework.boot' version '2.4.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'jacoco'
id "com.netflix.dgs.codegen" version "4.0.10"
id "org.flywaydb.flyway" version "7.5.4"
}

apply plugin: 'com.netflix.dgs.codegen'

group = 'com.karankumar'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
Expand All @@ -33,7 +40,6 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation "org.flywaydb:flyway-core:7.5.4"
// https://mvnrepository.com/artifact/commons-validator/commons-validator
implementation "commons-validator:commons-validator:1.7"

compileOnly 'org.projectlombok:lombok'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.util.List;
import java.util.Set;

@SpringBootApplication
Expand All @@ -44,7 +43,6 @@ public CommandLineRunner populateData(AuthorRepository authorRepository,
PublisherRepository publisherRepository) {
return args -> {
Publisher publisher = new Publisher("Bloomsbury");
publisherRepository.save(publisher);

Book book1 = createBook(
"Harry Potter and the Philosopher's stone",
Expand Down Expand Up @@ -77,6 +75,8 @@ public CommandLineRunner populateData(AuthorRepository authorRepository,
Author author = new Author("J.K. Rowling", Set.of(book1, book2, book3));
author.setAbout("A fantastic author");
authorRepository.save(author);

publisherRepository.save(publisher);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package com.karankumar.booksapi.datafetchers;

import com.karankumar.booksapi.DgsConstants;
import com.karankumar.booksapi.model.Book;
import com.karankumar.booksapi.service.BookService;
import com.netflix.graphql.dgs.DgsComponent;
Expand All @@ -31,23 +32,23 @@ public BookDataFetcher(BookService bookService) {
this.bookService = bookService;
}

@DgsData(parentType = "Query", field = "findAllBooks")
@DgsData(parentType = DgsConstants.QUERY_TYPE, field = DgsConstants.QUERY.FindAllBooks)
public List<Book> findAllBooks() {
return bookService.findAll();
}

@DgsData(parentType = "Query", field = "findBookByIsbn13")
public Book findBookByIsbn13(@InputArgument("isbn13") String isbn13) {
@DgsData(parentType = DgsConstants.QUERY_TYPE, field = DgsConstants.QUERY.FindBookByIsbn13)
public Book findBookByIsbn13(@InputArgument(DgsConstants.BOOK.Isbn13) String isbn13) {
return bookService.findBookByIsbn13(isbn13);
}

@DgsData(parentType = "Query", field = "findByAuthor")
public List<Book> findByAuthor(@InputArgument("fullName") String fullName) {
@DgsData(parentType = DgsConstants.QUERY_TYPE, field = DgsConstants.QUERY.FindByAuthor)
public List<Book> findByAuthor(@InputArgument(DgsConstants.AUTHOR.FullName) String fullName) {
return bookService.findByAuthor(fullName);
}

@DgsData(parentType = "Query", field = "findByTitleIgnoreCase")
public Book findByTitle(@InputArgument("title") String title) {
@DgsData(parentType = DgsConstants.QUERY_TYPE, field = DgsConstants.QUERY.FindByTitleIgnoreCase)
public Book findByTitle(@InputArgument(DgsConstants.BOOK.Title) String title) {
return bookService.findByTitle(title);
}
}
6 changes: 6 additions & 0 deletions src/main/java/com/karankumar/booksapi/model/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +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,6 +78,9 @@ public class Book {
@Column(nullable = false)
private BookFormat format;

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

public Book(@NonNull String title, @NonNull Language language, @NonNull String blurb,
@NonNull BookGenre genre, @NonNull BookFormat format) {
this.title = title;
Expand Down
51 changes: 51 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,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 src/main/java/com/karankumar/booksapi/model/BookSeriesMapping.java
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package com.karankumar.booksapi.mutations;

import com.karankumar.booksapi.DgsConstants;
import com.karankumar.booksapi.model.Author;
import com.karankumar.booksapi.service.AuthorService;
import com.netflix.graphql.dgs.DgsComponent;
Expand All @@ -31,9 +32,9 @@ public AuthorMutation(AuthorService authorService) {
this.authorService = authorService;
}

@DgsData(parentType = "Mutation", field = "addAuthor")
@DgsData(parentType = DgsConstants.MUTATION.TYPE_NAME, field = DgsConstants.MUTATION.AddAuthor)
public Author addAuthor(DataFetchingEnvironment dataFetchingEnvironment) {
String fullName = dataFetchingEnvironment.getArgument("fullName");
String fullName = dataFetchingEnvironment.getArgument(DgsConstants.AUTHOR.FullName);
return authorService.save(new Author(fullName, new HashSet<>()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package com.karankumar.booksapi.mutations;

import com.karankumar.booksapi.DgsConstants;
import com.karankumar.booksapi.exception.InvalidISBN10Exception;
import com.karankumar.booksapi.exception.InvalidISBN13Exception;
import com.karankumar.booksapi.model.Book;
Expand All @@ -37,29 +38,30 @@ public BookMutation(BookService bookService) {
}

// TODO: change this to update a book rather than updating a specific field
@DgsData(parentType = "Mutation", field = "addIsbn13")
@DgsData(parentType = DgsConstants.MUTATION.TYPE_NAME, field = DgsConstants.MUTATION.AddIsbn13)
public Book addIsbn13(DataFetchingEnvironment dataFetchingEnvironment)
throws InvalidISBN10Exception, InvalidISBN13Exception {
Optional<Book> optionalBook = bookService.findById(
dataFetchingEnvironment.getArgument("bookId")
dataFetchingEnvironment.getArgument(DgsConstants.BOOK.Id)
);

if (optionalBook.isEmpty()) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, NOT_FOUND_ERROR_MESSAGE);
}

String isbn13 = dataFetchingEnvironment.getArgument("isbn13");
String isbn13 = dataFetchingEnvironment.getArgument(DgsConstants.BOOK.Isbn13);
Book book = optionalBook.get();
book.setIsbn13(isbn13);
return bookService.save(optionalBook.get());
}

@DgsData(parentType = "Mutation", field = "deleteBook")
@DgsData(parentType = DgsConstants.MUTATION.TYPE_NAME, field = DgsConstants.MUTATION.DeleteBook)
public Book deleteBook(DataFetchingEnvironment dataFetchingEnvironment) {
Long id = dataFetchingEnvironment.getArgument("bookId");
if (id == null) {
String stringId = dataFetchingEnvironment.getArgument(DgsConstants.BOOK.Id);
if (stringId == null) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, NOT_FOUND_ERROR_MESSAGE);
}
Long id = Long.parseLong(stringId);

Optional<Book> book = bookService.findById(id);
if (book.isEmpty()) {
Expand Down
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,11 @@ public interface BookRepository extends CrudRepository<Book, Long> {
Book findBookByIsbn13(String isbn13);

Book findByTitleIgnoreCase(String title);

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

@Query("SELECT a.seriesPosition 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,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);
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 add a corresponding query to the GraphQL schema?

}
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 was deleted.

Loading