package cz.muni.fi.pa165.facade;

import cz.muni.fi.pa165.dto.BookCollectionDTO;
import cz.muni.fi.pa165.dto.BookDTO;
import cz.muni.fi.pa165.dto.CreateBookCollectionDTO;
import cz.muni.fi.pa165.entity.Book;
import cz.muni.fi.pa165.entity.BookCollection;
import cz.muni.fi.pa165.facade.BookCollectionFacade;
import cz.muni.fi.pa165.service.BookCollectionService;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import org.dozer.Mapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author xkubist
 */
@Service
@Transactional
public class BookCollectionFacadeImpl implements BookCollectionFacade{
    @Inject
    BookCollectionService service;
    
    @Inject
    Mapper mapper;

    @Override
     public void createBookCollection(CreateBookCollectionDTO bookCollection){
        service.create(mapper.map(bookCollection, BookCollection.class));
    }

    @Override
    public BookCollectionDTO findById(Long id){
        return mapper.map(service.findById(id), BookCollectionDTO.class);
    }
    
    @Override
    public List<BookCollectionDTO> findAll(){
        List<BookCollection> list = service.findAll();
        List<BookCollectionDTO> finalList = new ArrayList<>();
        for (BookCollection bookCollection : list) {
            finalList.add(mapper.map(bookCollection, BookCollectionDTO.class));
        }
        return finalList;
    }

    @Override
    public void delete(Long bookId){
        service.delete(service.findById(bookId));
    }
    
    @Override
    public void addBookToCollection(Long id,BookDTO bookDto){
        service.addBookToCollection(id, mapper.map(bookDto,Book.class));
    }
    
    @Override
    public void removeBookFromCollection(Long id,BookDTO bookDto){
        service.removeBookFromCollection(id, mapper.map(bookDto,Book.class));
    
    }


}
@@ -29,16 +29,244 @@
 ade;%0D%0A%0D%0A
+import java.util.ArrayList;%0D%0Aimport java.util.List;%0D%0A%0D%0Aimport javax.inject.Inject;%0D%0A%0D%0Aimport org.dozer.Mapper;%0D%0Aimport org.springframework.stereotype.Service;%0D%0Aimport org.springframework.transaction.annotation.Transactional;%0D%0A%0D%0A
 import c
@@ -487,62 +487,8 @@
 n;%0D%0A
-import cz.muni.fi.pa165.facade.BookCollectionFacade;%0D%0A
 impo
@@ -550,220 +550,44 @@
 ort 
-java.util.ArrayList;%0D%0Aimport java.util.List;%0D%0Aimport javax.inject.Inject;%0D%0Aimport org.dozer.Mapper;%0D%0Aimport org.springframework.stereotype.Service;%0D%0Aimport org.springframework.transaction.annotation.Transactional
+cz.muni.fi.pa165.service.BookService
 ;%0D%0A%0D
@@ -716,16 +716,17 @@
 onFacade
+ 
 %7B%0D%0A    @
@@ -769,20 +769,61 @@
 rvice;%0D%0A
+%0D%0A
     
+@Inject%0D%0A    BookService bookService;%0D%0A
 %0D%0A    @I
@@ -870,17 +870,16 @@
 de%0D%0A    
- 
 public v
@@ -942,16 +942,17 @@
 lection)
+ 
 %7B%0D%0A     
@@ -958,23 +958,32 @@
     
-service.create(
+BookCollection entity = 
 mapp
@@ -1022,24 +1022,177 @@
 ction.class)
+;%0D%0A        for (Long id : bookCollection.getBookIds()) %7B%0D%0A            entity.addBook(bookService.findById(id));%0D%0A        %7D%0D%0A        service.create(entity
 );%0D%0A    %7D%0D%0A%0D
@@ -1253,16 +1253,17 @@
 Long id)
+ 
 %7B%0D%0A     
@@ -1331,36 +1331,32 @@
 class);%0D%0A    %7D%0D%0A
-    
 %0D%0A    @Override%0D
@@ -1400,16 +1400,17 @@
 indAll()
+ 
 %7B%0D%0A     
@@ -1756,16 +1756,17 @@
  bookId)
+ 
 %7B%0D%0A     
@@ -1810,36 +1810,32 @@
 okId));%0D%0A    %7D%0D%0A
-    
 %0D%0A    @Override%0D
@@ -1871,32 +1871,33 @@
 lection(Long id,
+ 
 BookDTO bookDto)
@@ -1888,32 +1888,33 @@
 BookDTO bookDto)
+ 
 %7B%0D%0A        servi
@@ -1951,32 +1951,33 @@
 per.map(bookDto,
+ 
 Book.class));%0D%0A 
@@ -1982,20 +1982,16 @@
 %0A    %7D%0D%0A
-    
 %0D%0A    @O
@@ -2048,16 +2048,17 @@
 Long id,
+ 
 BookDTO 
@@ -2065,16 +2065,17 @@
 bookDto)
+ 
 %7B%0D%0A     
@@ -2133,16 +2133,17 @@
 bookDto,
+ 
 Book.cla
@@ -2149,20 +2149,16 @@
 ass));%0D%0A
-    
 %0D%0A    %7D%0D
@@ -2160,11 +2160,9 @@
    %7D%0D%0A%0D%0A
-%0D%0A
 %7D

Fix BookCollectionFacadeImpl.create