diff --git a/src/main/java/com/loafle/bridge/collector/CollectorController.java b/src/main/java/com/loafle/bridge/collector/CollectorController.java index 1b4cd6f..243e4c3 100644 --- a/src/main/java/com/loafle/bridge/collector/CollectorController.java +++ b/src/main/java/com/loafle/bridge/collector/CollectorController.java @@ -1,7 +1,23 @@ package com.loafle.bridge.collector; +import com.loafle.bridge.discoveryservice.entity.DiscoveryService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + /** * Created by root on 16. 11. 15. */ public class CollectorController { + + @Autowired + private CollectorRepository repository; + + @RequestMapping(value = "/collector/{productId}", method = RequestMethod.GET) + public Collector get(@PathVariable(value = "productId") long productId) { + return repository.findByPID(productId); + } + + } diff --git a/src/main/java/com/loafle/bridge/collector/CollectorRepository.java b/src/main/java/com/loafle/bridge/collector/CollectorRepository.java index b10c8e5..e925b97 100644 --- a/src/main/java/com/loafle/bridge/collector/CollectorRepository.java +++ b/src/main/java/com/loafle/bridge/collector/CollectorRepository.java @@ -1,7 +1,8 @@ package com.loafle.bridge.collector; -import com.loafle.bridge.collector.Collector; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.data.rest.core.annotation.RepositoryRestResource; /** @@ -10,4 +11,6 @@ import org.springframework.data.rest.core.annotation.RepositoryRestResource; @RepositoryRestResource(collectionResourceRel = "collector", path = "collector") public interface CollectorRepository extends JpaRepository { + @Query("SELECT c FROM Collector c where c.productId = :productId") + Collector findByPID(@Param("productId") Long productId); }