Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ dependencies {

tasks.named('test') {
useJUnitPlatform()
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.getdata.restcall_test1.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.getdata.restcall_test1.Service.AuthorService;
import com.getdata.restcall_test1.Entity.Author;
import com.getdata.restcall_test1.Entity.Books;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

@RestController
public class AuthorController {
Expand All @@ -21,4 +23,21 @@ public AuthorController(AuthorService authorService) {
public Author getDetails(@PathVariable String AuthorID){
return authorService.getAuthorsByID(AuthorID);
}
}
@GetMapping("/getAuthorBooks/{AuthorID}")
public ResponseEntity<List<Books>> getBooksByAuthor(@PathVariable String AuthorID){
List<Books> books = authorService.getBooksByAuthorID(AuthorID);
if (books != null && !books.isEmpty()) {
return ResponseEntity.ok(books);
} else {
return ResponseEntity.notFound().build();
}
}
@PostMapping("/createAuthor")
public ResponseEntity<Void> createAuthor(@RequestBody Author author) {
authorService.createAuthor(author);
return new ResponseEntity<>(HttpStatus.CREATED);
}
}

//http://localhost:8080/getAuthor/B0000000
//http://localhost:8080/books/isbn/9780743210898
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import org.springframework.http.HttpStatus;
import java.util.List;

@RestController
Expand Down Expand Up @@ -45,12 +45,25 @@ public ResponseEntity<Books> getBookByISBN(@PathVariable String isbn) {
return ResponseEntity.notFound().build();
}
}
@PostMapping("/createBook")
public ResponseEntity<Void> createBook(@RequestBody Books book) {
booksService.createBook(book);
return new ResponseEntity<>(HttpStatus.CREATED);
}
}



//http://localhost:8080/books/Fantasy for genre
//http://localhost:8080/books/Best Sellers for best-seller
//http://localhost:8080/books/Fantasy for genre
//http://localhost:8080/books/Best Sellers for best-seller
//http://localhost:8080/books/publisher/discount?publisher=Bantam&discountPercent=5 discount for publisher
//http://localhost:8080/books/Vintage/5 a more simple way to update price
//GET http://localhost:8080/books/isbn/9780743210898 for isbn



//http://localhost:8080/books/genre/Fantasy for genre
//http://localhost:8080/books/best-sellers for best-seller
//http://localhost:8080/books/publisher/discount?publisher=Bantam&discountPercent=5 discount for publisher
//http://localhost:8080/books/Vintage/5 a more simple way to update price
//GET http://localhost:8080/books/isbn/9780743210898 for isbn
Expand Down

This file was deleted.

This file was deleted.

19 changes: 8 additions & 11 deletions src/main/java/com/getdata/restcall_test1/Entity/Author.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.getdata.restcall_test1.Entity;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;


@Entity
Expand All @@ -16,24 +18,19 @@ public Author(){
}

@Id
@Getter
@Setter
@Column(name = "AuthorID")
private String AuthorID;

@Getter
@Setter
@Column(name = "FirstName")
private String FirstName;

@Getter
@Setter
@Column(name = "LastName")
private String LastName;

public String getAuthorID(){
return this.AuthorID;
}

public String getFirstName(){
return this.FirstName;
}

public String getLastName(){
return this.LastName;
}
}
55 changes: 5 additions & 50 deletions src/main/java/com/getdata/restcall_test1/Entity/Books.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.getdata.restcall_test1.Entity;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -56,57 +57,11 @@ public Books() {}
@Column(name = "ISBN")
private String ISBN;

@Getter
@Setter
@JsonBackReference
@ManyToOne
@JoinColumn(name = "AuthorID")
private Author author;

}
















































}
48 changes: 0 additions & 48 deletions src/main/java/com/getdata/restcall_test1/Entity/CreditCard.java

This file was deleted.

49 changes: 0 additions & 49 deletions src/main/java/com/getdata/restcall_test1/Entity/User.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package com.getdata.restcall_test1.Repository;


import com.getdata.restcall_test1.Entity.Books;
import java.util.List;
import com.getdata.restcall_test1.Entity.Author;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface AuthorRepo extends JpaRepository<Author, String> {

@Query("SELECT b FROM Books b WHERE b.author.AuthorID = :authorId")
List<Books> findBooksByAuthorID(@Param("authorId") String authorId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public interface BookRepo extends JpaRepository<Books, String>{
@Query("SELECT b FROM Books b JOIN Rating r ON b.ISBN = r.ISBN WHERE r.rating = :rating")
List<Books> findBooksByRating(@Param("rating") int rating);

// Optional<Books> findById(Long id);
// Optional<Books> findById(Long id);

List<Books> findByPublisher(String publisher);

// Find a book by ISBN
Optional<Books> findById(String isbn);

}
}

This file was deleted.

Loading