package com.dassault_systemes.diy.web.endpoints;

import com.dassault_systemes.diy.domain.Tool;
import com.dassault_systemes.diy.repositories.ToolRepository;

import org.springframework.data.rest.webmvc.RepositoryRestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.inject.Inject;

import java.util.List;

import static org.springframework.web.bind.annotation.RequestMethod.GET;

@RepositoryRestController
@RequestMapping(value = "/tools")
public class ToolController {

    private final ToolRepository repository;

    @Inject
    ToolController(ToolRepository repository) {
        this.repository = repository;
    }

    @RequestMapping(value = "/search", method = GET)
    @ResponseBody
    public List<Tool> search(@RequestParam("query") String searchQuery) {
        return repository.search(searchQuery);
    }

}

@@ -200,32 +200,202 @@
 mvc.
-RepositoryRestController
+PersistentEntityResourceAssembler;%0Aimport org.springframework.data.rest.webmvc.RepositoryRestController;%0Aimport org.springframework.hateoas.Resource;%0Aimport org.springframework.hateoas.Resources
 ;%0Aim
@@ -705,16 +705,94 @@
 d.GET;%0A%0A
+/**%0A * custom Spring Data Rest method, exposed with ALPS/HATEOAS metadata%0A */%0A
 @Reposit
@@ -1111,18 +1111,33 @@
 lic 
-List
+Resources%3CResource
 %3CTool%3E
+%3E
  sea
@@ -1185,57 +1185,485 @@
 uery
-) %7B%0A        return repository.search(searchQuery)
+,%0A                                            PersistentEntityResourceAssembler persistentEntityResourceAssembler) %7B%0A        List%3CTool%3E tools = repository.search(searchQuery);%0A        Resources%3CResource%3CTool%3E%3E resources = Resources.wrap(tools);%0A        resources.forEach(toolResource -%3E toolResource%0A                .add(persistentEntityResourceAssembler.getSelfLinkFor(toolResource.getContent())));%0A        //TODO add links section to the current path%0A        return resources
 ;%0A  

add HATEOAS metadata on the custom /api/tools/search spring data rest method