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

Updates api routes for camera plugin integrations #9209

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

DraKen0009
Copy link

@DraKen0009 DraKen0009 commented Nov 25, 2024

Proposed Changes

Updated routes for the camera plugin integration in backend.

backend pr : ohcnetwork/care#2610

@ohcnetwork/care-fe-code-reviewers

Summary by CodeRabbit

  • New Features

    • Updated camera presets fetching mechanism to use external IDs for improved consistency.
    • Enhanced logic for managing camera presets in the ConsultationFeedTab component.
  • Bug Fixes

    • Refined handling of preset states to ensure accurate retrieval based on external IDs.
  • Chores

    • Streamlined API routing for camera presets, consolidating and renaming endpoints for clarity.

Copy link
Contributor

coderabbitai bot commented Nov 25, 2024

Walkthrough

The changes in this pull request involve updates to several components and routing definitions related to camera presets. The CameraFeedWithBedPresets, ConfigureCamera, and ConsultationFeedTab components have been modified to utilize new query parameters, specifically switching from using asset_id to asset_external_id and assetbed_id to assetbed_external_id. Additionally, the routing definitions have been restructured to streamline API calls, consolidating and renaming routes for clarity. The overall functionality and user experience remain consistent across these components despite the underlying data source modifications.

Changes

File Path Change Summary
src/components/CameraFeed/CameraFeedWithBedPresets.tsx Updated query to fetch camera presets using FeedRoutes.positionPresets.list with asset_external_id.
src/components/CameraFeed/ConfigureCamera.tsx Modified API calls to use assetbed_external_id instead of assetbed_id in cameraPresetsQuery.
src/components/CameraFeed/routes.ts Removed and updated routes for camera presets, introducing positionPresets.list and changing paths.
src/components/Facility/ConsultationDetails/ConsultationFeedTab.tsx Adjusted logic to use FeedRoutes.positionPresets.list with bed_external_id for querying presets.

Poem

In the fields where cameras play,
New paths are set, come what may.
External IDs now lead the way,
Presets dance in bright array.
Hopping through code with joy and cheer,
Changes made, the future's near! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Nov 25, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 6321bda
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/6744cf75cb8a5b0008067360
😎 Deploy Preview https://deploy-preview-9209--care-ohc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@DraKen0009 DraKen0009 marked this pull request as ready for review November 25, 2024 19:27
@DraKen0009 DraKen0009 requested a review from a team as a code owner November 25, 2024 19:27
Copy link

netlify bot commented Nov 25, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit d8091c5
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/6748b6d385e03d000873d58f
😎 Deploy Preview https://deploy-preview-9209--care-ohc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (1)
src/components/CameraFeed/routes.ts (1)

57-82: Consider API versioning strategy

The removal of the /api/v1/ prefix from all routes deviates from API versioning best practices. This could make future API version migrations more challenging.

Consider:

  1. Maintaining version prefix for better API lifecycle management
  2. Documenting the versioning strategy if it's intentionally removed
  3. Using API gateway or proxy layer to handle version routing if needed
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fdfc53d and fceb604.

📒 Files selected for processing (4)
  • src/components/CameraFeed/CameraFeedWithBedPresets.tsx (1 hunks)
  • src/components/CameraFeed/ConfigureCamera.tsx (4 hunks)
  • src/components/CameraFeed/routes.ts (1 hunks)
  • src/components/Facility/ConsultationDetails/ConsultationFeedTab.tsx (2 hunks)
🔇 Additional comments (6)
src/components/CameraFeed/CameraFeedWithBedPresets.tsx (1)

19-20: Verify asset.id contains the external ID

The code is passing props.asset.id as asset_external_id, but we need to verify if asset.id actually contains the external ID value expected by the backend.

Let's verify the AssetData type definition and usage:

Additionally, consider adding type safety:

 const { data, loading } = useQuery(FeedRoutes.listCameraPresets, {
-    query: { asset_external_id: props.asset.id, limit: 100 },
+    query: { 
+      asset_external_id: props.asset.external_id ?? props.asset.id,
+      limit: 100 
+    },
 });
src/components/CameraFeed/routes.ts (1)

57-65: Clarify the coexistence of similar routes

There appear to be two similar routes for listing camera presets:

  • listAssetBedPresets at /api/camera/assetbed/position_presets/
  • listCameraPresets at /api/camera/position_presets/

This could lead to confusion about which endpoint to use in different scenarios.

Let's check for usage patterns:

✅ Verification successful

Both routes serve different use cases and are correctly utilized

The coexistence of these routes is intentional and properly implemented:

  • listAssetBedPresets is used in ConfigureCamera.tsx with assetbed_external_id parameter
  • listCameraPresets is used in:
    • ConsultationFeedTab.tsx with bed_external_id parameter
    • CameraFeedWithBedPresets.tsx with asset_external_id parameter

Each route serves a specific context and accepts different query parameters, suggesting they are designed to handle distinct use cases rather than being duplicates.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages of both routes to understand the transition
echo "Searching for listAssetBedPresets usage:"
rg "listAssetBedPresets" -A 2

echo -e "\nSearching for listCameraPresets usage:"
rg "listCameraPresets" -A 2

Length of output: 1576

src/components/Facility/ConsultationDetails/ConsultationFeedTab.tsx (1)

119-121: LGTM! Verify the updatePreset endpoint compatibility.

The addition of assetbed_external_id in the query parameters is consistent with the API route updates.

Let's verify the endpoint compatibility:

✅ Verification successful

Endpoint compatibility verified for assetbed_external_id parameter

Both usages of FeedRoutes.updatePreset in the codebase consistently include the assetbed_external_id query parameter:

  • ConsultationFeedTab.tsx uses preset.asset_bed.id
  • ConfigureCamera.tsx uses selectedAssetBed.id
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the updatePreset endpoint usage and parameters
ast-grep --pattern 'FeedRoutes.updatePreset'

Length of output: 296


Script:

#!/bin/bash
# Let's check the implementation and usage of updatePreset route
ast-grep --pattern 'updatePreset = $$$'

# Also check the usage context in both files
rg -B 5 -A 5 "FeedRoutes.updatePreset" src/components/CameraFeed/ConfigureCamera.tsx src/components/Facility/ConsultationDetails/ConsultationFeedTab.tsx

Length of output: 2341


Script:

#!/bin/bash
# Let's check the ConfigureCamera.tsx implementation to see if it also uses assetbed_external_id
rg -A 10 "FeedRoutes.updatePreset" src/components/CameraFeed/ConfigureCamera.tsx

# Also check for any route definitions
ast-grep --pattern 'updatePreset: $$$'

Length of output: 706

src/components/CameraFeed/ConfigureCamera.tsx (3)

422-422: LGTM! Good error handling and user feedback

The API call is properly structured with appropriate error handling and success notification.


530-532: LGTM! Proper error handling and user feedback

The delete preset implementation includes appropriate error handling and success notification.


104-108: Verify if the position parameter is always required

The position parameter is hardcoded to true. Consider if this parameter is necessary since it seems to be always set to true.

✅ Verification successful

Let me gather more information about the API route and its usage.


Let me try a different approach to find the API route definition and type information.


Let me check the routes definition to understand the API parameters better.


Based on the routes file content, I can now generate the final response:

The position parameter is correctly set to true

The position parameter is required as it's a crucial part of the CameraPreset type definition, which includes a position: PTZPayload field. This field stores the pan-tilt-zoom coordinates for each preset, so requesting it in the list query is necessary for proper functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the position parameter is used differently in other files
rg -A 5 "FeedRoutes.listAssetBedPresets" 

Length of output: 503


Script:

#!/bin/bash
# Check the API route definition and other usages
rg -g "*.ts*" -A 5 "listAssetBedPresets.*=" 

# Check for any documentation or type definitions
ast-grep --pattern 'interface $_ {
  $$$
  position: $_
  $$$
}'

Length of output: 112


Script:

#!/bin/bash
# Search for route definitions
rg -g "*.ts*" "listAssetBedPresets"

# Look for any types or interfaces related to camera presets
rg -g "*.ts*" -B 2 -A 5 "type.*Preset|interface.*Preset"

Length of output: 3134


Script:

#!/bin/bash
# Check the routes file content
cat src/components/CameraFeed/routes.ts

Length of output: 2151

src/components/CameraFeed/routes.ts Outdated Show resolved Hide resolved
src/components/CameraFeed/ConfigureCamera.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
src/components/CameraFeed/routes.ts (2)

Line range hint 44-54: Align route prefix with new pattern

The operateAsset route still uses the /api/v1/ prefix while new routes use /api/camera/. This inconsistency should be addressed.

Consider updating the path to match the new pattern:

-    path: "/api/v1/asset/{id}/operate_assets/",
+    path: "/api/camera/assets/{id}/operate/",

56-78: Consider implementing a migration strategy

These route changes constitute breaking changes, including:

  1. New route structure (/api/camera/position-presets/)
  2. Parameter changes (asset_external_id, assetbed_external_id)

Consider:

  • Implementing version compatibility in the backend
  • Adding deprecation notices for old routes
  • Documenting migration steps for other teams
  • Coordinating the rollout with dependent services

Would you like help creating a migration guide or deprecation timeline?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fceb604 and 70e6f62.

📒 Files selected for processing (4)
  • src/components/CameraFeed/CameraFeedWithBedPresets.tsx (1 hunks)
  • src/components/CameraFeed/ConfigureCamera.tsx (4 hunks)
  • src/components/CameraFeed/routes.ts (1 hunks)
  • src/components/Facility/ConsultationDetails/ConsultationFeedTab.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/components/CameraFeed/CameraFeedWithBedPresets.tsx
  • src/components/CameraFeed/ConfigureCamera.tsx
🔇 Additional comments (2)
src/components/CameraFeed/routes.ts (1)

56-78: Verify backend compatibility with new route structure

The new RESTful route structure is well-organized and follows best practices. However, we need to ensure the backend PR (#2610) supports these changes.

Let's verify the backend compatibility:

✅ Verification successful

Route changes are already in use and functioning

The new route structure /api/camera/position-presets/ is already being actively used across multiple frontend components:

  • ConsultationFeedTab.tsx
  • ConfigureCamera.tsx
  • CameraFeedWithBedPresets.tsx

These components are successfully making API calls using the new route structure for all CRUD operations (list, create, update, delete). Since these components are functioning in the codebase and no old route patterns (/api/v1/camera_presets) were found, this indicates that the backend already supports these routes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the backend PR implements the new routes

# Fetch the backend PR details
echo "Checking backend PR #2610 for route implementations:"
gh api repos/ohcnetwork/care/pulls/2610 --jq '.body' | grep -i "position-presets"

# Search for any remaining old route patterns in the frontend
echo -e "\nChecking for remaining old route patterns:"
rg -t ts -t tsx "/api/v1/.*camera_presets"

Length of output: 368


Script:

#!/bin/bash
# Let's try a different approach to verify the backend compatibility

# Search for any route definitions related to camera presets in the backend
echo "Searching for camera preset route definitions:"
rg -t py "position.?presets|camera.?presets" --context 2

# Check for any existing API endpoint tests
echo -e "\nSearching for related API tests:"
fd -e py -e yaml test.*camera.*preset

# Look for any migration files that might indicate schema changes
echo -e "\nChecking for related migrations:"
fd -e py "migration.*camera"

# Check for any remaining old route patterns in TypeScript files (fixing the file type)
echo -e "\nChecking for old route patterns in frontend:"
rg -t typescript "/api/v1/.*camera_presets"

Length of output: 731


Script:

#!/bin/bash
# Let's try one final approach focusing on the frontend changes

# Search for any references to the old or new camera preset routes
echo "Searching for camera preset route patterns:"
rg "api/.*camera.*preset" -l

# Look for any route definition files
echo -e "\nSearching for route definition files:"
fd "routes.ts"

# Check for any imports or usages of these routes
echo -e "\nChecking for route imports and usages:"
rg "positionPresets" -A 2 -B 2

Length of output: 4814

src/components/Facility/ConsultationDetails/ConsultationFeedTab.tsx (1)

61-62: Verify bed.id compatibility with external_id format

The query parameter uses bed?.id directly as the bed_external_id. Please ensure that the bed.id format matches the expected external ID format used by the API.

✅ Verification successful

Let me gather more information about the bed object structure and the API endpoint to verify the ID format compatibility.


Based on the search results, I can now generate the final response:

The bed.id usage is correct and compatible with the API's external ID format

The codebase shows consistent usage of bed.id as the external identifier:

  • The bed object follows the BaseModel interface which defines id as a string type
  • Other components like ConfigureCamera also use similar pattern with bed_external_id and assetbed_external_id accepting the bed.id directly
  • The API routes and query parameters are aligned with this usage pattern
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the bed object structure and ID format
# Look for bed object type definitions and usage patterns

# Check for bed type definitions
ast-grep --pattern 'type $_ = {
  $$$
  bed_object: {
    $$$
  }
  $$$
}'

# Check for bed.id usage patterns
rg "bed\?\.id|bed\.id" -A 2 -B 2

Length of output: 5803


Script:

#!/bin/bash
# Check bed type definitions and interfaces
ast-grep --pattern 'interface $_ {
  $$$
  id: $_
  $$$
}'

# Check the API route definition
rg "positionPresets|bed_external_id" -A 2 -B 2

# Check for any type transformations or validations related to bed IDs
rg "bed.*id.*external" -A 2 -B 2

Length of output: 41224

@nihal467
Copy link
Member

@DraKen0009 can you check the coderabbit suggestion

CC: @rithviknishad

@rithviknishad
Copy link
Member

rithviknishad commented Nov 27, 2024

@nihal467 not in scope of this PR; also request handles errors gracefully.

@nihal467
Copy link
Member

nihal467 commented Nov 27, 2024

image
image

  • the camera preset creation is not working and the related api is throwing 500

@rithviknishad
Copy link
Member

Fixed in ohcnetwork/care_camera_asset@ffe864b

@nihal467
Copy link
Member

image

@rithviknishad @DraKen0009 the camera preset is still not working, do give it a check before requesting next review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Review required
Development

Successfully merging this pull request may close these issues.

4 participants