package org.mockserver.examples.proxy.web.controller;

import org.mockserver.examples.proxy.service.BookService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import jakarta.annotation.Resource;

/**
 * @author jamesdbloom
 */
@Controller
public class BooksPageController {

    @Resource
    private BookService bookService;

    @RequestMapping(value = "/books", method = RequestMethod.GET)
    public String getBookList(Model model) {
        model.addAttribute("books", bookService.getAllBooks());
        return "books";
    }

    @RequestMapping(value = "/book/{id}", method = RequestMethod.GET)
    public String getBook(@PathVariable String id, Model model) {
        model.addAttribute("book", bookService.getBook(id));
        return "book";
    }

}
