Skip to content

Commit

Permalink
updated java files
Browse files Browse the repository at this point in the history
  • Loading branch information
czhou578 committed Jun 14, 2024
1 parent 0f51202 commit e281f50
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 51 deletions.
24 changes: 12 additions & 12 deletions app/src/GraphQLTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down
4 changes: 2 additions & 2 deletions app/src/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ function App() {
<Link to={"/graphql"}>
<h3>Test API Response Times (GraphQL)</h3>
</Link>
<Link to={"/requests"}>
{/* <Link to={"/requests"}>
<h3>Test Fetch Response Time</h3>
</Link>
</Link> */}
</header>
<div style={{ color: "white", marginBottom: "10px" }}>
<h2>Queries being Run</h2>
Expand Down
3 changes: 3 additions & 0 deletions errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

Fix:
Original file line number Diff line number Diff line change
@@ -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<Category, Integer> {
@Query(value = "INSERT INTO category (categoryName, description, picture) VALUES ('Seafood', 'tasty', null)")
void insertCategory();
}
// @Repository
// public interface CategoryRepo extends JpaRepository<Category, Integer> {
// @Query(value = "INSERT INTO category (categoryName, description, picture)
// VALUES ('Seafood', 'tasty', null)")
// void insertCategory();
// }
Original file line number Diff line number Diff line change
Expand Up @@ -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<Category> index() {
return repo.findAll();
}
// @GetMapping("/category")
// public List<Category> index() {
// return repo.findAll();
// }

@GetMapping("/shippers")
public List<Shipper> 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";
// }

}
6 changes: 6 additions & 0 deletions java-backend/demo/src/main/java/com/example/demo/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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<Product, Long> {
public interface ProductRepo extends JpaRepository<Product, Integer> {

// @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();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.example.demo;
// package com.example.demo;

public class SalesOrder {
// public class SalesOrder {

}
// }
14 changes: 7 additions & 7 deletions java-backend/demo/src/main/java/com/example/demo/SalesRepo.java
Original file line number Diff line number Diff line change
@@ -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<SalesOrder, Long> {
@Query(value = "DELETE from salesorder ORDER BY orderId DESC limit 1")
void deleteByOrderIdDescLimitOne();
}
// public interface SalesRepo extends JpaRepository<SalesOrder, Long> {
// @Query(value = "DELETE from salesorder ORDER BY orderId DESC limit 1")
// void deleteByOrderIdDescLimitOne();
// }
Original file line number Diff line number Diff line change
@@ -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<Product> 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
}

}
Binary file added python-backend/__pycache__/fetch.cpython-38.pyc
Binary file not shown.
File renamed without changes.
13 changes: 8 additions & 5 deletions python-backend/main.py
Original file line number Diff line number Diff line change
@@ -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__)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

0 comments on commit e281f50

Please sign in to comment.