kontenhumas-be/docs/COMPREHENSIVE_WORKFLOW_DETA...

13 KiB

Comprehensive Workflow Detail API

Overview

API endpoint untuk mendapatkan detail lengkap dari Approval Workflow beserta semua data terkait termasuk steps, client settings, dan informasi pendukung lainnya.

Endpoint

POST /approval-workflows/comprehensive-details

Request

Headers

Authorization: Bearer <access_token>
Content-Type: application/json

Request Body

{
  "workflowId": 1
}

Request Structure

type ComprehensiveWorkflowDetailRequest struct {
    WorkflowId uint `json:"workflowId" validate:"required"`
}

Response

Success Response (200)

{
  "success": true,
  "messages": ["Comprehensive workflow details retrieved successfully"],
  "data": {
    "workflow": {
      "id": 1,
      "name": "Standard Article Approval",
      "description": "Standard approval workflow for articles",
      "isDefault": true,
      "isActive": true,
      "requiresApproval": true,
      "autoPublish": false,
      "clientId": "123e4567-e89b-12d3-a456-426614174000",
      "createdAt": "2024-01-01T00:00:00Z",
      "updatedAt": "2024-01-01T00:00:00Z",
      "totalSteps": 3,
      "activeSteps": 3,
      "hasBranches": false,
      "maxStepOrder": 3
    },
    "steps": [
      {
        "id": 1,
        "workflowId": 1,
        "stepOrder": 1,
        "stepName": "Content Review",
        "requiredUserLevelId": 2,
        "requiredUserLevelName": "Editor",
        "canSkip": false,
        "autoApproveAfterHours": null,
        "isActive": true,
        "parentStepId": null,
        "parentStepName": null,
        "conditionType": null,
        "conditionValue": null,
        "isParallel": false,
        "branchName": null,
        "branchOrder": null,
        "hasChildren": false,
        "isFirstStep": true,
        "isLastStep": false
      },
      {
        "id": 2,
        "workflowId": 1,
        "stepOrder": 2,
        "stepName": "Final Approval",
        "requiredUserLevelId": 3,
        "requiredUserLevelName": "Manager",
        "canSkip": false,
        "autoApproveAfterHours": null,
        "isActive": true,
        "parentStepId": null,
        "parentStepName": null,
        "conditionType": null,
        "conditionValue": null,
        "isParallel": false,
        "branchName": null,
        "branchOrder": null,
        "hasChildren": false,
        "isFirstStep": false,
        "isLastStep": true
      }
    ],
    "clientSettings": {
      "id": 1,
      "clientId": "123e4567-e89b-12d3-a456-426614174000",
      "requiresApproval": true,
      "defaultWorkflowId": 1,
      "defaultWorkflowName": "Standard Article Approval",
      "autoPublishArticles": false,
      "approvalExemptUsers": [1, 2],
      "approvalExemptRoles": [1],
      "approvalExemptCategories": [1, 2],
      "requireApprovalFor": ["articles", "news"],
      "skipApprovalFor": ["announcements"],
      "isActive": true,
      "createdAt": "2024-01-01T00:00:00Z",
      "updatedAt": "2024-01-01T00:00:00Z",
      "exemptUsersDetails": [
        {
          "id": 1,
          "username": "admin",
          "fullname": "Administrator",
          "email": "admin@example.com",
          "userLevelId": 1,
          "userLevelName": "Super Admin",
          "isActive": true
        }
      ],
      "exemptRolesDetails": [
        {
          "id": 1,
          "roleName": "Super Admin",
          "isActive": true
        }
      ],
      "exemptCategoriesDetails": [
        {
          "id": 1,
          "categoryName": "Announcements",
          "isActive": true
        }
      ]
    },
    "relatedData": {
      "userLevels": [
        {
          "id": 1,
          "name": "Super Admin",
          "aliasName": "super_admin",
          "levelNumber": 1,
          "isApprovalActive": true,
          "isActive": true
        },
        {
          "id": 2,
          "name": "Editor",
          "aliasName": "editor",
          "levelNumber": 2,
          "isApprovalActive": true,
          "isActive": true
        }
      ]
    },
    "statistics": {
      "totalArticlesProcessed": 0,
      "pendingArticles": 0,
      "approvedArticles": 0,
      "rejectedArticles": 0,
      "averageProcessingTime": 0,
      "mostActiveStep": "",
      "lastUsedAt": null
    },
    "lastUpdated": "2024-01-01T00:00:00Z"
  }
}

Response Structure

ComprehensiveWorkflowDetailResponse

type ComprehensiveWorkflowDetailResponse struct {
    Workflow       WorkflowDetailInfo           `json:"workflow"`
    Steps          []WorkflowStepDetailInfo     `json:"steps"`
    ClientSettings ClientApprovalSettingsDetail `json:"clientSettings"`
    RelatedData    RelatedDataInfo              `json:"relatedData"`
    Statistics     WorkflowStatisticsInfo       `json:"statistics"`
    LastUpdated    time.Time                    `json:"lastUpdated"`
}

WorkflowDetailInfo

type WorkflowDetailInfo struct {
    ID               uint      `json:"id"`
    Name             string    `json:"name"`
    Description      *string   `json:"description"`
    IsDefault        *bool     `json:"isDefault"`
    IsActive         *bool     `json:"isActive"`
    RequiresApproval *bool     `json:"requiresApproval"`
    AutoPublish      *bool     `json:"autoPublish"`
    ClientId         *string   `json:"clientId"`
    CreatedAt        time.Time `json:"createdAt"`
    UpdatedAt        time.Time `json:"updatedAt"`
    
    // Additional workflow info
    TotalSteps   int  `json:"totalSteps"`
    ActiveSteps  int  `json:"activeSteps"`
    HasBranches  bool `json:"hasBranches"`
    MaxStepOrder int  `json:"maxStepOrder"`
}

WorkflowStepDetailInfo

type WorkflowStepDetailInfo struct {
    ID                    uint   `json:"id"`
    WorkflowId            uint   `json:"workflowId"`
    StepOrder             int    `json:"stepOrder"`
    StepName              string `json:"stepName"`
    RequiredUserLevelId   uint   `json:"requiredUserLevelId"`
    RequiredUserLevelName string `json:"requiredUserLevelName"`
    CanSkip               *bool  `json:"canSkip"`
    AutoApproveAfterHours *int   `json:"autoApproveAfterHours"`
    IsActive              *bool  `json:"isActive"`
    
    // Multi-branch support fields
    ParentStepId   *uint   `json:"parentStepId"`
    ParentStepName *string `json:"parentStepName"`
    ConditionType  *string `json:"conditionType"`
    ConditionValue *string `json:"conditionValue"`
    IsParallel     *bool   `json:"isParallel"`
    BranchName     *string `json:"branchName"`
    BranchOrder    *int    `json:"branchOrder"`
    
    // Additional step info
    HasChildren bool `json:"hasChildren"`
    IsFirstStep bool `json:"isFirstStep"`
    IsLastStep  bool `json:"isLastStep"`
}

ClientApprovalSettingsDetail

type ClientApprovalSettingsDetail struct {
    ID                       uint                    `json:"id"`
    ClientId                 string                  `json:"clientId"`
    RequiresApproval         *bool                   `json:"requiresApproval"`
    DefaultWorkflowId        *uint                   `json:"defaultWorkflowId"`
    DefaultWorkflowName      *string                 `json:"defaultWorkflowName"`
    AutoPublishArticles      *bool                   `json:"autoPublishArticles"`
    ApprovalExemptUsers      []uint                  `json:"approvalExemptUsers"`
    ApprovalExemptRoles      []uint                  `json:"approvalExemptRoles"`
    ApprovalExemptCategories []uint                  `json:"approvalExemptCategories"`
    RequireApprovalFor       []string                `json:"requireApprovalFor"`
    SkipApprovalFor          []string                `json:"skipApprovalFor"`
    IsActive                 *bool                   `json:"isActive"`
    CreatedAt                time.Time               `json:"createdAt"`
    UpdatedAt                time.Time               `json:"updatedAt"`
    
    // Detailed exempt information
    ExemptUsersDetails      []UserDetailInfo      `json:"exemptUsersDetails"`
    ExemptRolesDetails      []UserRoleDetailInfo  `json:"exemptRolesDetails"`
    ExemptCategoriesDetails []CategoryDetailInfo  `json:"exemptCategoriesDetails"`
}

RelatedDataInfo

type RelatedDataInfo struct {
    UserLevels []UserLevelDetailInfo `json:"userLevels"`
}

WorkflowStatisticsInfo

type WorkflowStatisticsInfo struct {
    TotalArticlesProcessed int     `json:"totalArticlesProcessed"`
    PendingArticles        int     `json:"pendingArticles"`
    ApprovedArticles       int     `json:"approvedArticles"`
    RejectedArticles       int     `json:"rejectedArticles"`
    AverageProcessingTime  int     `json:"averageProcessingTime"`
    MostActiveStep         string  `json:"mostActiveStep"`
    LastUsedAt             *string `json:"lastUsedAt"`
}

Error Responses

400 Bad Request

{
  "success": false,
  "messages": ["Validation failed: workflowId is required"],
  "data": null
}

401 Unauthorized

{
  "success": false,
  "messages": ["Unauthorized access"],
  "data": null
}

404 Not Found

{
  "success": false,
  "messages": ["Workflow not found"],
  "data": null
}

500 Internal Server Error

{
  "success": false,
  "messages": ["Internal server error"],
  "data": null
}

Features

1. Comprehensive Workflow Information

  • Detail lengkap workflow termasuk metadata dan statistik
  • Informasi step dengan hierarki dan kondisi
  • Status aktif/inaktif dan konfigurasi approval

2. Detailed Step Information

  • Informasi lengkap setiap step dalam workflow
  • Nama user level yang diperlukan untuk approval
  • Konfigurasi skip, auto-approve, dan kondisi
  • Dukungan multi-branch workflow

3. Client Settings Integration

  • Pengaturan approval global untuk client
  • Daftar user, role, dan kategori yang dikecualikan
  • Informasi detail untuk setiap exemption
  • Workflow default yang digunakan
  • Daftar user level yang tersedia
  • Data pendukung untuk konfigurasi workflow
  • Informasi terkait untuk referensi

5. Statistics Information

  • Statistik penggunaan workflow (placeholder untuk implementasi future)
  • Informasi performa dan aktivitas
  • Data untuk monitoring dan analisis

Use Cases

1. Workflow Management Dashboard

  • Menampilkan detail lengkap workflow untuk administrator
  • Monitoring status dan konfigurasi workflow
  • Analisis performa dan penggunaan

2. Workflow Configuration

  • Mengedit workflow dengan informasi lengkap
  • Mengatur step dan kondisi approval
  • Konfigurasi exemption dan pengaturan client

3. Approval Process Monitoring

  • Melihat status artikel dalam proses approval
  • Tracking progress melalui step workflow
  • Monitoring bottleneck dan performa

4. Client Settings Management

  • Mengatur pengaturan approval global
  • Mengelola exemption untuk user dan kategori
  • Konfigurasi workflow default

Implementation Notes

1. Performance Considerations

  • API menggunakan single query dengan join untuk efisiensi
  • Data related diambil secara terpisah untuk fleksibilitas
  • Caching dapat diimplementasikan untuk data yang jarang berubah

2. Security

  • Menggunakan authentication token untuk akses
  • Validasi clientId dari token untuk multi-tenant
  • Authorization check untuk akses workflow

3. Error Handling

  • Graceful handling untuk data yang tidak ditemukan
  • Logging untuk debugging dan monitoring
  • Rollback mechanism untuk operasi yang gagal

4. Extensibility

  • Struktur response dapat diperluas untuk kebutuhan future
  • Statistics dapat diimplementasikan dengan query yang lebih kompleks
  • Support untuk workflow yang lebih kompleks

Dependencies

Required Repositories

  • ApprovalWorkflowsRepository
  • ApprovalWorkflowStepsRepository
  • ClientApprovalSettingsRepository
  • UsersRepository
  • UserLevelsRepository
  • UserRolesRepository
  • ArticleCategoriesRepository
  • ArticleApprovalFlowsRepository

Required Services

  • ApprovalWorkflowsService
  • ClientApprovalSettingsService

Testing

Unit Tests

func TestGetComprehensiveWorkflowDetails(t *testing.T) {
    // Test cases for comprehensive workflow details
    // Test with valid workflow ID
    // Test with invalid workflow ID
    // Test with missing client settings
    // Test with empty steps
}

Integration Tests

func TestComprehensiveWorkflowDetailsAPI(t *testing.T) {
    // Test API endpoint
    // Test authentication
    // Test response structure
    // Test error handling
}

Future Enhancements

1. Real-time Statistics

  • Implementasi query untuk statistik real-time
  • Monitoring performa workflow
  • Analytics dan reporting

2. Workflow Templates

  • Template workflow yang dapat digunakan kembali
  • Import/export workflow configuration
  • Workflow marketplace

3. Advanced Branching

  • Conditional workflow berdasarkan konten
  • Dynamic step generation
  • AI-powered workflow optimization

4. Integration Features

  • Webhook untuk notifikasi
  • API untuk external system integration
  • Workflow automation triggers