Merge pull request #26 from LucasPatenaude/database-testing

Add Database Functionality to Application
This commit is contained in:
Lucas Patenaude
2024-04-22 18:05:03 -06:00
committed by GitHub
18 changed files with 288 additions and 77 deletions

View File

@@ -30,6 +30,27 @@
border-color: darkred;
color: white;
}
/* CSS for the account info card */
.account-info-card {
border: 1px solid #ccc;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
padding: 20px;
width: 300px;
}
.info-container {
margin-bottom: 10px;
}
#username {
font-size: 18px;
font-weight: bold;
color: #333;
}
#teamlogo{
width: 23px;
height: 23px;
}

View File

@@ -2,7 +2,67 @@ document.addEventListener("DOMContentLoaded", function() {
var favoriteButton = document.getElementById("club-favorite-button");
if (favoriteButton) {
favoriteButton.addEventListener("click", function() {
favoriteButton.src = "/img/club-page/favorited.png";
var userID = document.getElementById("userID").value;
var teamID = document.getElementById("teamID").value;
var teamName = document.getElementById("teamName").value;
var teamLogo = document.getElementById("teamLogo").value;
if (favoriteButton.src.includes("/favorited.png")) {
removeFavoriteTeam(userID, teamID)
}
else {
addFavoriteTeam(userID, teamID, teamName, teamLogo)
}
});
}
});
async function addFavoriteTeam(userID, teamID, teamName, teamLogo){
try {
const response = await fetch('/favteam/add', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
userID: userID,
teamID: teamID,
teamName: teamName,
teamLogo: teamLogo
})
});
if (!response.ok) {
throw new Error('Failed to add favorite team');
}
//Changes button if favorite team is added//
console.log('New favorite team added successfully.');
var favoriteButton = document.getElementById("club-favorite-button");
favoriteButton.src = "/img/club-page/favorited.png";
} catch (error) {
console.error('Error adding favorite team:', error);
}
}
async function removeFavoriteTeam(userID, teamID) {
try {
const response = await fetch('/favteam/remove', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
userID: userID,
teamID: teamID
})
});
console.log('Favorite team removed successfully.');
//Change button source//
var favoriteButton = document.getElementById("club-favorite-button");
favoriteButton.src = "/img/club-page/unfavorited.png";
} catch (error) {
console.error('Error removing favorite team:', error);
}
}

View File

@@ -37,4 +37,5 @@ document.addEventListener("DOMContentLoaded", function() {
selectElement.add(option);
}
});

View File

@@ -15,7 +15,7 @@ const fetchClubsData = async (req, res, next) => {
// 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: {
@@ -63,7 +63,6 @@ const fetchClubsData = async (req, res, next) => {
staff: clubData.staff,
lastUpdated: clubData.lastUpdated
};
next();
} catch (error) {
console.error('Error fetching clubs data:', error);

View File

@@ -1,36 +0,0 @@
const axios = require('axios');
// Middleware function to fetch leagues data
const fetchLeagueScorerData = async (req, res, next) => {
try {
// Extract league ID from the URL
const leagueID = req.params.leagueID;
// Make GET request to the API endpoint using the league ID
const response = await axios.get(`http://api.football-data.org/v4/teams/${teamID}/scorers?limit=5`, {
headers: {
'X-Auth-Token': '0aa1ed31245d4a36b1ef5a79150324b3', // Add your API key here
},
});
// Extract relevant data from the API response
const scorerData = response.data;
// Attach the data to res.locals
res.locals.topScorers = {
scorers: scorerData.scorers.map(player => ({
playerID: scorer.player.id,
playerName: scorer.player.name,
goals: scorer.numberOfGoals,
}))
};
next();
} catch (error) {
console.error('Error fetching leagues data:', error);
res.locals.topScorers = null; // Set to null if there's an error
next(); // Call next middleware or route handler
}
};
module.exports = fetchLeagueScorerData;

View File

@@ -17,6 +17,8 @@ const fetchLeaguesData = async (req, res, next) => {
const leagueData = response.data;
// Attach the data to res.locals
//res.locals.username = req.session.user.username;
console.log(req.session.user)
res.locals.league = {
area: {
league_flag: leagueData.area.flag,
@@ -39,7 +41,7 @@ const fetchLeaguesData = async (req, res, next) => {
draws: team.draw,
goal_difference: team.goalDifference,
points: team.points
}))
})),
};
next();
} catch (error) {

View File

@@ -9,9 +9,8 @@ module.exports = function generateClubRoutes(app) {
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 });
res.render('pages/club-page', { clubID: clubID, });
});
};

View File

@@ -9,9 +9,8 @@ module.exports = function generateLeagueRoutes(app) {
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 });
res.render('pages/leagues-page', { leagueID: leagueID, user: user});
});
};

View File

@@ -9,7 +9,7 @@ const fetchTeamNames = async (selectedLeague) => {
'X-Auth-Token': '0aa1ed31245d4a36b1ef5a79150324b3',
},
});
const teams = response.data.teams.map(team => team.name);
return teams;
} catch (error) {