(
&self,
request: Request<api::GetDevicesSummaryRequest>,
)
| 618 | } |
| 619 | |
| 620 | async fn get_devices_summary( |
| 621 | &self, |
| 622 | request: Request<api::GetDevicesSummaryRequest>, |
| 623 | ) -> Result<Response<api::GetDevicesSummaryResponse>, Status> { |
| 624 | let req = request.get_ref(); |
| 625 | |
| 626 | let tenant_id = if req.tenant_id.is_empty() { |
| 627 | None |
| 628 | } else { |
| 629 | Some(Uuid::from_str(&req.tenant_id).map_err(|e| e.status())?) |
| 630 | }; |
| 631 | |
| 632 | if tenant_id.is_none() { |
| 633 | self.validator |
| 634 | .validate(request.extensions(), validator::ValidateIsAdmin::new()) |
| 635 | .await?; |
| 636 | } else { |
| 637 | self.validator |
| 638 | .validate( |
| 639 | request.extensions(), |
| 640 | validator::ValidateTenantAccess::new( |
| 641 | validator::Flag::Read, |
| 642 | *tenant_id.as_ref().unwrap(), |
| 643 | ), |
| 644 | ) |
| 645 | .await?; |
| 646 | } |
| 647 | |
| 648 | let active_inactive = device::get_active_inactive(&tenant_id) |
| 649 | .await |
| 650 | .map_err(|e| e.status())?; |
| 651 | |
| 652 | let dr_count = device::get_data_rates(&tenant_id) |
| 653 | .await |
| 654 | .map_err(|e| e.status())?; |
| 655 | |
| 656 | Ok(Response::new(api::GetDevicesSummaryResponse { |
| 657 | active_count: active_inactive.active_count as u32, |
| 658 | inactive_count: active_inactive.inactive_count as u32, |
| 659 | never_seen_count: active_inactive.never_seen_count as u32, |
| 660 | dr_count: dr_count |
| 661 | .iter() |
| 662 | .map(|i| (i.dr.unwrap() as u32, i.count as u32)) |
| 663 | .collect(), |
| 664 | })) |
| 665 | } |
| 666 | |
| 667 | async fn get_gateways_summary( |
| 668 | &self, |
nothing calls this directly
no test coverage detected