Skip to content

Commit e90015a

Browse files
committed
feat(backend): Fixes #89 - Collection Chamionships
1 parent 8a0c848 commit e90015a

5 files changed

Lines changed: 124 additions & 3 deletions

File tree

app/backend/src/app.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import newsRoutes from './routes/news.js';
2222
import albumsRoutes from './routes/albums.js';
2323
import mediasRoutes from './routes/medias.js';
2424
import partnersRoutes from './routes/partners.js';
25+
import championshipsRoutes from './routes/championships.js';
2526

2627
// Utiliser les routes
2728
app.use('/api/users', usersRoutes);
@@ -33,5 +34,7 @@ app.use('/api/news', newsRoutes);
3334
app.use('/api/albums', albumsRoutes);
3435
app.use('/api/medias', mediasRoutes);
3536
app.use('/api/partners', partnersRoutes);
37+
app.use('/api/championships', championshipsRoutes);
3638

39+
// Exporter l'application
3740
export default app;
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import Championship from '../models/Championship.js';
2+
3+
// Liste (optionnellement filtrée par saison ou équipe)
4+
export const getChampionships = async (req, res) => {
5+
try {
6+
const filter = {};
7+
8+
if (req.query.seasonId) {
9+
filter.seasonId = req.query.seasonId;
10+
}
11+
12+
if (req.query.teamId) {
13+
filter.teamId = req.query.teamId;
14+
}
15+
16+
const championships = await Championship.find(filter).populate('teamId').sort({ createdAt: -1 });
17+
18+
res.json(championships);
19+
} catch (error) {
20+
res.status(500).json({ message: error.message });
21+
}
22+
};
23+
24+
// Par ID
25+
export const getChampionshipById = async (req, res) => {
26+
try {
27+
const championship = await Championship.findById(req.params.id).populate('teamId');
28+
29+
if (!championship) {
30+
return res.status(404).json({ message: 'Championship not found' });
31+
}
32+
33+
res.json(championship);
34+
} catch (error) {
35+
res.status(500).json({ message: error.message });
36+
}
37+
};
38+
39+
// Création
40+
export const createChampionship = async (req, res) => {
41+
try {
42+
const championship = await Championship.create(req.body);
43+
res.status(201).json(championship);
44+
} catch (error) {
45+
res.status(400).json({ message: error.message });
46+
}
47+
};
48+
49+
// Mise à jour
50+
export const updateChampionship = async (req, res) => {
51+
try {
52+
const championship = await Championship.findByIdAndUpdate(req.params.id, req.body, {
53+
new: true,
54+
runValidators: true,
55+
});
56+
57+
if (!championship) {
58+
return res.status(404).json({ message: 'Championship not found' });
59+
}
60+
61+
res.json(championship);
62+
} catch (error) {
63+
res.status(400).json({ message: error.message });
64+
}
65+
};
66+
67+
// Suppression
68+
export const deleteChampionship = async (req, res) => {
69+
try {
70+
const championship = await Championship.findByIdAndDelete(req.params.id);
71+
72+
if (!championship) {
73+
return res.status(404).json({ message: 'Championship not found' });
74+
}
75+
76+
res.json({ message: 'Championship deleted' });
77+
} catch (error) {
78+
res.status(500).json({ message: error.message });
79+
}
80+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import mongoose from 'mongoose';
2+
3+
const championshipSchema = new mongoose.Schema(
4+
{
5+
teamId: {
6+
type: mongoose.Schema.Types.ObjectId,
7+
ref: 'Team',
8+
required: true,
9+
},
10+
federationUrl: {
11+
type: String,
12+
required: true,
13+
trim: true,
14+
},
15+
},
16+
{
17+
timestamps: true,
18+
},
19+
);
20+
21+
export default mongoose.model('Championship', championshipSchema);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import express from 'express';
2+
import {
3+
getChampionships,
4+
getChampionshipById,
5+
createChampionship,
6+
updateChampionship,
7+
deleteChampionship,
8+
} from '../controllers/championshipsController.js';
9+
10+
const router = express.Router();
11+
12+
router.get('/', getChampionships);
13+
router.get('/:id', getChampionshipById);
14+
router.post('/', createChampionship);
15+
router.put('/:id', updateChampionship);
16+
router.delete('/:id', deleteChampionship);
17+
18+
export default router;

docs/data-conception/data.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,18 @@
174174
| `updatedAt` | Date MAJ |
175175

176176

177-
## championships_ffvb
177+
## championships
178178

179179
| Champ | Description |
180180
| --------------- | -------------- |
181181
| `_id` | Identifiant |
182-
| `seasonId` | Saison |
183182
| `teamId` | Équipe du club |
184183
| `federationUrl` | URL FFVB |
185184
| `createdAt` | Date import |
186185
| `updatedAt` | Date MAJ |
187186

188187

189-
## standings_ffvb
188+
## standings
190189

191190
| Champ | Description |
192191
| ---------------- | ------------ |

0 commit comments

Comments
 (0)