Skip to content

Commit

Permalink
Menos código duplicado
Browse files Browse the repository at this point in the history
  • Loading branch information
CANCI0 committed Apr 7, 2024
1 parent f13cdbf commit c6af312
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,21 @@ app.post("/adduser", async (req, res) => {
}
});

app.get("/userInfo", async (req, res) => {
const handleRequest = async (req, res, serviceUrl) => {
try {
// Forward the question request to the user service
const userResponse = await axios.get(
userServiceUrl + "/userInfo",
{ params: req.query }
);
res.json(userResponse.data);
const response = await axios.get(serviceUrl, { params: req.query });
res.json(response.data);
} catch (error) {
returnError(res, error);
}
}

app.get("/userInfo", async (req, res) => {
handleRequest(req, res, userServiceUrl + "/userInfo");
});

app.get("/friends", async (req, res) => {
handleRequest(req, res, userServiceUrl + "/friends");
});

app.post("/saveGameList", async (req, res) => {
Expand All @@ -82,19 +86,6 @@ app.post("/saveGameList", async (req, res) => {
}
});

app.get("/friends", async (req, res) => {
try {
// Forward the question request to the user service
const userResponse = await axios.get(
userServiceUrl + "/friends",
{ params: req.query }
);
res.json(userResponse.data);
} catch (error) {
returnError(res, error);
}
});

app.get("/users/search", async (req, res) => {
try {
// Forward the question request to the user service
Expand Down

0 comments on commit c6af312

Please sign in to comment.