diff --git a/app/src/GraphQLTest.tsx b/app/src/GraphQLTest.tsx index b2069e0..c817996 100644 --- a/app/src/GraphQLTest.tsx +++ b/app/src/GraphQLTest.tsx @@ -16,18 +16,18 @@ export default function GraphQLTest() { const [iterations, setIterations] = useState(0); const [completedRun, setCompletedRun] = useState(""); - const getJsRoute = "http://127.0.0.1:3001/spacex/graphql"; - const getPythonRoute = "http://127.0.0.1:8080/python/graphql/get?"; - const getGoRoute = "http://127.0.0.1:8083/go/graphql/get"; - - useEffect(() => { - console.log("adsfadf"); - fetch(getGoRoute) - .then((response) => { - if (response.ok) return response.json(); - }) - .then((res) => console.log(res)); - }, []); + const getJsRoute = "http://192.168.81.153:3001/spacex/graphql"; + const getPythonRoute = "http://192.168.81.153:8080/python/graphql/get?"; + const getGoRoute = "http://192.168.81.153:8083/go/graphql/get"; + + // useEffect(() => { + // console.log("adsfadf"); + // fetch(getGoRoute) + // .then((response) => { + // if (response.ok) return response.json(); + // }) + // .then((res) => console.log(res)); + // }, []); const options = [ { diff --git a/app/src/Home.tsx b/app/src/Home.tsx index 270fbd7..1dbedd7 100644 --- a/app/src/Home.tsx +++ b/app/src/Home.tsx @@ -251,9 +251,9 @@ function App() {

Test API Response Times (GraphQL)

- + {/*

Test Fetch Response Time

- + */}

Queries being Run

diff --git a/errors.txt b/errors.txt new file mode 100644 index 0000000..9b14b20 --- /dev/null +++ b/errors.txt @@ -0,0 +1,3 @@ +Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) + +Fix: \ No newline at end of file diff --git a/java-backend/demo/src/main/java/com/example/demo/CategoryRepo.java b/java-backend/demo/src/main/java/com/example/demo/CategoryRepo.java index ae7855e..c832b4e 100644 --- a/java-backend/demo/src/main/java/com/example/demo/CategoryRepo.java +++ b/java-backend/demo/src/main/java/com/example/demo/CategoryRepo.java @@ -1,10 +1,11 @@ -package com.example.demo; +// package com.example.demo; -import org.springframework.stereotype.Repository; -import org.springframework.data.jpa.repository.*; +// import org.springframework.stereotype.Repository; +// import org.springframework.data.jpa.repository.*; -@Repository -public interface CategoryRepo extends JpaRepository { - @Query(value = "INSERT INTO category (categoryName, description, picture) VALUES ('Seafood', 'tasty', null)") - void insertCategory(); -} +// @Repository +// public interface CategoryRepo extends JpaRepository { +// @Query(value = "INSERT INTO category (categoryName, description, picture) +// VALUES ('Seafood', 'tasty', null)") +// void insertCategory(); +// } diff --git a/java-backend/demo/src/main/java/com/example/demo/FirstController.java b/java-backend/demo/src/main/java/com/example/demo/FirstController.java index f4cc728..b74b3d9 100644 --- a/java-backend/demo/src/main/java/com/example/demo/FirstController.java +++ b/java-backend/demo/src/main/java/com/example/demo/FirstController.java @@ -5,31 +5,46 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; -import org.springframework.web.bind.annotation.RequestParam; +import java.lang.String; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; @RestController @CrossOrigin +@RequestMapping public class FirstController { + // private CategoryRepo repo; @Autowired - private CategoryRepo repo; private ShipperRepo shippers; - private SalesRepo sales; + @Autowired + private UpdateProductService productService; + // private SalesRepo sales; - @GetMapping("/category") - public List index() { - return repo.findAll(); - } + // @GetMapping("/category") + // public List index() { + // return repo.findAll(); + // } @GetMapping("/shippers") public List allShippers() { return shippers.findAll(); } - @GetMapping("/delete-sales") - public String deleteSales() { - sales.deleteByOrderIdDescLimitOne(); - return "1 Sales deleted"; + @RequestMapping(value = "/product", method = { RequestMethod.GET, RequestMethod.PUT }) + public Product updateProductName() { + + return productService.updateProduct(); } + // @GetMapping("/delete-sales") + // public String deleteSales() { + // sales.deleteByOrderIdDescLimitOne(); + // return "1 Sales deleted"; + // } + } diff --git a/java-backend/demo/src/main/java/com/example/demo/Product.java b/java-backend/demo/src/main/java/com/example/demo/Product.java index 3fea8fb..a7ff4ba 100644 --- a/java-backend/demo/src/main/java/com/example/demo/Product.java +++ b/java-backend/demo/src/main/java/com/example/demo/Product.java @@ -23,4 +23,10 @@ public class Product { private short unitsOnOrder; private short reorderLevel; private char discontinued; + + // productName = 'Product 1' + + public void setProductName(String name) { + this.productName = name; + } } diff --git a/java-backend/demo/src/main/java/com/example/demo/ProductRepo.java b/java-backend/demo/src/main/java/com/example/demo/ProductRepo.java index e790460..bcdd846 100644 --- a/java-backend/demo/src/main/java/com/example/demo/ProductRepo.java +++ b/java-backend/demo/src/main/java/com/example/demo/ProductRepo.java @@ -1,10 +1,14 @@ package com.example.demo; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; -public interface ProductRepo extends JpaRepository { +public interface ProductRepo extends JpaRepository { + + // @Modifying + // @Query(value = "UPDATE product SET productName = 'Product 1' WHERE productId + // = 55", nativeQuery = true) + // String updateProduct(); - @Query(value = "UPDATE product SET productName = 'Product 1' WHERE productId = 55") - void updateProduct(); } diff --git a/java-backend/demo/src/main/java/com/example/demo/SalesOrder.java b/java-backend/demo/src/main/java/com/example/demo/SalesOrder.java index 37bebbd..d93167f 100644 --- a/java-backend/demo/src/main/java/com/example/demo/SalesOrder.java +++ b/java-backend/demo/src/main/java/com/example/demo/SalesOrder.java @@ -1,5 +1,5 @@ -package com.example.demo; +// package com.example.demo; -public class SalesOrder { +// public class SalesOrder { -} +// } diff --git a/java-backend/demo/src/main/java/com/example/demo/SalesRepo.java b/java-backend/demo/src/main/java/com/example/demo/SalesRepo.java index f87019f..a6b9192 100644 --- a/java-backend/demo/src/main/java/com/example/demo/SalesRepo.java +++ b/java-backend/demo/src/main/java/com/example/demo/SalesRepo.java @@ -1,9 +1,9 @@ -package com.example.demo; +// package com.example.demo; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; +// import org.springframework.data.jpa.repository.JpaRepository; +// import org.springframework.data.jpa.repository.Query; -public interface SalesRepo extends JpaRepository { - @Query(value = "DELETE from salesorder ORDER BY orderId DESC limit 1") - void deleteByOrderIdDescLimitOne(); -} +// public interface SalesRepo extends JpaRepository { +// @Query(value = "DELETE from salesorder ORDER BY orderId DESC limit 1") +// void deleteByOrderIdDescLimitOne(); +// } diff --git a/java-backend/demo/src/main/java/com/example/demo/UpdateProductService.java b/java-backend/demo/src/main/java/com/example/demo/UpdateProductService.java new file mode 100644 index 0000000..c1f4734 --- /dev/null +++ b/java-backend/demo/src/main/java/com/example/demo/UpdateProductService.java @@ -0,0 +1,32 @@ +package com.example.demo; + +import com.example.demo.Product; +import com.example.demo.ProductRepo; +import org.springframework.beans.factory.annotation.*; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Optional; + +@Service +@RequestMapping +@CrossOrigin +public class UpdateProductService { + + @Autowired + private ProductRepo productRepo; + + public Product updateProduct() { + Optional optionalProduct = productRepo.findById(55); + if (optionalProduct.isPresent()) { + Product product = optionalProduct.get(); + product.setProductName("Product 1"); + + return productRepo.save(product); + } + return null; // or throw an exception + } + +} diff --git a/python-backend/__pycache__/fetch.cpython-38.pyc b/python-backend/__pycache__/fetch.cpython-38.pyc new file mode 100644 index 0000000..e956a2e Binary files /dev/null and b/python-backend/__pycache__/fetch.cpython-38.pyc differ diff --git a/app/src/Fetch_files/fetch.py b/python-backend/fetch.py similarity index 100% rename from app/src/Fetch_files/fetch.py rename to python-backend/fetch.py diff --git a/python-backend/main.py b/python-backend/main.py index be7d3f0..8948854 100644 --- a/python-backend/main.py +++ b/python-backend/main.py @@ -1,6 +1,10 @@ import mysql.connector from flask import Flask, jsonify, request from flask_cors import CORS, cross_origin +from fetch import getData + +import subprocess + import requests app = Flask(__name__) @@ -56,11 +60,6 @@ def requesting(): for x in range(int(iterations)): mydbcursor = executeSelect() returnData.append(mydbcursor) - # mycursor.execute("SELECT * FROM shipper") - # queryResult = mycursor.fetchall() - # print(queryResult) - # print(data) - # mycursor.close() return jsonify(returnData) @@ -134,6 +133,10 @@ def getCeoRoadster(): print(r.text) return result +def requestPerson(): + result = getData() + return result.stdout.decode('utf-8') + if __name__ == '__main__': app.run(host='192.168.81.153', port=8080)