remy.liu 4 jaren geleden
bovenliggende
commit
32063011a4

+ 6 - 0
goods-service/src/main/java/com/remy/goods/controller/GoodsServiceController.java

@@ -5,6 +5,7 @@ import com.remy.goods.service.GoodsService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
 import java.util.UUID;
 
 @RestController
@@ -14,6 +15,11 @@ public class GoodsServiceController {
     @Autowired
     private GoodsService goodsService;
 
+    @RequestMapping()
+    public List<Goods> findAll() {
+        return goodsService.findAll();
+    }
+
     @RequestMapping("{serialNo}")
     public Goods findBySerialNo(@PathVariable("serialNo") String serialNo) {
         return goodsService.findBySerialNo(serialNo);

+ 2 - 1
goods-service/src/main/java/com/remy/goods/dao/GoodsDAO.java

@@ -1,11 +1,12 @@
 package com.remy.goods.dao;
 
 import com.remy.goods.entity.Goods;
+import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.repository.CrudRepository;
 
 import javax.persistence.Id;
 
-public interface GoodsDAO extends CrudRepository<Goods, Id> {
+public interface GoodsDAO extends JpaRepository<Goods, Id> {
 
     Goods findByName(String name);
 

+ 4 - 0
goods-service/src/main/java/com/remy/goods/service/GoodsService.java

@@ -2,8 +2,12 @@ package com.remy.goods.service;
 
 import com.remy.goods.entity.Goods;
 
+import java.util.List;
+
 public interface GoodsService {
 
+    List<Goods> findAll();
+
     Goods findBySerialNo(String serialNo);
 
     Goods save(Goods goods);

+ 6 - 0
goods-service/src/main/java/com/remy/goods/service/impl/GoodsServiceImpl.java

@@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.persistence.EntityNotFoundException;
+import java.util.List;
 
 @Service
 public class GoodsServiceImpl implements GoodsService {
@@ -14,6 +15,11 @@ public class GoodsServiceImpl implements GoodsService {
     @Autowired
     private GoodsDAO goodsDAO;
 
+    @Override
+    public List<Goods> findAll() {
+        return goodsDAO.findAll();
+    }
+
     @Override
     public Goods findBySerialNo(String serialNo) {
         Goods goods = goodsDAO.findGoodsBySerialNo(serialNo);

+ 0 - 1
graphql-api/src/main/java/com/remy/graphql/resolvers/mutation/GoodsMutation.java

@@ -2,7 +2,6 @@ package com.remy.graphql.resolvers.mutation;
 
 import com.remy.common.module.GoodsDTO;
 import com.remy.graphql.evn.RestAPIEnv;
-import com.remy.graphql.helper.BeanHelper;
 import graphql.kickstart.tools.GraphQLMutationResolver;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;

+ 14 - 0
graphql-api/src/main/java/com/remy/graphql/resolvers/query/GoodsQuery.java

@@ -4,9 +4,13 @@ import com.remy.common.module.GoodsDTO;
 import com.remy.graphql.evn.RestAPIEnv;
 import graphql.kickstart.tools.GraphQLQueryResolver;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpMethod;
 import org.springframework.stereotype.Component;
 import org.springframework.web.client.RestTemplate;
 
+import java.util.List;
 import java.util.concurrent.CompletableFuture;
 
 @Component
@@ -15,6 +19,16 @@ public class GoodsQuery implements GraphQLQueryResolver {
     @Autowired
     RestAPIEnv apiEnv;
 
+    public CompletableFuture<List<GoodsDTO>> goodsList() {
+        return CompletableFuture.supplyAsync(() ->
+                new RestTemplate().exchange(
+                        apiEnv.getGoodsEndpoint(),
+                        HttpMethod.GET,
+                        new HttpEntity(null),
+                        new ParameterizedTypeReference<List<GoodsDTO>>() {
+                        }).getBody());
+    }
+
     public CompletableFuture<GoodsDTO> goods(String serialNo) {
         return CompletableFuture.supplyAsync(() ->
                 new RestTemplate().getForObject(apiEnv.getGoodsEndpoint() + serialNo, GoodsDTO.class));

+ 1 - 0
graphql-api/src/main/resources/goods.graphqls

@@ -1,5 +1,6 @@
 type Query{
     goods(serialNo: String!): Goods!
+    goodsList: [Goods]
 }
 
 type Mutation{