6.4 KiB
title | author | date | status |
---|---|---|---|
Collections REST Endpoints for Dashboards and Metrics | Cascade | 2025-03-19 | Draft |
Collections REST Endpoints for Dashboards and Metrics
Problem Statement
Currently, the application allows users to create collections and add assets to them, but there's no REST API to manage the association between collections and assets (specifically dashboards and metrics). This limits the ability to programmatically manage collections through the API.
We need to implement REST endpoints that allow users to add and remove dashboards and metrics from collections, ensuring proper permission checks and data integrity.
Goals
- Create REST endpoints to add dashboards and metrics to collections
- Create REST endpoints to remove dashboards and metrics from collections
- Create REST endpoints to manage multiple asset types in a single request
- Ensure proper permission validation for all operations
- Maintain data integrity with proper error handling
- Follow established patterns for REST endpoints and handlers
Non-Goals
- Modifying the existing collections functionality
- Creating new UI components for these endpoints
- Changing the database schema
Technical Design
Overview
We will implement six REST endpoints:
- POST /collections/:id/dashboards - Add dashboards to a collection
- DELETE /collections/:id/dashboards - Remove dashboards from a collection
- POST /collections/:id/metrics - Add metrics to a collection
- DELETE /collections/:id/metrics - Remove metrics from a collection
- POST /collections/:id/assets - Add multiple assets of different types to a collection
- DELETE /collections/:id/assets - Remove multiple assets of different types from a collection
Each endpoint will validate permissions, check that the assets exist, and perform the appropriate database operations on the collections_to_assets
table.
Component Breakdown
The implementation will be divided into the following components:
Handlers
add_dashboards_to_collection_handler.rs
- Business logic for adding dashboards to a collectionremove_dashboards_from_collection_handler.rs
- Business logic for removing dashboards from a collectionadd_metrics_to_collection_handler.rs
- Business logic for adding metrics to a collectionremove_metrics_from_collection_handler.rs
- Business logic for removing metrics from a collectionadd_assets_to_collection_handler.rs
- Business logic for adding multiple assets of different types to a collectionremove_assets_from_collection_handler.rs
- Business logic for removing multiple assets of different types from a collection
REST Routes
add_dashboards_to_collection.rs
- REST endpoint for adding dashboards to a collectionremove_dashboards_from_collection.rs
- REST endpoint for removing dashboards from a collectionadd_metrics_to_collection.rs
- REST endpoint for adding metrics to a collectionremove_metrics_from_collection.rs
- REST endpoint for removing metrics from a collectionadd_assets_to_collection.rs
- REST endpoint for adding multiple assets of different types to a collectionremove_assets_from_collection.rs
- REST endpoint for removing multiple assets of different types from a collection
Dependencies
libs/sharing
- For permission checkinglibs/database
- For database operationslibs/handlers
- For implementing business logic
Implementation Plan
The implementation will be broken down into six separate PRDs, each focusing on a specific endpoint. These PRDs can be worked on concurrently by different developers:
- ✅ Add Dashboard to Collections REST Endpoint
- ✅ Remove Dashboard from Collections REST Endpoint
- ✅ Add Metric to Collections REST Endpoint
- ✅ Remove Metric from Collections REST Endpoint
- Add Assets to Collection REST Endpoint
- ✅ Remove Assets from Collection REST Endpoint
Additionally, we have a separate PRD for the concurrent asset existence checking approach:
Phase 1: Implementation of Individual Endpoints
Each endpoint will be implemented according to its respective PRD. These can be developed in parallel since they don't have dependencies on each other.
Success Criteria:
- All endpoints are implemented according to their PRDs
- All tests pass
- Code review is complete
Phase 2: Integration and Testing
After all endpoints are implemented, we'll perform integration testing to ensure they work together correctly.
Success Criteria:
- All endpoints can be called in sequence without errors
- Collections can be populated and modified using the new endpoints
- Permission checks work correctly
Testing Strategy
Each PRD will include its own detailed testing strategy, but at a high level:
Unit Tests
- Test handlers with mocked database connections
- Test permission validation logic
- Test error handling for various scenarios
Integration Tests
- Test endpoints with a test database
- Verify correct database state after operations
- Test permission checks with different user roles
Security Considerations
- All endpoints will require authentication
- Permission checks will ensure users can only modify collections they have access to
- Input validation will prevent malicious data
Monitoring and Logging
- All operations will be logged with appropriate context
- Errors will be logged with detailed information
- Metrics will be collected for endpoint usage
Rollout Plan
- Deploy to staging environment
- Perform manual testing
- Deploy to production
- Monitor for any issues