firt commit
This commit is contained in:
commit
c2e63830e1
71 changed files with 9613 additions and 0 deletions
30
server/controllers/matchController.js
Executable file
30
server/controllers/matchController.js
Executable file
|
@ -0,0 +1,30 @@
|
|||
import { query } from '../utils/database.js';
|
||||
|
||||
export const getMatches = async (req, res) => {
|
||||
try {
|
||||
// Fetch all matches, ordered by date
|
||||
const matches = await query('SELECT id, name, date, location, totalSeats, availableSeats, price, timeoutDate FROM matches ORDER BY date');
|
||||
res.status(200).json(matches);
|
||||
} catch (error) {
|
||||
console.error('Error fetching matches:', error);
|
||||
res.status(500).json({ message: 'Failed to fetch matches', error: error.message });
|
||||
}
|
||||
};
|
||||
|
||||
export const getMatchDetails = async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
|
||||
// Fetch details for a specific match
|
||||
const match = await query('SELECT id, name, date, location, totalSeats, availableSeats, price, timeoutDate FROM matches WHERE id = ?', [id]);
|
||||
|
||||
if (match.length === 0) {
|
||||
return res.status(404).json({ message: 'Match not found' });
|
||||
}
|
||||
|
||||
res.status(200).json(match[0]);
|
||||
} catch (error) {
|
||||
console.error('Error fetching match details:', error);
|
||||
res.status(500).json({ message: 'Failed to fetch match details', error: error.message });
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue