6.6 KiB
6.6 KiB
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):
# 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):
# 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
{
"message": "Your approval message here"
}
🧪 Practical Examples
1. Approve Article dari User Level 3 (Branch A):
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:
{
"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):
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:
{
"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:
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
- Input: Article ID (123)
- Find Active Flow:
SELECT * FROM article_approval_flows WHERE article_id = 123 AND status_id = 1 - Get Flow Info:
- Flow ID: 456
- Current Step: 2
- Current Branch: "Branch_A"
- Workflow ID: 1
- Process Approval: Menggunakan multi-branch logic
- Update Flow: Step dan branch diupdate sesuai workflow
- 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:
// 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:
// 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:
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:
{
"success": false,
"messages": ["No active approval flow found for this article"]
}
2. Invalid Article ID:
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:
{
"success": false,
"messages": ["Invalid article ID format"]
}
📊 Testing Scenarios
Test Case 1: Normal Approval Flow
- Create article dengan user level 5
- Article otomatis masuk ke Branch A (Level 2 A Branch)
- User level 3 approve → masuk ke Final Approval
- User level 2 approve → artikel published
Test Case 2: Branch B Flow
- Create article dengan user level 6
- Article otomatis masuk ke Branch B (Level 2 B Branch)
- User level 4 approve → masuk ke Final Approval
- User level 2 approve → artikel published
Test Case 3: Error Handling
- Try approve artikel yang tidak ada approval flow
- Try approve dengan user level yang tidak sesuai
- 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! 🚀