File structure updates
This commit is contained in:
@@ -1,74 +1,77 @@
|
||||
const axios = require('axios');
|
||||
const axios = require("axios");
|
||||
|
||||
// Middleware function to fetch clubs data
|
||||
const fetchClubsData = async (req, res, next) => {
|
||||
try {
|
||||
// Extract club ID from the URL
|
||||
const clubID = req.params.clubID;
|
||||
try {
|
||||
// Extract club ID from the URL
|
||||
const clubID = req.params.clubID;
|
||||
|
||||
// Make GET request to the API endpoint using the club ID
|
||||
const response = await axios.get(`http://api.football-data.org/v4/teams/${clubID}/?offset=&limit=`, {
|
||||
headers: {
|
||||
'X-Auth-Token': '0aa1ed31245d4a36b1ef5a79150324b3', // Add your API key here
|
||||
},
|
||||
});
|
||||
// Make GET request to the API endpoint using the club ID
|
||||
const response = await axios.get(
|
||||
`http://api.football-data.org/v4/teams/${clubID}/?offset=&limit=`,
|
||||
{
|
||||
headers: {
|
||||
"X-Auth-Token": "0aa1ed31245d4a36b1ef5a79150324b3", // Add your API key here
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
// Extract relevant data from the API response
|
||||
const clubData = response.data;
|
||||
// res.locals.user = users
|
||||
// Attach the data to res.locals
|
||||
res.locals.club = {
|
||||
area: {
|
||||
id: clubData.area.id,
|
||||
name: clubData.area.name,
|
||||
code: clubData.area.code,
|
||||
club_flag: clubData.area.flag,
|
||||
},
|
||||
club_id: clubData.id,
|
||||
name: clubData.name,
|
||||
shortName: clubData.shortName,
|
||||
tla: clubData.tla,
|
||||
crest: clubData.crest,
|
||||
address: clubData.address,
|
||||
website: clubData.website,
|
||||
founded: clubData.founded,
|
||||
clubColors: clubData.clubColors,
|
||||
venue: clubData.venue,
|
||||
runningCompetitions: clubData.runningCompetitions.map(competition => ({
|
||||
id: competition.id,
|
||||
name: competition.name,
|
||||
code: competition.code,
|
||||
type: competition.type,
|
||||
emblem: competition.emblem
|
||||
})),
|
||||
coach: {
|
||||
id: clubData.coach.id,
|
||||
firstName: clubData.coach.firstName,
|
||||
lastName: clubData.coach.lastName,
|
||||
name: clubData.coach.name,
|
||||
dateOfBirth: clubData.coach.dateOfBirth,
|
||||
nationality: clubData.coach.nationality,
|
||||
contract: {
|
||||
start: clubData.coach.contract.start,
|
||||
until: clubData.coach.contract.until
|
||||
}
|
||||
},
|
||||
squad: clubData.squad.map(player => ({
|
||||
id: player.id,
|
||||
name: player.name,
|
||||
position: player.position,
|
||||
dateOfBirth: player.dateOfBirth,
|
||||
nationality: player.nationality
|
||||
})),
|
||||
staff: clubData.staff,
|
||||
lastUpdated: clubData.lastUpdated
|
||||
};
|
||||
next();
|
||||
} catch (error) {
|
||||
console.error('Error fetching clubs data:', error);
|
||||
res.locals.club = null; // Set to null if there's an error
|
||||
next(); // Call next middleware or route handler
|
||||
}
|
||||
// Extract relevant data from the API response
|
||||
const clubData = response.data;
|
||||
// res.locals.user = users
|
||||
// Attach the data to res.locals
|
||||
res.locals.club = {
|
||||
area: {
|
||||
id: clubData.area.id,
|
||||
name: clubData.area.name,
|
||||
code: clubData.area.code,
|
||||
club_flag: clubData.area.flag,
|
||||
},
|
||||
club_id: clubData.id,
|
||||
name: clubData.name,
|
||||
shortName: clubData.shortName,
|
||||
tla: clubData.tla,
|
||||
crest: clubData.crest,
|
||||
address: clubData.address,
|
||||
website: clubData.website,
|
||||
founded: clubData.founded,
|
||||
clubColors: clubData.clubColors,
|
||||
venue: clubData.venue,
|
||||
runningCompetitions: clubData.runningCompetitions.map((competition) => ({
|
||||
id: competition.id,
|
||||
name: competition.name,
|
||||
code: competition.code,
|
||||
type: competition.type,
|
||||
emblem: competition.emblem,
|
||||
})),
|
||||
coach: {
|
||||
id: clubData.coach.id,
|
||||
firstName: clubData.coach.firstName,
|
||||
lastName: clubData.coach.lastName,
|
||||
name: clubData.coach.name,
|
||||
dateOfBirth: clubData.coach.dateOfBirth,
|
||||
nationality: clubData.coach.nationality,
|
||||
contract: {
|
||||
start: clubData.coach.contract.start,
|
||||
until: clubData.coach.contract.until,
|
||||
},
|
||||
},
|
||||
squad: clubData.squad.map((player) => ({
|
||||
id: player.id,
|
||||
name: player.name,
|
||||
position: player.position,
|
||||
dateOfBirth: player.dateOfBirth,
|
||||
nationality: player.nationality,
|
||||
})),
|
||||
staff: clubData.staff,
|
||||
lastUpdated: clubData.lastUpdated,
|
||||
};
|
||||
next();
|
||||
} catch (error) {
|
||||
console.error("Error fetching clubs data:", error);
|
||||
res.locals.club = null; // Set to null if there's an error
|
||||
next(); // Call next middleware or route handler
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = fetchClubsData;
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
const express = require('express');
|
||||
const express = require("express");
|
||||
const app = express();
|
||||
|
||||
// generate-league-routes.js
|
||||
|
||||
// Define a function to generate league routes
|
||||
module.exports = function generateClubRoutes(app) {
|
||||
// Define a route to handle requests to "/league/:leagueName"
|
||||
app.get('/club/:clubID', (req, res) => {
|
||||
// Extract the league name from the URL parameters
|
||||
const clubID = req.params.clubID;
|
||||
// Render the league page template using Handlebars
|
||||
res.render('pages/club-page', { clubID: clubID, });
|
||||
});
|
||||
// Define a route to handle requests to "/league/:leagueName"
|
||||
app.get("/club/:clubID", (req, res) => {
|
||||
// Extract the league name from the URL parameters
|
||||
const clubID = req.params.clubID;
|
||||
// Render the league page template using Handlebars
|
||||
res.render("pages/club-page", { clubID: clubID });
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
// Add click event listener to club logos
|
||||
document.querySelectorAll('#league-table-club-logo, #league-table-club-name-column, #league-top-scorers-logo, #league-top-scorers-club-name-column').forEach(element => {
|
||||
element.addEventListener('click', (event) => {
|
||||
// Get the club ID from the clicked club logo's clubID attribute
|
||||
const clubId = element.getAttribute('clubID');
|
||||
redirectToClubPage(clubId);
|
||||
});
|
||||
});
|
||||
document
|
||||
.querySelectorAll(
|
||||
"#league-table-club-logo, #league-table-club-name-column, #league-top-scorers-logo, #league-top-scorers-club-name-column"
|
||||
)
|
||||
.forEach((element) => {
|
||||
element.addEventListener("click", (event) => {
|
||||
// Get the club ID from the clicked club logo's clubID attribute
|
||||
const clubId = element.getAttribute("clubID");
|
||||
redirectToClubPage(clubId);
|
||||
});
|
||||
});
|
||||
|
||||
// Function to redirect to the club page
|
||||
function redirectToClubPage(clubID) {
|
||||
// Append the club ID to the URL
|
||||
var url = "/club/" + clubID;
|
||||
// Append the club ID to the URL
|
||||
var url = "/club/" + clubID;
|
||||
|
||||
// Redirect to the club page
|
||||
window.location.href = url;
|
||||
// Redirect to the club page
|
||||
window.location.href = url;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
const express = require('express');
|
||||
const express = require("express");
|
||||
const app = express();
|
||||
|
||||
// generate-league-routes.js
|
||||
|
||||
// Define a function to generate league routes
|
||||
module.exports = function generateLeagueRoutes(app) {
|
||||
// Define a route to handle requests to "/league/:leagueName"
|
||||
app.get('/league/:leagueID', (req, res) => {
|
||||
// Extract the league name from the URL parameters
|
||||
const leagueID = req.params.leagueID;
|
||||
// Render the league page template using Handlebars
|
||||
res.render('pages/leagues-page', { leagueID: leagueID, user: user});
|
||||
});
|
||||
// Define a route to handle requests to "/league/:leagueName"
|
||||
app.get("/league/:leagueID", (req, res) => {
|
||||
// Extract the league name from the URL parameters
|
||||
const leagueID = req.params.leagueID;
|
||||
// Render the league page template using Handlebars
|
||||
res.render("pages/leagues-page", { leagueID: leagueID, user: user });
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
const axios = require('axios');
|
||||
const axios = require("axios");
|
||||
|
||||
const fetchTeamNames = async (selectedLeague) => {
|
||||
try {
|
||||
const response = await axios({
|
||||
url: `http://api.football-data.org/v4/competitions/${selectedLeague}/teams`,
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'X-Auth-Token': '0aa1ed31245d4a36b1ef5a79150324b3',
|
||||
},
|
||||
});
|
||||
|
||||
const teams = response.data.teams.map(team => team.name);
|
||||
return teams;
|
||||
} catch (error) {
|
||||
console.error('Error fetching teams data:', error);
|
||||
return [];
|
||||
}
|
||||
try {
|
||||
const response = await axios({
|
||||
url: `http://api.football-data.org/v4/competitions/${selectedLeague}/teams`,
|
||||
method: "GET",
|
||||
headers: {
|
||||
"X-Auth-Token": "0aa1ed31245d4a36b1ef5a79150324b3",
|
||||
},
|
||||
});
|
||||
|
||||
const teams = response.data.teams.map((team) => team.name);
|
||||
return teams;
|
||||
} catch (error) {
|
||||
console.error("Error fetching teams data:", error);
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = fetchTeamNames;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
function redirectToLeaguePage(leagueID) {
|
||||
// Append the league name to the URL
|
||||
var url = "/league/" + leagueID;
|
||||
|
||||
// Redirect to the league page
|
||||
window.location.href = url;
|
||||
}
|
||||
// Append the league name to the URL
|
||||
var url = "/league/" + leagueID;
|
||||
|
||||
// Redirect to the league page
|
||||
window.location.href = url;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user