package com.midgetontoes.todolist.controller;

import com.midgetontoes.todolist.jpa.ListRepository;
import com.midgetontoes.todolist.model.List;
import com.midgetontoes.todolist.resource.ListResource;
import com.midgetontoes.todolist.resource.ListResourceAssembler;
import com.midgetontoes.todolist.service.ListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.Resources;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;
import java.util.Collection;
import java.util.Optional;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/lists")
public class ListRestController {

    @Autowired
    private ListService listService;

    @RequestMapping(method = RequestMethod.GET)
    public Resources<ListResource> readLists(Principal principal) {
        String username = principal.getName();
        ListResourceAssembler listResourceAssembler = new ListResourceAssembler();
        java.util.List<ListResource> lists = listService.findByUserUsername(username)
                .stream()
                .map(listResourceAssembler::toResource)
                .collect(Collectors.toList());
        return new Resources<ListResource>(lists);
    }

    @RequestMapping(value = "/{listId}", method = RequestMethod.GET)
    public ListResource readList(@PathVariable Long listId) {
        return new ListResourceAssembler().toResource(listService.findOne(listId));
    }
}

@@ -44,106 +44,8 @@
 r;%0A%0A
-import com.midgetontoes.todolist.jpa.ListRepository;%0Aimport com.midgetontoes.todolist.model.List;%0A
 impo
@@ -92,24 +92,24 @@
 stResource;%0A
+
 import com.m
@@ -609,100 +609,8 @@
 pal;
-%0Aimport java.util.Collection;%0Aimport java.util.Optional;%0Aimport java.util.stream.Collectors;
 %0A%0A@R
@@ -912,346 +912,124 @@
     
-ListResourceAssembler listResourceAssembler = new ListResourceAssembler();%0A        java.util.List%3CListResource%3E lists = listService.findByUserUsername(username)%0A                .stream()%0A                .map(listResourceAssembler::toResource)%0A                .collect(Collectors.toList());%0A        return new Resources%3CListResource%3E(lists
+return new Resources%3CListResource%3E(new ListResourceAssembler().toResources(listService.findByUserUsername(username))
 );%0A 

use resource assembler