Temporary Wishlist Search Query Management

Description

The Temporary Wishlist Search Query Management feature allows users to manage search query items within a temporary wishlist before converting them to official wishlists. This module provides functionality to list, add, and delete temporary wishlist search queries with mall-specific validation and keyword analysis support.

Activity Diagram

---
config:
  theme: base
  flowchart:
    curve: linear
    htmlLabels: true
  themeVariables:
    edgeLabelBackground: "transparent"
---
flowchart TD
    Start([User accesses temp wishlist])
    TempWishlistSearchQueries[(temp_wishlist_search_queries)]
    Malls[(malls)]
    
    subgraph Controllers
        SearchQueryController[TempWishlistSearchQueryController]
    end
    
    subgraph Services
        SearchQueryService(TempWishlistSearchQueryService)
    end
    
    subgraph Models
        SearchQueryModel[[TempWishlistSearchQuery]]
        MallModel[[Mall]]
    end
    
    Start --> SearchQueryController
    
    SearchQueryController --- ListStep[
        <div style='text-align: center'>
            <span style='display: inline-block; background-color: #6699cc !important; color:white; width: 28px; height: 28px; line-height: 28px; border-radius: 50%; font-weight: bold'>1</span>
            <p style='margin-top: 8px'>List Search Queries</p>
        </div>
    ]
    ListStep --> SearchQueryService
    
    SearchQueryController --- AddStep[
        <div style='text-align: center'>
            <span style='display: inline-block; background-color: #6699cc !important; color:white; width: 28px; height: 28px; line-height: 28px; border-radius: 50%; font-weight: bold'>2</span>
            <p style='margin-top: 8px'>Add Search Query</p>
        </div>
    ]
    AddStep --> SearchQueryService
    
    SearchQueryController --- DeleteStep[
        <div style='text-align: center'>
            <span style='display: inline-block; background-color: #6699cc !important; color:white; width: 28px; height: 28px; line-height: 28px; border-radius: 50%; font-weight: bold'>3</span>
            <p style='margin-top: 8px'>Delete Search Query</p>
        </div>
    ]
    DeleteStep --> SearchQueryService
    
    SearchQueryService --> SearchQueryModel
    SearchQueryModel --> TempWishlistSearchQueries
    SearchQueryModel -.-> MallModel
    MallModel --> Malls
    
    %% Styling
    style SearchQueryController fill:#e6f3ff,stroke:#0066cc,stroke-width:2px
    style SearchQueryService fill:#f0f8e6,stroke:#339933,stroke-width:2px
    style SearchQueryModel fill:#fff0f5,stroke:#cc6699,stroke-width:2px
    style MallModel fill:#fff0f5,stroke:#cc6699,stroke-width:2px
    style TempWishlistSearchQueries fill:#ffe6cc,stroke:#ff9900,stroke-width:2px
    style Malls fill:#ffe6cc,stroke:#ff9900,stroke-width:2px
    style ListStep fill:transparent,stroke:transparent,stroke-width:1px
    style AddStep fill:transparent,stroke:transparent,stroke-width:1px
    style DeleteStep fill:transparent,stroke:transparent,stroke-width:1px

Detail Dataflow Dependency

Step-by-Step Process

Step 1: Retrieve Temporary Wishlist Search Queries

  • Description: System retrieves all temporary wishlist search queries associated with a specific temporary wishlist group
  • Action: Query the database for all search queries associated with the temporary wishlist group ID
  • Input: Temporary wishlist group ID
  • Output: List of temporary wishlist search queries with their details (keyword, mall ID)
  • Dependencies: Temporary wishlist group must exist in the database

Step 2: Mall-Specific Keyword Validation

  • Description: System validates the search keyword against mall-specific requirements
  • Action: Check if the keyword format is valid for the selected mall
  • Input: Search keyword and mall ID
  • Output: Validated search query data or validation error
  • Dependencies: Mall configuration in the system

Step 3: Keyword Analysis and Normalization

  • Description: System analyzes and normalizes the search keyword
  • Action: Remove special characters, normalize spaces, and check for minimum length
  • Input: Raw search keyword
  • Output: Normalized search keyword
  • Dependencies: Keyword validation rules based on mall requirements

Step 4: Search Query Storage/Deletion

  • Description: System stores new search query or deletes existing search query from the temporary wishlist
  • Action: Insert new record or delete existing record from the database
  • Input: Validated search query data or search query ID to delete
  • Output: Success message or error message
  • Dependencies: Valid database connection and proper authorization

Database Related Tables & Fields

Database: gb_console

erDiagram
    temp_wishlist_to_groups {
        bigint id PK
        bigint user_id FK
        bigint group_id FK
        string name "Name of the wishlist"
        string slug "Slug of the wishlist"
        tinyInteger status "1: Temporary Save, 2: CSV Import Draft"
    }
    
    temp_wishlist_search_queries {
        bigint id PK
        bigint temp_wishlist_to_group_id FK
        string keyword "The keyword to search"
        bigint mall_id FK
    }
    
    malls {
        bigint id PK
        string name
        string slug
    }

    temp_wishlist_to_groups ||--o{ temp_wishlist_search_queries : "has many"
    malls ||--o{ temp_wishlist_search_queries : "belongs to"

Case Documentation

Case 1: List Temporary Wishlist Search Queries

API: Get Temporary Wishlist Search Queries

Sequence Diagram

sequenceDiagram
    participant Client
    participant Controller as TempWishlistSearchQueryController
    participant Service as TempWishlistSearchQueryService
    participant Repository as TempWishlistSearchQueryRepository
    participant Database
    
    rect rgb(200, 255, 200)
    Note right of Client: Happy Case - List Search Queries
    
    Client->>Controller: GET /api/v1/temp-wishlist-search-query?temp_wishlist_to_group_id={id}
    Controller->>Service: list(params)
    
    Service->>Repository: getByWishlistToGroupId(wishlistToGroupId)
    Repository->>Database: Query WHERE temp_wishlist_to_group_id = ?
    Database-->>Repository: Return search queries
    Repository-->>Service: Return search queries collection
    
    Service->>Service: Format search queries data
    Service-->>Controller: Return formatted search queries
    Controller-->>Client: Return JSON response with search queries
    end
    
    rect rgb(255, 200, 200)
    Note right of Client: Error Handling
    
    rect rgb(255, 230, 230)
    alt Invalid wishlist group ID
        Client->>Controller: GET /api/v1/temp-wishlist-search-query?temp_wishlist_to_group_id=invalid
        Controller->>Service: list(params)
        Service->>Repository: getByWishlistToGroupId(wishlistToGroupId)
        Repository->>Database: Query WHERE temp_wishlist_to_group_id = ?
        Database-->>Repository: Return empty result
        Repository-->>Service: Return empty collection
        Service-->>Controller: Return empty collection
        Controller-->>Client: Return empty data array
    end
    end
    end

Steps

  1. Client sends GET request to retrieve temporary wishlist search queries for a specific group
  2. Controller receives the request and calls the service layer
  3. Service layer fetches search queries from the repository using the wishlist group ID
  4. Repository queries the database and returns the search queries collection
  5. Search queries are formatted and returned to the client as a JSON response

Error Handling

  • If the wishlist group ID is invalid or not found, an empty data array is returned
  • If the user doesn't have permission to access the wishlist group, a 403 Forbidden error is returned
  • If a system error occurs, a 500 Internal Server Error is returned with an error message

Case 2: Delete Temporary Wishlist Search Query

API: Delete Temporary Wishlist Search Query

Sequence Diagram

sequenceDiagram
    participant Client
    participant Controller as TempWishlistSearchQueryController
    participant Service as TempWishlistSearchQueryService
    participant Repository as TempWishlistSearchQueryRepository
    participant Database
    
    rect rgb(200, 255, 200)
    Note right of Client: Happy Case - Delete Search Query
    
    Client->>Controller: DELETE /api/v1/temp-wishlist-search-query/{id}
    Controller->>Service: delete(id)
    
    Service->>Repository: findById(id)
    Repository->>Database: Query WHERE id = ?
    Database-->>Repository: Return search query
    Repository-->>Service: Return search query
    
    rect rgb(255, 255, 200)
    Note right of Service: Authorization Check
    Service->>Service: Verify user can delete search query
    end
    
    Service->>Repository: delete(id)
    Repository->>Database: DELETE/Soft Delete WHERE id = ?
    Database-->>Repository: Confirm deletion
    Repository-->>Service: Return success
    
    Service-->>Controller: Return success result
    Controller-->>Client: Return success JSON response
    end
    
    rect rgb(255, 200, 200)
    Note right of Client: Error Handling
    
    rect rgb(255, 230, 230)
    alt Search Query Not Found
        Client->>Controller: DELETE /api/v1/temp-wishlist-search-query/999999
        Controller->>Service: delete(id)
        Service->>Repository: findById(id)
        Repository->>Database: Query WHERE id = ?
        Database-->>Repository: Return null
        Repository-->>Service: Return null
        Service-->>Controller: Return not found error
        Controller-->>Client: Return 404 Not Found
    else Unauthorized Access
        Client->>Controller: DELETE /api/v1/temp-wishlist-search-query/{id}
        Controller->>Service: delete(id)
        Service->>Repository: findById(id)
        Repository->>Database: Query WHERE id = ?
        Database-->>Repository: Return search query
        Repository-->>Service: Return search query
        Service->>Service: Verify user can delete search query
        Service-->>Controller: Return unauthorized error
        Controller-->>Client: Return 403 Forbidden
    end
    end
    end

Steps

  1. Client sends DELETE request with the search query ID
  2. Controller receives the request and calls the service layer
  3. Service layer verifies the search query exists and the user has permission to delete it
  4. If authorized, the search query is deleted (typically a soft delete)
  5. Success response is returned to the client

Error Handling

  • If the search query ID is not found, a 404 Not Found error is returned
  • If the user doesn't have permission to delete the search query, a 403 Forbidden error is returned
  • If a system error occurs during deletion, a 500 Internal Server Error is returned with an error message