Skip to content

Commit fac21da

Browse files
feat:Added CRUD support for books and authors
Signed-off-by: Hitarth Hindocha <hindochahitarth@gmail.com>
1 parent e266fff commit fac21da

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

spring-boot-postgres-graphql/src/main/java/com/keploy/springbootpostgresgraphql/controller/BookController.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ public Boolean deleteAuthor(@Argument int id) {
115115
return true;
116116
}
117117

118+
@MutationMapping
119+
public Author updateAuthor(@Argument int id, @Argument AuthorInput author) {
120+
Author existingAuthor = authorRepository.findAuthorById(id);
121+
if (existingAuthor != null) {
122+
existingAuthor.setFirstName(author.getFirstName());
123+
existingAuthor.setLastName(author.getLastName());
124+
return authorRepository.save(existingAuthor);
125+
}
126+
return null;
127+
}
128+
118129
@MutationMapping
119130
public Category addCategory(@Argument CategoryInput category) {
120131
Category newCategory = new Category();

spring-boot-postgres-graphql/src/main/resources/graphql/schema.graphqls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type Mutation {
1313
updateBook(id: ID!, book: BookInput!): Book
1414
deleteBook(id: ID!): Boolean
1515
addAuthor(author: AuthorInput!): Author
16+
updateAuthor(id: ID!, author: AuthorInput!): Author
1617
deleteAuthor(id: ID!): Boolean
1718
addCategory(category: CategoryInput!): Category
1819
}

0 commit comments

Comments
 (0)