kontenhumas-be/docs/API_APPROVE_ARTICLE_BY_FLOW.md

5.8 KiB

API Approve Article by Active Flow

🚀 Overview

API ini adalah versi yang disederhanakan dari approval process. User cukup memasukkan article ID dan sistem akan otomatis menggunakan approval flow yang sedang aktif untuk artikel tersebut. Tidak perlu mengetahui flow ID atau step yang sedang berjalan.

📋 Endpoint

POST /api/article-approval-flows/articles/{articleId}/approve

🔧 Request Body

{
  "message": "Article looks good, approved for next level"
}

📝 Field Descriptions

  • message (optional): Pesan approval yang akan dicatat dalam log

📤 Response

Success Response (200):

{
  "success": true,
  "messages": ["Article successfully approved through active approval flow"],
  "data": {
    "article_id": 123,
    "flow_id": 456,
    "current_step": 2,
    "current_branch": "Branch_A",
    "workflow_id": 1
  }
}

Error Response (400) - No Active Flow:

{
  "success": false,
  "messages": ["No active approval flow found for this article"]
}

Error Response (400) - Invalid Article ID:

{
  "success": false,
  "messages": ["Invalid article ID format"]
}

🧪 Curl Examples

1. Approve Article dengan Message:

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": "Article content is good, approved for next level"
  }'

2. Approve Article tanpa Message:

curl -X POST "http://localhost:8080/api/article-approval-flows/articles/123/approve" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{}'

3. Approve Article dengan Message Spesifik:

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": "Reviewed and approved. Content meets quality standards."
  }'

🔄 How It Works

  1. Input: User hanya perlu memberikan article ID
  2. Find Active Flow: Sistem mencari approval flow yang aktif untuk artikel tersebut
  3. Multi-Branch Logic: Sistem menggunakan multi-branch approval logic yang sudah ada
  4. Process Approval: Approval diproses sesuai dengan workflow yang sedang berjalan
  5. Response: Return informasi tentang approval yang telah diproses

🎯 Benefits

Before (Complex):

# User perlu tahu flow ID dan step
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
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"}'

🔒 Authentication

API ini memerlukan authentication token. Token harus disertakan di header:

Authorization: Bearer YOUR_JWT_TOKEN

⚠️ Important Notes

  1. Active Flow Required: Artikel harus memiliki approval flow yang aktif
  2. Multi-Branch Support: Menggunakan multi-branch approval logic yang sudah ada
  3. Automatic Detection: Sistem otomatis mendeteksi flow yang sedang aktif
  4. User Level Validation: Approval hanya bisa dilakukan oleh user dengan level yang sesuai
  5. Workflow Progression: Approval akan mengikuti workflow yang sudah dikonfigurasi

🚨 Error Handling

Common Errors:

  1. No Active Flow (400):

    • Artikel tidak memiliki approval flow yang aktif
    • Approval flow sudah selesai atau dibatalkan
  2. Invalid Article ID (400):

    • Article ID tidak valid atau tidak ditemukan
  3. Authentication Error (401):

    • Invalid atau missing token
    • Expired token
  4. Authorization Error (403):

    • User tidak memiliki permission untuk approve artikel ini
    • User level tidak sesuai dengan step yang sedang berjalan
  5. Server Error (500):

    • Database error
    • Workflow processing error

🔄 Workflow Integration

API ini terintegrasi dengan:

  • Multi-Branch Approval Logic
  • User Level Validation
  • Workflow Step Progression
  • Approval History Logging
  • Notification System

📊 Use Cases

  1. Simple Approval: User yang tidak perlu tahu detail workflow
  2. Mobile App: Interface yang sederhana untuk mobile
  3. Bulk Operations: Approve multiple articles dengan script
  4. Third-party Integration: API yang mudah digunakan oleh sistem eksternal

🔄 Comparison with Existing APIs

Feature Old API New API
Complexity High (need flow ID) Low (only article ID)
User Experience Complex Simple
Error Handling Manual flow detection Automatic
Multi-Branch Supported Supported
Workflow Logic Full control Automatic

🎉 Migration Guide

From Old API:

# Old way
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"}'

To New API:

# New way (simpler)
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"}'

🎉 API ini memberikan pengalaman yang lebih sederhana dan user-friendly untuk proses approval artikel!

User tidak perlu lagi mengetahui flow ID atau step yang sedang berjalan - cukup masukkan article ID dan sistem akan menangani sisanya secara otomatis. 🚀