search_service.py


Overview

The search_service.py file defines the SearchService class, which provides data access and business logic related to "Search" entities within the InfiniFlow application. It acts as a service layer interfacing with the database models to perform CRUD operations, filtering, pagination, access control, and detailed retrieval of search records. This service builds upon a common base service and integrates tightly with user and status models to ensure data integrity and permission checks.

Key functionalities include:

This service plays a crucial role in managing "Search" objects in the system, encapsulating database interactions and enforcing business rules.


Class: SearchService

Inherits from: CommonService

SearchService is a specialized service class dedicated to managing Search model objects. It extends CommonService to reuse common database interaction patterns and adds methods specific to the search domain.

Properties


Methods


save(**kwargs)

Creates and saves a new Search record in the database.


accessible4deletion(search_id: int, user_id: int) -> bool

Checks if a specific Search record is accessible for deletion by a particular user.


get_detail(search_id: int) -> dict

Retrieves detailed information for a single Search record, including related tenant user data.


get_by_tenant_ids(joined_tenant_ids: list[int], user_id: int, page_number: int, items_per_page: int, orderby: str, desc: bool, keywords: str) -> tuple[list[dict], int]

Queries and paginates search records filtered by tenants, user ownership, keywords, and sorted by specified fields.


Important Implementation Details


Interaction with Other Parts of the System


Visual Diagram: Class Structure of SearchService

classDiagram
    class CommonService {
        <<abstract>>
        +model
        +save()
        +getter_by(field)
    }

    class SearchService {
        +model = Search
        +save(**kwargs)
        +accessible4deletion(search_id, user_id) bool
        +get_detail(search_id) dict
        +get_by_tenant_ids(joined_tenant_ids, user_id, page_number, items_per_page, orderby, desc, keywords) tuple[list[dict], int]
    }

    SearchService --|> CommonService

Summary

The search_service.py module encapsulates all business logic and database access patterns related to managing Search entities. It provides a clear interface for creating, querying, retrieving details, and validating permissions on search records. Leveraging Peewee ORM, it integrates robust querying capabilities with pagination, filtering, and sorting. This service is a foundational component for any feature that requires managing or displaying search configurations within the InfiniFlow platform.