Skip to content

Commit

Permalink
update go files
Browse files Browse the repository at this point in the history
  • Loading branch information
czhou578 committed Jun 30, 2024
1 parent 84c71e5 commit bb34781
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 25 deletions.
31 changes: 23 additions & 8 deletions app/routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const jwt = require("jsonwebtoken");

const router = express.Router();

const MAX_RETRIES = 3;
const RETRY_DELAY = 1000; // 1 second

router.get("/javascript/all-customers", (_, res) => {
let sql = "SELECT * FROM customers";

Expand Down Expand Up @@ -54,14 +57,26 @@ router.get("/javascript/new-category", (_, res) => {
});

router.put("/javascript/update-customer", (_, res) => {
let sql = "Update product set productName = 'Product 1' where productId = 55";

database.query(sql, (error, _) => {
if (error) throw error;

res.status(200).send({ resp: "Data successfully Updated!" });
console.log("success!");
});
const updateProduct = (retries) => {
let sql = "UPDATE product SET productName = 'Product 1' WHERE productId = 55";

database.query(sql, (error, result) => {
if (error) {
if (error.code === 'ER_LOCK_WAIT_TIMEOUT' && retries > 0) {
console.log(`Lock wait timeout, retrying... (${retries} attempts left)`);
setTimeout(() => updateProduct(retries - 1), RETRY_DELAY);
} else {
console.error("Database error:", error);
res.status(500).send({ error: "An error occurred while updating the product" });
}
} else {
res.status(200).send({ resp: "Data successfully Updated!" });
console.log("success!");
}
});
};

updateProduct(MAX_RETRIES);
});

router.delete("/javascript/delete-salesorder", (_, res) => {
Expand Down
33 changes: 25 additions & 8 deletions app/src/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,36 @@ function App() {
languageSequence === "JavaScript, Go, Python, Java" &&
queryType === "JOIN"
) {
jsRouteWrapper(iterations, joinJSRoute, "JOIN");
goRouteWrapper(iterations, joinGoRoute, "JOIN");
pythonRouteWrapper(iterations, joinPythonRoute, "JOIN");
javaRouteWrapper(iterations, joinJavaRoute, "JOIN")
jsRouteWrapper(iterations, joinJSRoute, "GET");
goRouteWrapper(iterations, joinGoRoute, "GET");
pythonRouteWrapper(iterations, joinPythonRoute, "GET");
javaRouteWrapper(iterations, joinJavaRoute, "GET")

} else if (
languageSequence === "JavaScript, Go, Python, Java" &&
queryType === "INSERT"
) {
jsRouteWrapper(iterations, insertJSRoute, "INSERT");
goRouteWrapper(iterations, insertGoRoute, "INSERT");
pythonRouteWrapper(iterations, joinPythonRoute, "INSERT");
javaRouteWrapper(iterations, insertJavaRoute, "INSERT")
jsRouteWrapper(iterations, insertJSRoute, "POST");
goRouteWrapper(iterations, insertGoRoute, "POST");
pythonRouteWrapper(iterations, insertPythonRoute, "POST");
javaRouteWrapper(iterations, insertJavaRoute, "POST")

} else if (
languageSequence === "JavaScript, Go, Python, Java" &&
queryType === "UPDATE"
) {
jsRouteWrapper(iterations, updateJSRoute, "PUT");
goRouteWrapper(iterations, updateGoRoute, "PUT");
pythonRouteWrapper(iterations, updatePythonRoute, "PUT");
javaRouteWrapper(iterations, updateJavaRoute, "PUT")
} else if (
languageSequence === "JavaScript, Go, Python, Java" &&
queryType === "DELETE"
) {
jsRouteWrapper(iterations, deleteJSRoute, "DELETE");
goRouteWrapper(iterations, deleteGoRoute, "DELETE");
pythonRouteWrapper(iterations, deletePythonRoute, "DELETE");
javaRouteWrapper(iterations, deleteJavaRoute, "DELETE")
}
};

Expand Down
12 changes: 6 additions & 6 deletions go-backend/api/models/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

const dbuser = "root"
const dbpass = "password"
const dbpass = "Issaquah@411"
const dbname = "northwind"

type Shipper struct {
Expand All @@ -23,7 +23,7 @@ type EmployeeId struct {
}

func GetShippers() []Shipper {
db, err := sql.Open("mysql", dbuser+":"+dbpass+"@tcp(192.168.81.153:3306)/"+dbname)
db, err := sql.Open("mysql", dbuser+":"+dbpass+"@tcp(127.0.0.1:3306)/"+dbname)

if err != nil {
fmt.Println("error", err.Error())
Expand Down Expand Up @@ -60,7 +60,7 @@ func GetShippers() []Shipper {
}

func GetCountNumId() []EmployeeId {
db, err := sql.Open("mysql", dbuser+":"+dbpass+"@tcp(192.168.81.153:3306)/"+dbname)
db, err := sql.Open("mysql", dbuser+":"+dbpass+"@tcp(127.0.0.1:3306)/"+dbname)
if err != nil {
fmt.Println("error", err.Error())
return nil
Expand Down Expand Up @@ -95,7 +95,7 @@ func GetCountNumId() []EmployeeId {
}

func NewCategoryInsert() int64 {
db, err := sql.Open("mysql", dbuser+":"+dbpass+"@tcp(192.168.81.153:3306)/"+dbname)
db, err := sql.Open("mysql", dbuser+":"+dbpass+"@tcp(127.0.0.1:3306)/"+dbname)

if err != nil {
log.Fatal(err)
Expand All @@ -120,7 +120,7 @@ func NewCategoryInsert() int64 {
}

func UpdateCustomer() int64 {
db, err := sql.Open("mysql", dbuser+":"+dbpass+"@tcp(192.168.81.153:3306)/"+dbname)
db, err := sql.Open("mysql", dbuser+":"+dbpass+"@tcp(127.0.0.1:3306)/"+dbname)

if err != nil {
log.Fatal(err)
Expand All @@ -144,7 +144,7 @@ func UpdateCustomer() int64 {
}

func DeleteSalesOrder() int64 {
db, err := sql.Open("mysql", dbuser+":"+dbpass+"@tcp(192.168.81.153:3306)/"+dbname)
db, err := sql.Open("mysql", dbuser+":"+dbpass+"@tcp(127.0.0.1:3306)/"+dbname)

if err != nil {
log.Fatal(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.lang.String;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@RestController
@CrossOrigin
@RequestMapping
public class FirstController {

Expand All @@ -31,7 +32,8 @@ public List<Long> getEmployeeCountByRegion() {
return employeeTerritoryService.countEmployeesByRegion();
}

@GetMapping("/java/category")
@PostMapping("/java/category")
@CrossOrigin(origins = "*", allowedHeaders = "*", allowCredentials = "false")
public Category insertCategory() {
return categoryService.insertAndSaveCategory();
}
Expand All @@ -41,13 +43,16 @@ public List<Shipper> allShippers() {
return shippers.findAll();
}

@RequestMapping(value = "/java/product", method = { RequestMethod.GET, RequestMethod.PUT })
@PutMapping("/java/product")
@CrossOrigin(origins = "*", allowedHeaders = "*", allowCredentials = "false")
public Product updateProductName() {

return productService.updateProduct();
}

@RequestMapping(value = "/java/delete-sales", method = { RequestMethod.DELETE })
@CrossOrigin(origins = "*", allowedHeaders = "*", allowCredentials = "false")

public String deleteSales() {
sales.deleteByOrderIdDescLimitOne();
return "1 Sales deleted";
Expand Down

0 comments on commit bb34781

Please sign in to comment.