FlowFuse / flowfuse

Connect, collect, transform, visualise, and interact with your Industrial Data in a single platform. Use FlowFuse to manage, scale and secure your Node-RED solutions.
https://flowfuse.com
Other
285 stars 64 forks source link

Add search api for apps/devices/instances #4764

Closed knolleary closed 3 days ago

knolleary commented 1 week ago

Closes #4756

Description

Adds GET /api/v1/search as a general search endpoint for a user's resources.

For this iteration, it searches Applications, Instances and Devices in a given team using their name property.

The endpoint accepts two query params:

I have reused existing model find functions by adding an optional query parameter.

The response object looks like this. Each object in the results array has an object property to identify the type of thing it is. It then contains properties for that thing largely consistent with existing 'summary' views. This should give us enough info to render the search results sensibly.

For instances, there are a couple more bits to look at adding around dashboard usage and current state - but this should be good enough to get started.

{
    "count": 3,
    "results": [
        {
            "object": "application",
            "id": "p8QoZboADe",
            "name": "Debugging Demo",
            "description": "",
            "links": {
                "self": "http://127.0.0.1:3000/api/v1/applications/p8QoZboADe"
            },
            "deviceCount": 0,
            "instanceCount": 2,
            "deviceGroupCount": 0,
            "snapshotCount": 18,
            "pipelineCount": 2
        },
        {
            "object": "instance",
            "id": "33b340ca-1400-4de1-884c-ed19792592d6",
            "name": "debugging-demo",
            "url": "http://debugging-demo.example.com",
            "createdAt": "2023-05-11T14:41:51.094Z",
            "updatedAt": "2024-11-11T15:58:48.873Z",
            "links": {
                "self": "http://127.0.0.1:3000/api/v1/projects/33b340ca-1400-4de1-884c-ed19792592d6"
            },
            "protected": {
                "enabled": false
            }
        },
        {
            "object": "device",
            "id": "mYLjNYqMDn",
            "ownerType": null,
            "name": "demo1",
            "type": "my new thing",
            "lastSeenAt": "2022-08-02T13:32:02.000Z",
            "lastSeenMs": 71977676685,
            "status": "unknown",
            "mode": "autonomous",
            "isDeploying": false,
            "links": {
                "self": "http://127.0.0.1:3000/api/v1/devices/mYLjNYqMDn"
            }
        }
    ]
}
codecov[bot] commented 1 week ago

Codecov Report

Attention: Patch coverage is 98.21429% with 1 line in your changes missing coverage. Please review.

Project coverage is 78.84%. Comparing base (becdc3e) to head (81900e9). Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
forge/db/models/Device.js 88.88% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #4764 +/- ## ========================================== + Coverage 78.79% 78.84% +0.05% ========================================== Files 311 312 +1 Lines 14791 14836 +45 Branches 3387 3397 +10 ========================================== + Hits 11654 11698 +44 - Misses 3137 3138 +1 ``` | [Flag](https://app.codecov.io/gh/FlowFuse/flowfuse/pull/4764/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FlowFuse) | Coverage Δ | | |---|---|---| | [backend](https://app.codecov.io/gh/FlowFuse/flowfuse/pull/4764/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FlowFuse) | `78.84% <98.21%> (+0.05%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FlowFuse#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.


🚨 Try these New Features: