package lan.dk.podcastserver.business;

import lan.dk.podcastserver.entity.Item;
import lan.dk.podcastserver.entity.WatchList;
import lan.dk.podcastserver.repository.ItemRepository;
import lan.dk.podcastserver.repository.WatchListRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Set;
import java.util.UUID;

/**
 * Created by kevin on 17/01/2016 for PodcastServer
 */
@Component
public class WatchListBusiness {

    private final WatchListRepository watchListRepository;
    private final ItemRepository itemRepository;

    @Autowired
    public WatchListBusiness(WatchListRepository watchListRepository, ItemRepository itemRepository) {
        this.watchListRepository = watchListRepository;
        this.itemRepository = itemRepository;
    }

    public WatchList findOne(UUID id) {
        return watchListRepository.findOne(id);
    }

    public List<WatchList> findAll() {
        return watchListRepository.findAll();
    }

    public Set<WatchList> findContainsItem(UUID itemId) {
        Item item = itemRepository.findOne(itemId);
        return watchListRepository.findContainsItem(item);
    }

    public WatchList add(UUID watchListId, UUID itemId) {
        WatchList watchList = watchListRepository.findOne(watchListId);
        Item item = itemRepository.findOne(itemId);

        return watchListRepository.save(watchList.add(item));
    }

    public WatchList remove(UUID watchListId, UUID itemId) {
        WatchList watchList = watchListRepository.findOne(watchListId);
        Item item = itemRepository.findOne(itemId);

        return watchListRepository.save(watchList.remove(item));
    }

    public void delete(UUID uuid) {
        watchListRepository.delete(uuid);
    }

    public WatchList save(WatchList watchList) {
        return watchListRepository.save(watchList);
    }
}

@@ -231,24 +231,63 @@
 Repository;%0A
+import lombok.RequiredArgsConstructor;%0A
 import org.s
@@ -337,16 +337,16 @@
 owired;%0A
-
 import o
@@ -527,16 +527,74 @@
 mponent%0A
+@RequiredArgsConstructor(onConstructor = @__(@Autowired))%0A
 public c
@@ -674,24 +674,24 @@
 Repository;%0A
+
     private 
@@ -732,235 +732,8 @@
 y;%0A%0A
-    @Autowired%0A    public WatchListBusiness(WatchListRepository watchListRepository, ItemRepository itemRepository) %7B%0A        this.watchListRepository = watchListRepository;%0A        this.itemRepository = itemRepository;%0A    %7D%0A%0A
     

refactor to use lombok for constructor