CSV Download Request

Overview Description

The CSV Download Request functionality allows users to request downloading review sentences data from wishlist datasets as CSV files. When a user sends a request, the system creates a record in the wishlist_dataset_gcs_path table with status "new" (0), then a batch job processes the request to create a CSV file and upload it to Google Cloud Storage.

Swagger Link

API: CSV Download Request API

Case 1: Successful CSV Download Request

Description

User successfully sends a CSV download request with valid information.

Sequence Diagram

sequenceDiagram
    participant Client
    participant ReviewDownloadController as ReviewDownloadController
    participant ProductAnalyzerService as ProductAnalyzerService
    participant WishlistDatasetGcsPath as WishlistDatasetGcsPath
    participant Database

    Note over Client,Database: CSV Download Request Flow

    rect rgb(200, 255, 200)
    Note right of Client: Happy Case Flow

    Client->>ReviewDownloadController: POST /api/v1/general/review/csv/download (params)

    rect rgb(200, 230, 255)
    Note right of ReviewDownloadController: Input Validation
    ReviewDownloadController->>ReviewDownloadController: Validate request parameters
    end

    rect rgb(200, 255, 255)
    Note right of ReviewDownloadController: Business Logic
    ReviewDownloadController->>ProductAnalyzerService: requestDownloadCsv(params, wishlistDataset)
    ProductAnalyzerService->>ProductAnalyzerService: Process parameters and validate request
    ProductAnalyzerService->>WishlistDatasetGcsPath: Create record with status 'new'
    WishlistDatasetGcsPath->>Database: INSERT INTO wishlist_dataset_gcs_path
    Database-->>WishlistDatasetGcsPath: Return created record
    WishlistDatasetGcsPath-->>ProductAnalyzerService: Return success
    ProductAnalyzerService-->>ReviewDownloadController: Return true
    end

    ReviewDownloadController-->>Client: 200 OK (success message)
    end

    rect rgb(255, 200, 200)
    Note right of Client: Error Handling
    rect rgb(255, 230, 230)
    alt Validation Error
        ReviewDownloadController-->>Client: 422 Validation Error
    else Service Error
        ProductAnalyzerService-->>ReviewDownloadController: Service error
        ReviewDownloadController-->>Client: 400 Error
    end
    end
    end

Steps

Step 1: CSV Download Request

  • Description: User sends CSV download request
  • Request: POST /api/v1/general/review/csv/download
  • Validation:
    • wldh_slug: Slug of wishlist dataset history (required)

Step 2: Process Business Logic

  • Description: Process business logic and create record
  • Action:
    • Check user authentication
    • Create record in wishlist_dataset_gcs_path table

Step 3: Create Database Record

  • Description: Save download request information to database
  • Action:
    • Create record with status = 0 (new)
    • Save user and dataset information
    • Store config parameters as JSON

Step 4: Return Success Response

  • Description: Return success response
  • Response:
    • Success: 200 OK with success message
    • Error: Appropriate error code with message

Database Related Tables & Fields

erDiagram
    wishlist_dataset_gcs_path {
        bigint id PK
        bigint dataset_id "Dataset ID (indexed)"
        bigint user_id FK "User ID who requested download (indexed)"
        integer status "Status: 0: new, 1: processing, 2: completed, 3: failed (indexed)"
        string gcs_link "Link to CSV file on GCS (nullable)"
        string error_message "Error message if any (nullable)"
        timestamp created_at
        timestamp updated_at
    }
    users {
        bigint id PK
        string name "User's full name"
        string email "User's email address"
    }

    users ||--o{ wishlist_dataset_gcs_path : requests

Error Handling

  • Log
    • Download request failures logged to application log
    • Validation errors logged for debugging
  • Error Detail:
    Status Code Error Message Description
    422 "Validation failed" When parameters are invalid
    401 "Unauthorized" When user is not authenticated
    404 "Dataset not found" When dataset is not found
    500 "Internal server error" When system error occurs