package com.bookstore.action.api.books;

import com.bookstore.model.Book;
import com.bookstore.service.BookService;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * Class ListAction
 */
@Controller("apiBookListController")
@Scope("prototype")
@Result(type="json", params = {
        "excludeProperties", "^bookList\\[\\d+\\]\\.category,^bookList\\[\\d+\\]\\.orderBooks"
})
public class ListAction extends ActionSupport {
    private List<Book> bookList = null;

    @Autowired
    private transient BookService bookService;

    @Action("list")
    public String execute() {
        bookList = bookService.findAll("", 0, bookService.count(""));
        return SUCCESS;
    }

    public List<Book> getBookList() {
        return bookList;
    }

    public void setBookList(List<Book> bookList) {
        this.bookList = bookList;
    }
}
