Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/backend/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import newsRoutes from './routes/news.js';
import albumsRoutes from './routes/albums.js';
import mediasRoutes from './routes/medias.js';
import partnersRoutes from './routes/partners.js';
import championshipsRoutes from './routes/championships.js';

// Utiliser les routes
app.use('/api/users', usersRoutes);
Expand All @@ -33,5 +34,7 @@ app.use('/api/news', newsRoutes);
app.use('/api/albums', albumsRoutes);
app.use('/api/medias', mediasRoutes);
app.use('/api/partners', partnersRoutes);
app.use('/api/championships', championshipsRoutes);

// Exporter l'application
export default app;
80 changes: 80 additions & 0 deletions app/backend/src/controllers/championshipsController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import Championship from '../models/Championship.js';

// Liste (optionnellement filtrée par saison ou équipe)
export const getChampionships = async (req, res) => {
try {
const filter = {};

if (req.query.seasonId) {
filter.seasonId = req.query.seasonId;
}

if (req.query.teamId) {
filter.teamId = req.query.teamId;
}

const championships = await Championship.find(filter).populate('teamId').sort({ createdAt: -1 });

res.json(championships);
} catch (error) {
res.status(500).json({ message: error.message });
}
};

// Par ID
export const getChampionshipById = async (req, res) => {
try {
const championship = await Championship.findById(req.params.id).populate('teamId');

if (!championship) {
return res.status(404).json({ message: 'Championship not found' });
}

res.json(championship);
} catch (error) {
res.status(500).json({ message: error.message });
}
};

// Création
export const createChampionship = async (req, res) => {
try {
const championship = await Championship.create(req.body);
res.status(201).json(championship);
} catch (error) {
res.status(400).json({ message: error.message });
}
};

// Mise à jour
export const updateChampionship = async (req, res) => {
try {
const championship = await Championship.findByIdAndUpdate(req.params.id, req.body, {
new: true,
runValidators: true,
});

if (!championship) {
return res.status(404).json({ message: 'Championship not found' });
}

res.json(championship);
} catch (error) {
res.status(400).json({ message: error.message });
}
};

// Suppression
export const deleteChampionship = async (req, res) => {
try {
const championship = await Championship.findByIdAndDelete(req.params.id);

if (!championship) {
return res.status(404).json({ message: 'Championship not found' });
}

res.json({ message: 'Championship deleted' });
} catch (error) {
res.status(500).json({ message: error.message });
}
};
21 changes: 21 additions & 0 deletions app/backend/src/models/Championship.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import mongoose from 'mongoose';

const championshipSchema = new mongoose.Schema(
{
teamId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Team',
required: true,
},
federationUrl: {
type: String,
required: true,
trim: true,
},
},
{
timestamps: true,
},
);

export default mongoose.model('Championship', championshipSchema);
18 changes: 18 additions & 0 deletions app/backend/src/routes/championships.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import express from 'express';
import {
getChampionships,
getChampionshipById,
createChampionship,
updateChampionship,
deleteChampionship,
} from '../controllers/championshipsController.js';

const router = express.Router();

router.get('/', getChampionships);
router.get('/:id', getChampionshipById);
router.post('/', createChampionship);
router.put('/:id', updateChampionship);
router.delete('/:id', deleteChampionship);

export default router;
5 changes: 2 additions & 3 deletions docs/data-conception/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,19 +174,18 @@
| `updatedAt` | Date MAJ |


## championships_ffvb
## championships

| Champ | Description |
| --------------- | -------------- |
| `_id` | Identifiant |
| `seasonId` | Saison |
| `teamId` | Équipe du club |
| `federationUrl` | URL FFVB |
| `createdAt` | Date import |
| `updatedAt` | Date MAJ |


## standings_ffvb
## standings

| Champ | Description |
| ---------------- | ------------ |
Expand Down
Loading