Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add search api for apps/devices/instances #4764

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

knolleary
Copy link
Member

@knolleary knolleary commented Nov 13, 2024

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:

  • team : the team id to search within. This is a required property for this iteration - but will allow us to enable account-wide search for a user in the future if so needed.
  • query : string search term.

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"
            }
        }
    ]
}

Copy link

codecov bot commented Nov 13, 2024

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 (0b4c35f) to head (37cdc1e).

Files with missing lines Patch % Lines
forge/db/models/Device.js 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4764      +/-   ##
==========================================
+ Coverage   78.79%   78.84%   +0.05%     
==========================================
  Files         311      312       +1     
  Lines       14782    14827      +45     
  Branches     3385     3395      +10     
==========================================
+ Hits        11647    11691      +44     
- Misses       3135     3136       +1     
Flag Coverage Δ
backend 78.84% <98.21%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@knolleary knolleary requested a review from cstns November 14, 2024 13:15
@knolleary knolleary marked this pull request as ready for review November 14, 2024 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create search api
1 participant