mirror of
https://github.com/R0m1k3/podcastic.git
synced 2026-10-19 21:18:03 +02:00
Rend l'abonnement idempotent (409 → 200)
Abonner deux fois au même podcast retourne 200 au lieu de 409. Tous les messages d'erreur traduits en français. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
eb6821ca76
commit
a8cef14226
2 files changed
+20
-28
No files matched your search
@@ -73,20 +73,15 @@ export const subscribe = async (req: Request, res: Response) => {
|
||||
podcastId: podcast._id,
|
||||
});
|
||||
|
||||
if (existingSubscription) {
|
||||
return res.status(409).json({ message: 'Already subscribed to this podcast' });
|
||||
}
|
||||
if (!existingSubscription) {
|
||||
const subscription = new UserSubscription({
|
||||
userId: req.user.id,
|
||||
podcastId: podcast._id,
|
||||
await subscription.save();
|
||||
}
|
||||
|
||||
// Create subscription
|
||||
const subscription = new UserSubscription({
|
||||
userId: req.user.id,
|
||||
podcastId: podcast._id,
|
||||
});
|
||||
|
||||
await subscription.save();
|
||||
|
||||
res.status(201).json({
|
||||
message: 'Subscribed successfully',
|
||||
res.status(200).json({
|
||||
message: existingSubscription ? 'Déjà abonné' : 'Abonnement réussi',
|
||||
podcast: podcast.toJSON(),
|
||||
});
|
||||
} catch (error) {
|
||||
@@ -98,7 +93,7 @@ export const subscribe = async (req: Request, res: Response) => {
|
||||
}
|
||||
|
||||
console.error('Subscribe error:', error);
|
||||
res.status(500).json({ message: 'Failed to subscribe' });
|
||||
res.status(500).json({ message: "Impossible de s'abonner" });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -230,25 +225,21 @@ export const subscribeFromDiscovery = async (req: Request, res: Response) => {
|
||||
podcastId: podcast._id,
|
||||
});
|
||||
|
||||
if (existingSubscription) {
|
||||
return res.status(409).json({ message: 'Already subscribed to this podcast' });
|
||||
if (!existingSubscription) {
|
||||
const subscription = new UserSubscription({
|
||||
userId: req.user.id,
|
||||
podcastId: podcast._id,
|
||||
});
|
||||
await subscription.save();
|
||||
}
|
||||
|
||||
// Create subscription
|
||||
const subscription = new UserSubscription({
|
||||
userId: req.user.id,
|
||||
podcastId: podcast._id,
|
||||
});
|
||||
|
||||
await subscription.save();
|
||||
|
||||
res.status(201).json({
|
||||
message: 'Subscribed successfully',
|
||||
res.status(200).json({
|
||||
message: existingSubscription ? 'Déjà abonné' : 'Abonnement réussi',
|
||||
podcast: podcast.toJSON(),
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error('Subscribe from discovery error:', error);
|
||||
res.status(500).json({ message: 'Failed to subscribe' });
|
||||
res.status(500).json({ message: "Impossible de s'abonner" });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ export default function Discover() {
|
||||
await subscribeMutation.mutateAsync(podcast);
|
||||
// Show success toast (you might want to add a toast library)
|
||||
alert(`"${podcast.title}" ajouté à vos abonnements !`);
|
||||
queryClient.invalidateQueries({ queryKey: ['episodes', 'latest'] });
|
||||
} catch (error: any) {
|
||||
const errorMessage = error.response?.data?.message || 'Failed to subscribe';
|
||||
alert(`Erreur : ${errorMessage}`);
|
||||
@@ -81,7 +82,7 @@ export default function Discover() {
|
||||
setRssSuccess(null);
|
||||
try {
|
||||
const result = await podcastService.subscribe(rssUrl.trim());
|
||||
setRssSuccess(`"${result.podcast.title}" ajouté à vos abonnements !`);
|
||||
setRssSuccess(`"${result.podcast.title}" — ${result.message === 'Déjà abonné' ? 'Déjà dans vos abonnements' : 'ajouté à vos abonnements !'}`);
|
||||
setRssUrl('');
|
||||
queryClient.invalidateQueries({ queryKey: ['podcasts', 'subscriptions'] });
|
||||
} catch (error: any) {
|
||||
|
||||
Reference in new issue
Block a user