const bookService = require('../services/bookService');

exports.searchBooks = async (req, res) => {
    try {
        const query = req.query.q || "";
        const books = await bookService.searchBooks(query);
        res.json(books);
    } catch (error) {
        res.status(500).json({ message: "Qidiruvda xatolik yuz berdi" });
    }
};

exports.getBooks = async (req, res) => {
    try {
        const books = await bookService.getAllBooks();
        res.json(books);
    } catch (error) {
        res.status(500).json({ message: error.message });
    }
};

exports.createBook = async (req, res) => {
    try {
        const book = await bookService.addBook(req.body);
        res.status(201).json(book);
    } catch (error) {
        res.status(400).json({ message: error.message });
    }
};