Currently, our application lacks a REST API endpoint for creating dashboards. Users need to be able to programmatically create new dashboards through the API to support automation and integration scenarios.
## Proposed Solution
Implement a POST /dashboards endpoint that creates a new dashboard with default values. The endpoint will create a `DashboardFile` object with a `DashboardYml` containing a default name "Untitled Dashboard", no description, and an empty array of rows.
## Technical Design
### REST Endpoint
```
POST /dashboards
```
#### Request
The request body will be empty. All default values will be used for the new dashboard.
#### Response
```json
{
"dashboard": {
"id": "uuid",
"name": "Untitled Dashboard",
"description": null,
"config": {
"rows": []
},
"created_at": "timestamp",
"created_by": "user_uuid",
"updated_at": "timestamp",
"updated_by": "user_uuid",
"status": "Verified",
"version_number": 1,
"file": "yaml_content",
"file_name": "dashboard_filename.yml"
},
"access": "Owner",
"permission": "Owner",
"metrics": {},
"public_password": null,
"collections": []
}
```
### Handler Implementation
#### REST Handler
Create a new file at `src/routes/rest/routes/dashboards/create_dashboard.rs`:
```rust
use axum::{extract::State, Json};
use handlers::dashboards::create_dashboard_handler;
use handlers::types::User;
use uuid::Uuid;
use crate::routes::rest::ApiResponse;
use crate::AppState;
pub async fn create_dashboard_rest_handler(
State(state): State<AppState>,
user: User,
) -> ApiResponse {
match create_dashboard_handler(&user.id).await {
Ok(response) => ApiResponse::success(response),
Err(e) => {
tracing::error!("Failed to create dashboard: {}", e);
ApiResponse::error(e)
}
}
}
```
#### Business Logic Handler
Create a new file at `libs/handlers/src/dashboards/create_dashboard_handler.rs`:
```rust
use anyhow::{anyhow, Result};
use chrono::Utc;
use database::pool::get_pg_pool;
use database::schema::dashboard_files;
use database::types::dashboard_yml::DashboardYml;
use diesel::insert_into;
use diesel_async::RunQueryDsl;
use serde_yaml;
use uuid::Uuid;
use super::{BusterDashboard, BusterDashboardResponse, DashboardConfig};
use database::enums::{AssetPermissionRole, Verification};