Skip to content

Commit e30f9dc

Browse files
list by tags with dashboard listing api
1 parent 8e0e4da commit e30f9dc

File tree

3 files changed

+22
-32
lines changed

3 files changed

+22
-32
lines changed

src/handlers/http/modal/server.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,6 @@ impl Server {
307307
.authorize(Action::ListDashboard),
308308
),
309309
)
310-
.service(
311-
web::resource("/list_by_tag/{tags}").route(
312-
web::get()
313-
.to(dashboards::list_dashboards_by_tags)
314-
.authorize(Action::ListDashboard),
315-
),
316-
)
317310
.service(
318311
web::scope("/{dashboard_id}")
319312
.service(

src/handlers/http/users/dashboards.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ pub async fn list_dashboards(req: HttpRequest) -> Result<impl Responder, Dashboa
4444
return Err(DashboardError::Metadata("Invalid limit value"));
4545
}
4646
}
47+
48+
if let Some(tags) = query_map.get("tags") {
49+
let tags: Vec<String> = tags
50+
.split(',')
51+
.map(|s| s.trim().to_string())
52+
.filter(|s| !s.is_empty())
53+
.collect();
54+
if tags.is_empty() {
55+
return Err(DashboardError::Metadata("Tags cannot be empty"));
56+
}
57+
let dashboards = DASHBOARDS.list_dashboards_by_tags(tags).await;
58+
let dashboard_summaries = dashboards
59+
.iter()
60+
.map(|dashboard| dashboard.to_summary())
61+
.collect::<Vec<_>>();
62+
return Ok((web::Json(dashboard_summaries), StatusCode::OK));
63+
}
4764
}
4865
let dashboards = DASHBOARDS.list_dashboards(dashboard_limit).await;
4966
let dashboard_summaries = dashboards
@@ -215,29 +232,6 @@ pub async fn list_tags() -> Result<impl Responder, DashboardError> {
215232
Ok((web::Json(tags), StatusCode::OK))
216233
}
217234

218-
pub async fn list_dashboards_by_tags(tags: Path<String>) -> Result<impl Responder, DashboardError> {
219-
let tags = tags.into_inner();
220-
if tags.is_empty() {
221-
return Err(DashboardError::Metadata("Tags cannot be empty"));
222-
}
223-
// tags can be comma separated list of tags
224-
let tags = tags
225-
.split(',')
226-
.map(|s| s.trim().to_string())
227-
.filter(|s| !s.is_empty())
228-
.collect::<Vec<_>>();
229-
if tags.is_empty() {
230-
return Err(DashboardError::Metadata("Tags cannot be empty"));
231-
}
232-
let dashboards = DASHBOARDS.list_dashboards_by_tags(tags).await;
233-
let dashboard_summaries = dashboards
234-
.iter()
235-
.map(|dashboard| dashboard.to_summary())
236-
.collect::<Vec<_>>();
237-
238-
Ok((web::Json(dashboard_summaries), StatusCode::OK))
239-
}
240-
241235
#[derive(Debug, thiserror::Error)]
242236
pub enum DashboardError {
243237
#[error("Failed to connect to storage: {0}")]

src/users/dashboards.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,14 +375,17 @@ impl Dashboards {
375375
}
376376

377377
/// List dashboards by tag
378-
/// This function returns a list of dashboards that have the specified tag
378+
/// This function returns a list of dashboards that match any of the provided tags
379+
/// If no tags are provided, it returns an empty list
379380
pub async fn list_dashboards_by_tags(&self, tags: Vec<String>) -> Vec<Dashboard> {
380381
let dashboards = self.0.read().await;
381382
dashboards
382383
.iter()
383384
.filter(|d| {
384385
if let Some(dashboard_tags) = &d.tags {
385-
!tags.is_empty() && dashboard_tags.iter().any(|tag| tags.contains(tag))
386+
dashboard_tags
387+
.iter()
388+
.any(|dashboard_tag| tags.contains(dashboard_tag))
386389
} else {
387390
false
388391
}

0 commit comments

Comments
 (0)