package cz.muni.fi.pa165.facade;

import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cz.muni.fi.pa165.dto.BookDTO;
import cz.muni.fi.pa165.dto.CreateBookDTO;
import cz.muni.fi.pa165.entity.Book;
import cz.muni.fi.pa165.enums.BookState;
import cz.muni.fi.pa165.service.BookService;

/**
 * @author Michael Simacek
 *
 */
@Service
@Transactional
public class BookFacadeImpl implements BookFacade {

    @Inject
    ListMapper mapper;

    @Inject
    BookService service;

    @Override
    public void createBook(CreateBookDTO book) {
        service.create(mapper.map(book, Book.class));
    }

    @Override
    public BookDTO findById(Long id) {
        return mapper.map(service.findById(id), BookDTO.class);
    }

    @Override
    public List<BookDTO> findAll() {
        return mapper.map(service.findAll(), BookDTO.class);
    }

    @Override
    public void delete(Long bookId) {
        service.delete(service.findById(bookId));
    }

    @Override
    public void setState(Long bookId, BookState newState) {
        service.setState(service.findById(bookId), newState);
    }

    @Override
    public List<BookDTO> findByName(String name) {
        return mapper.map(service.findByName(name), BookDTO.class);
    }

}

@@ -351,16 +351,71 @@
 kState;%0A
+import cz.muni.fi.pa165.service.BookCollectionService;%0A
 import c
@@ -451,16 +451,16 @@
 ervice;%0A
-
 %0A/**%0A * 
@@ -641,16 +641,74 @@
 rvice;%0A%0A
+    @Inject%0A    BookCollectionService collectionService;%0A%0A
     @Ove
@@ -774,23 +774,22 @@
     
-service.create(
+Book entity = 
 mapp
@@ -812,16 +812,173 @@
 k.class)
+;%0A        for (Long id : book.getCollectionIds()) %7B%0A            entity.addCollection(collectionService.findById(id));%0A        %7D%0A        service.create(entity
 );%0A    %7D

Fix BookCollectionFacadeImpl.create