Skip to content

Endpoint to check for existent rule #496

@bracyw

Description

@bracyw

Description

Check if a rule with a given topic and expression already exists (in service of editing rules, or creating new ones, to avoid creating duplicate rules and for convenience if the client ever wants to check if a rule exists still server side)

Related diagram:

sequenceDiagram
    participant User
    participant Client
    participant Server
    
    User->>Client: Click Add button
    
    Note over Client,Server: (a) Check for Existing Rule
    Client->>Server: POST /rules/check (topic, expr)
    Note right of Server: Check if rule exists in rules hashmap
    Server-->>Client: Return rule_id or null
    
    Note over Client: (b) User Confirmation Flow
    alt Matching rule exists
        Client->>User: Ask: Sure you want to make rule again?
        User->>Client: Confirm
    else No matching rule
        Note over Client: Continue to add
    end
    
    Note over Client,Server: (c) Add Rule
    Client->>Server: POST /rules/add (Rule, client_id)
    Note right of Server: (d) Server Logic: Insert (client, rule_id) into BiMap, Add rule_id to topic_index, Insert rule into rules hashmap
    Server->>Server: Add rule
    Server-->>Client: Success response
    
    Note over Client,User: (e) UI Update
    Client->>User: Update rule list display
Loading

Acceptance Criteria

  • Returns existing rule_id if found
  • Returns null/404 if not found

Proposed Solution

POST /rules/check
Body: { topic: Topic, expr: String }
Response: { rule_id?: RuleId }

Add check_rule() method to RuleManager in rule_structs.rs, add endpoint to rule_controller.rs. Reference get_all_rules() for hashmap read pattern. Test using Postman for basic functionality, then add tests to rule_structs_test.rs.

Mocks

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    mediumA more complex taskscylla-serverDevelopment Focused in the Backend

    Type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions