package com.example.backend.controllers;

import java.util.List;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.backend.db.BookRepo;
import com.example.backend.models.Book;

@RestController
@RequestMapping("/books")
@CrossOrigin(origins = "http://localhost:4200/")
public class BookController {

    @PostMapping("/addBook")
    public int addBook(@RequestBody Book b){
        return new BookRepo().addBook(b);
    }

    @GetMapping("/getAllBooks")
    public List<Book> getAllBooks(){
        return new BookRepo().getAllBooks();
    }

     @PostMapping("/likeBook")
    public int likeBook(@RequestBody Book b){
        return new BookRepo().likeBook(b);
    }

     @PostMapping("/deleteBook")
    public int deleteBook(@RequestBody Book b){
        return new BookRepo().deleteBook(b);
    }
}
