|
|
@@ -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));
|