Spaces:
Running
Running
File size: 10,238 Bytes
ef287e1 |
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 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
# Exemples d'Utilisation de l'API Akompta
## 🔐 Authentification
### Inscription (Compte Personnel)
```bash
curl -X POST http://localhost:8000/api/auth/register/ \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "SecurePass123!",
"password2": "SecurePass123!",
"first_name": "John",
"last_name": "Doe",
"phone_number": "+22890123456",
"account_type": "personal",
"agreed": true
}'
```
**Réponse :**
```json
{
"user": {
"id": 1,
"email": "user@example.com",
"first_name": "John",
"last_name": "Doe",
"account_type": "personal",
"is_premium": false
},
"tokens": {
"refresh": "eyJ0eXAiOiJKV1QiLCJhbGc...",
"access": "eyJ0eXAiOiJKV1QiLCJhbGc..."
}
}
```
### Inscription (Compte Business)
```bash
curl -X POST http://localhost:8000/api/auth/register/ \
-H "Content-Type: application/json" \
-d '{
"email": "business@example.com",
"password": "SecurePass123!",
"password2": "SecurePass123!",
"first_name": "Jane",
"last_name": "Smith",
"phone_number": "+22890987654",
"account_type": "business",
"business_name": "AgriTech Solutions",
"sector": "Agriculture",
"location": "Lomé, Togo",
"ifu": "1234567890123",
"agreed": true,
"businessAgreed": true
}'
```
### Connexion
```bash
curl -X POST http://localhost:8000/api/auth/login/ \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"password": "SecurePass123!"
}'
```
### Rafraîchir le Token
```bash
curl -X POST http://localhost:8000/api/auth/token/refresh/ \
-H "Content-Type: application/json" \
-d '{
"refresh": "eyJ0eXAiOiJKV1QiLCJhbGc..."
}'
```
### Récupérer le Profil
```bash
curl -X GET http://localhost:8000/api/auth/me/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
```
### Modifier le Profil
```bash
curl -X PATCH http://localhost:8000/api/auth/me/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"phone_number": "+22890999888",
"dark_mode": true
}'
```
### Changer le Mot de Passe
```bash
curl -X POST http://localhost:8000/api/auth/change-password/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"old_password": "SecurePass123!",
"new_password": "NewSecurePass456!",
"new_password2": "NewSecurePass456!"
}'
```
## 📦 Produits
### Créer un Produit
```bash
curl -X POST http://localhost:8000/api/products/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Tomates",
"description": "Tomates fraîches de qualité",
"price": "800.00",
"unit": "Kg",
"category": "vente",
"stock_status": "ok"
}'
```
### Créer un Produit avec Image
```bash
curl -X POST http://localhost:8000/api/products/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-F "name=Tomates" \
-F "description=Tomates fraîches" \
-F "price=800.00" \
-F "unit=Kg" \
-F "category=vente" \
-F "stock_status=ok" \
-F "image=@/path/to/image.jpg"
```
### Lister les Produits
```bash
# Tous les produits
curl -X GET http://localhost:8000/api/products/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
# Filtrer par catégorie
curl -X GET "http://localhost:8000/api/products/?category=vente" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
# Rechercher
curl -X GET "http://localhost:8000/api/products/?search=tomate" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
# Pagination
curl -X GET "http://localhost:8000/api/products/?page=2" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
```
### Modifier un Produit
```bash
curl -X PUT http://localhost:8000/api/products/1/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Tomates Premium",
"price": "1000.00",
"stock_status": "low"
}'
```
### Supprimer un Produit
```bash
curl -X DELETE http://localhost:8000/api/products/1/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
```
### Exporter les Produits en CSV
```bash
curl -X GET http://localhost:8000/api/products/export/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-o products.csv
```
## 💰 Transactions
### Créer une Transaction
```bash
curl -X POST http://localhost:8000/api/transactions/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Vente de tomates",
"amount": "5000.00",
"type": "income",
"category": "Ventes",
"date": "2024-11-27T10:30:00Z",
"currency": "FCFA"
}'
```
### Lister les Transactions
```bash
# Toutes les transactions
curl -X GET http://localhost:8000/api/transactions/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
# Filtrer par type
curl -X GET "http://localhost:8000/api/transactions/?type=income" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
# Filtrer par période
curl -X GET "http://localhost:8000/api/transactions/?date_range=week" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
# Trier par date décroissante
curl -X GET "http://localhost:8000/api/transactions/?ordering=-date" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
# Rechercher
curl -X GET "http://localhost:8000/api/transactions/?search=vente" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
```
### Résumé des Transactions (Dashboard)
```bash
curl -X GET http://localhost:8000/api/transactions/summary/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
```
**Réponse :**
```json
{
"balance": "125000.00",
"income_24h": "15000.00",
"expenses_24h": "8000.00",
"income_variation": 12.5,
"expenses_variation": -5.3
}
```
## 📊 Analytics
### Overview (Graphique en Barres)
```bash
curl -X GET http://localhost:8000/api/analytics/overview/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
```
**Réponse :**
```json
[
{
"month": "Oct 2024",
"income": "85000.00",
"expenses": "45000.00"
},
{
"month": "Nov 2024",
"income": "120000.00",
"expenses": "65000.00"
}
]
```
### Breakdown (Graphique Camembert)
```bash
curl -X GET http://localhost:8000/api/analytics/breakdown/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
```
**Réponse :**
```json
[
{
"category": "Transport",
"amount": "25000.00",
"percentage": 38.5
},
{
"category": "Loyer",
"amount": "40000.00",
"percentage": 61.5
}
]
```
### KPIs
```bash
curl -X GET http://localhost:8000/api/analytics/kpi/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
```
**Réponse :**
```json
{
"average_basket": "12500.00",
"estimated_mrr": "120000.00",
"cac": "5000.00"
}
```
## 🎯 Budgets
### Créer un Budget
```bash
curl -X POST http://localhost:8000/api/budgets/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"category": "Transport",
"limit": "50000.00",
"color": "#3B82F6"
}'
```
### Lister les Budgets
```bash
curl -X GET http://localhost:8000/api/budgets/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
```
**Réponse :**
```json
{
"count": 3,
"results": [
{
"id": 1,
"category": "Transport",
"limit": "50000.00",
"color": "#3B82F6",
"spent_amount": "32500.00",
"percentage": 65.0
}
]
}
```
### Modifier un Budget
```bash
curl -X PUT http://localhost:8000/api/budgets/1/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"limit": "75000.00"
}'
```
### Supprimer un Budget
```bash
curl -X DELETE http://localhost:8000/api/budgets/1/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
```
## 📢 Annonces
### Lister les Annonces (Public)
```bash
curl -X GET http://localhost:8000/api/ads/
```
### Créer une Annonce
```bash
curl -X POST http://localhost:8000/api/ads/ \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-F "product_name=Engrais Bio" \
-F "owner_name=FertiTogo" \
-F "description=Engrais biologique de qualité" \
-F "whatsapp=+22890123456" \
-F "location=Lomé, Togo" \
-F "website=https://fertitogo.com" \
-F "image=@/path/to/image.jpg"
```
### Rechercher des Annonces
```bash
curl -X GET "http://localhost:8000/api/ads/?search=engrais" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
```
## ⚠️ Gestion des Erreurs
### Erreur de Validation
```json
{
"type": "validation_error",
"errors": {
"email": ["Cet email existe déjà."],
"ifu": ["Ce champ est obligatoire pour les comptes professionnels."]
}
}
```
### Erreur d'Authentification
```json
{
"type": "authentication_error",
"message": "Token invalide ou expiré"
}
```
### Erreur de Permission
```json
{
"type": "permission_error",
"message": "Vous n'avez pas la permission d'effectuer cette action"
}
```
## 📝 Notes Importantes
1. **Toujours inclure le token** dans l'en-tête `Authorization: Bearer YOUR_TOKEN`
2. **Les dates** doivent être au format ISO 8601 : `2024-11-27T10:30:00Z`
3. **Les montants** sont en format décimal avec 2 décimales : `"1000.00"`
4. **Pagination** : Paramètres `?page=2&page_size=20`
5. **Upload de fichiers** : Utiliser `multipart/form-data` avec `-F`
## 🔄 Exemple Complet de Workflow
```bash
# 1. S'inscrire
TOKEN=$(curl -X POST http://localhost:8000/api/auth/register/ \
-H "Content-Type: application/json" \
-d '{"email":"test@example.com","password":"Test123!","password2":"Test123!","first_name":"Test","last_name":"User","account_type":"personal","agreed":true}' \
| jq -r '.tokens.access')
# 2. Créer un produit
curl -X POST http://localhost:8000/api/products/ \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"name":"Tomates","price":"800.00","unit":"Kg","category":"vente","stock_status":"ok"}'
# 3. Ajouter une transaction
curl -X POST http://localhost:8000/api/transactions/ \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"name":"Vente tomates","amount":"5000.00","type":"income","category":"Ventes","date":"2024-11-27T10:00:00Z"}'
# 4. Voir le résumé
curl -X GET http://localhost:8000/api/transactions/summary/ \
-H "Authorization: Bearer $TOKEN"
``` |