File size: 7,082 Bytes
fafd0bb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# 🚀 Guide d'Intégration API - EduConnect Africa
> Développé par **Marino ATOHOUN** pour **Hypee**
## 📋 Vue d'ensemble
Ce document détaille comment utiliser les services API frontend pour communiquer avec le backend Django REST Framework.
---
## 🔐 Authentification
### Configuration
L'authentification utilise **JWT (JSON Web Tokens)** avec refresh automatique.
```typescript
import { authService } from './services';
// Connexion
await authService.login('email@example.com', 'password');
// Les tokens sont automatiquement stockés dans localStorage
// Inscription
await authService.register('John Doe', 'email@example.com', 'password', UserRole.STUDENT);
// Récupérer l'utilisateur connecté
const user = await authService.getCurrentUser();
// Mettre à jour le profil
await authService.updateProfile({ name: 'Nouveau nom', country: 'Bénin' });
// Déconnexion
authService.logout();
```
---
## 💬 Forum / Questions
### Récupérer les questions
```typescript
import { forumService } from './services';
// Toutes les questions (avec pagination)
const { count, results } = await forumService.getQuestions({
page: 1,
search: 'algorithme',
filter: 'unsolved', // 'solved' | 'unsolved' | undefined
tag: 'python'
});
// Une question spécifique
const question = await forumService.getQuestion('123');
// Créer une question
const newQuestion = await forumService.createQuestion({
title: 'Comment optimiser mon code ?',
content: 'J\'ai un problème de performance...',
tags: ['python', 'performance']
});
// Voter pour une question
await forumService.voteQuestion('123', 1); // 1 = upvote, -1 = downvote
```
---
## 👨🏫 Mentors
### Recherche et profils mentors
```typescript
import { mentorService } from './services';
// Liste des mentors
const { count, results } = await mentorService.getMentors({
page: 1,
search: 'data science',
country: 'Bénin',
specialty: 'Machine Learning'
});
// Profil d'un mentor
const mentor = await mentorService.getMentor('123');
// Mon profil mentor (si je suis mentor)
const myProfile = await mentorService.getMyMentorProfile();
// Mettre à jour mon profil mentor
await mentorService.updateMyMentorProfile({
bio: 'Expert en Data Science...',
specialties: ['Python', 'ML'],
availability: 'Lun-Ven 18h-20h'
});
// Avis d'un mentor
const reviews = await mentorService.getMentorReviews('123');
```
---
## 📅 Réservations (Bookings)
### Gérer les sessions mentor
```typescript
import { bookingService } from './services';
// Mes réservations
const bookings = await bookingService.getBookings({
status: 'PENDING' // PENDING | CONFIRMED | REJECTED | COMPLETED | CANCELLED
});
// Créer une réservation
const booking = await bookingService.createBooking({
mentor_id: '123',
date: '2025-12-01',
time: '18:00',
domains: ['Python', 'Data Science'],
expectations: 'Aide pour mon projet...',
main_questions: 'Comment structurer mon code ?'
});
// Mettre à jour le statut (mentor uniquement)
await bookingService.updateBookingStatus('456', 'CONFIRMED', 'Je confirme notre session');
// Demandes reçues (mentors)
const requests = await bookingService.getMentorRequests();
```
---
## 🎯 Opportunités
### Bourses, stages, concours
```typescript
import { opportunityService } from './services';
// Liste des opportunités
const { count, results } = await opportunityService.getOpportunities({
page: 1,
type: 'SCHOLARSHIP', // SCHOLARSHIP | CONTEST | INTERNSHIP | TRAINING
search: 'data'
});
// Détails d'une opportunité
const opportunity = await opportunityService.getOpportunity('123');
```
---
## 🔔 Notifications
### Gérer les notifications utilisateur
```typescript
import { notificationService } from './services';
// Toutes mes notifications
const notifications = await notificationService.getNotifications();
// Marquer comme lue
await notificationService.markAsRead('123');
// Marquer toutes comme lues
await notificationService.markAllAsRead();
// Supprimer une notification
await notificationService.deleteNotification('123');
```
---
## ⚙️ Configuration & Gestion des Erreurs
### Intercepteurs automatiques
Le client API gère automatiquement :
- ✅ Ajout du token JWT à chaque requête
- ✅ Rafraîchissement du token expiré
- ✅ Redirection vers /login si authentification échouée
- ✅ Gestion des erreurs réseau
### Exemple de gestion d'erreurs
```typescript
try {
const questions = await forumService.getQuestions();
} catch (error: any) {
if (error.response?.status === 401) {
// Non authentifié
console.error('Veuillez vous connecter');
} else if (error.response?.status === 403) {
// Accès refusé
console.error('Vous n\'avez pas les permissions');
} else if (error.response?.status === 404) {
// Non trouvé
console.error('Ressource introuvable');
} else {
// Autre erreur
console.error('Erreur:', error.message);
}
}
```
---
## 🌐 Endpoints Backend
### Base URL
```
http://127.0.0.1:8000/api/
```
### Endpoints disponibles
| Module | Méthode | Endpoint | Description |
|--------|---------|----------|-------------|
| **Auth** |
| | POST | `/auth/register/` | Inscription utilisateur |
| | POST | `/auth/login/` | Connexion utilisateur |
| | GET | `/auth/me/` | Utilisateur connecté |
| | PATCH | `/auth/profile/` | Mise à jour profil |
| **Forum** |
| | GET | `/forum/questions/` | Liste questions |
| | POST | `/forum/questions/` | Créer question |
| | GET | `/forum/questions/{id}/` | Détails question |
| | POST | `/forum/questions/{id}/vote/` | Voter |
| **Mentors** |
| | GET | `/mentors/` | Liste mentors |
| | GET | `/mentors/{id}/` | Profil mentor |
| | GET | `/mentors/my_profile/` | Mon profil (mentor) |
| | PATCH | `/mentors/my_profile/` | Modifier profil |
| **Bookings** |
| | GET | `/bookings/` | Mes réservations |
| | POST | `/bookings/` | Créer réservation |
| | PATCH | `/bookings/{id}/update_status/` | Changer statut |
| | GET | `/bookings/mentor_requests/` | Demandes reçues |
| **Opportunities** |
| | GET | `/opportunities/` | Liste opportunités |
| | GET | `/opportunities/{id}/` | Détails |
| **Notifications** |
| | GET | `/notifications/` | Mes notifications |
| | PATCH | `/notifications/{id}/mark_read/` | Marquer lue |
| | POST | `/notifications/mark_all_read/` | Tout marquer |
| | DELETE | `/notifications/{id}/` | Supprimer |
---
## 🧪 Tests Recommandés
### Scénario complet
1. ✅ Inscription d'un étudiant
2. ✅ Connexion
3. ✅ Consultation des questions
4. ✅ Création d'une question
5. ✅ Recherche de mentors
6. ✅ Réservation d'une session
7. ✅ Consultation des opportunités
8. ✅ Vérification des notifications
---
## 📚 Ressources
- **Documentation Swagger:** http://127.0.0.1:8000/api/docs/
- **Documentation ReDoc:** http://127.0.0.1:8000/api/redoc/
- **Schema OpenAPI:** http://127.0.0.1:8000/api/schema/
---
*Développé avec ❤️ par Marino ATOHOUN pour Hypee*
|