# Simplified Article Approval API - Usage Guide ## ๐ŸŽฏ **Overview** API baru ini menyederhanakan proses approval artikel. Sebelumnya user perlu mengetahui flow ID dan step yang sedang berjalan, sekarang cukup dengan article ID saja. ## ๐Ÿ”„ **Before vs After** ### **โŒ Before (Complex):** ```bash # User perlu tahu flow ID (456) dan step yang sedang berjalan curl -X POST "http://localhost:8080/api/article-approval-flows/456/multi-branch-approve" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_TOKEN" \ -d '{"message": "Approved"}' ``` ### **โœ… After (Simple):** ```bash # User hanya perlu tahu article ID (123) curl -X POST "http://localhost:8080/api/article-approval-flows/articles/123/approve" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_TOKEN" \ -d '{"message": "Approved"}' ``` ## ๐Ÿš€ **New Endpoint** ``` POST /api/article-approval-flows/articles/{articleId}/approve ``` ## ๐Ÿ“‹ **Request Format** ```json { "message": "Your approval message here" } ``` ## ๐Ÿงช **Practical Examples** ### **1. Approve Article dari User Level 3 (Branch A):** ```bash curl -X POST "http://localhost:8080/api/article-approval-flows/articles/10/approve" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer USER_LEVEL_3_TOKEN" \ -d '{ "message": "Content reviewed and approved. Ready for final approval." }' ``` **Expected Response:** ```json { "success": true, "messages": ["Article successfully approved through active approval flow"], "data": { "article_id": 10, "flow_id": 1, "current_step": 2, "current_branch": "Final_Approval", "workflow_id": 1 } } ``` ### **2. Approve Article dari User Level 2 (Final Approval):** ```bash curl -X POST "http://localhost:8080/api/article-approval-flows/articles/10/approve" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer USER_LEVEL_2_TOKEN" \ -d '{ "message": "Final approval granted. Article ready for publication." }' ``` **Expected Response:** ```json { "success": true, "messages": ["Article successfully approved through active approval flow"], "data": { "article_id": 10, "flow_id": 1, "current_step": 3, "current_branch": "Final_Approval", "workflow_id": 1 } } ``` ### **3. Approve Article tanpa Message:** ```bash curl -X POST "http://localhost:8080/api/article-approval-flows/articles/10/approve" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_TOKEN" \ -d '{}' ``` ## ๐Ÿ” **How It Works Internally** 1. **Input**: Article ID (123) 2. **Find Active Flow**: ```sql SELECT * FROM article_approval_flows WHERE article_id = 123 AND status_id = 1 ``` 3. **Get Flow Info**: - Flow ID: 456 - Current Step: 2 - Current Branch: "Branch_A" - Workflow ID: 1 4. **Process Approval**: Menggunakan multi-branch logic 5. **Update Flow**: Step dan branch diupdate sesuai workflow 6. **Response**: Return informasi yang relevan ## ๐ŸŽฏ **Benefits** ### **1. Simplified User Experience** - โœ… Tidak perlu tahu flow ID - โœ… Tidak perlu tahu step yang sedang berjalan - โœ… Tidak perlu tahu branch yang aktif - โœ… Cukup masukkan article ID ### **2. Reduced Complexity** - โœ… API call lebih sederhana - โœ… Error handling lebih mudah - โœ… Integration lebih straightforward - โœ… Maintenance lebih mudah ### **3. Better Error Messages** - โœ… "No active approval flow found" - jelas dan informatif - โœ… "Invalid article ID format" - mudah dipahami - โœ… Automatic flow detection - tidak perlu manual check ## ๐Ÿ”„ **Integration Examples** ### **Frontend Integration:** ```javascript // Simple approval function async function approveArticle(articleId, message = '') { const response = await fetch(`/api/article-approval-flows/articles/${articleId}/approve`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}` }, body: JSON.stringify({ message }) }); const result = await response.json(); return result; } // Usage approveArticle(123, 'Content looks good!'); ``` ### **Mobile App Integration:** ```javascript // React Native example const approveArticle = async (articleId) => { try { const response = await fetch(`${API_BASE}/article-approval-flows/articles/${articleId}/approve`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${userToken}` }, body: JSON.stringify({ message: 'Approved from mobile app' }) }); const result = await response.json(); if (result.success) { Alert.alert('Success', 'Article approved successfully!'); } else { Alert.alert('Error', result.messages[0]); } } catch (error) { Alert.alert('Error', 'Failed to approve article'); } }; ``` ## ๐Ÿšจ **Error Scenarios** ### **1. No Active Flow:** ```bash curl -X POST "http://localhost:8080/api/article-approval-flows/articles/999/approve" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_TOKEN" \ -d '{"message": "Approved"}' ``` **Response:** ```json { "success": false, "messages": ["No active approval flow found for this article"] } ``` ### **2. Invalid Article ID:** ```bash curl -X POST "http://localhost:8080/api/article-approval-flows/articles/invalid/approve" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_TOKEN" \ -d '{"message": "Approved"}' ``` **Response:** ```json { "success": false, "messages": ["Invalid article ID format"] } ``` ## ๐Ÿ“Š **Testing Scenarios** ### **Test Case 1: Normal Approval Flow** 1. Create article dengan user level 5 2. Article otomatis masuk ke Branch A (Level 2 A Branch) 3. User level 3 approve โ†’ masuk ke Final Approval 4. User level 2 approve โ†’ artikel published ### **Test Case 2: Branch B Flow** 1. Create article dengan user level 6 2. Article otomatis masuk ke Branch B (Level 2 B Branch) 3. User level 4 approve โ†’ masuk ke Final Approval 4. User level 2 approve โ†’ artikel published ### **Test Case 3: Error Handling** 1. Try approve artikel yang tidak ada approval flow 2. Try approve dengan user level yang tidak sesuai 3. Try approve artikel yang sudah selesai ## ๐ŸŽ‰ **Summary** API baru ini memberikan: - โœ… **Simplified Interface**: Cukup article ID - โœ… **Automatic Flow Detection**: Sistem otomatis cari flow aktif - โœ… **Multi-Branch Support**: Tetap mendukung multi-branch logic - โœ… **Better UX**: User experience yang lebih baik - โœ… **Easy Integration**: Mudah diintegrasikan dengan frontend/mobile **Sekarang user tidak perlu lagi repot dengan flow ID atau step yang sedang berjalan - cukup masukkan article ID dan sistem akan menangani sisanya!** ๐Ÿš€