MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / list

Method list

chirpstack/src/api/device_profile.rs:603–678  ·  view source on GitHub ↗
(
        &self,
        request: Request<api::ListDeviceProfilesRequest>,
    )

Source from the content-addressed store, hash-verified

601 }
602
603 async fn list(
604 &self,
605 request: Request<api::ListDeviceProfilesRequest>,
606 ) -> Result<Response<api::ListDeviceProfilesResponse>, Status> {
607 let req = request.get_ref();
608
609 let tenant_id = if req.tenant_id.is_empty() {
610 None
611 } else {
612 Some(Uuid::from_str(&req.tenant_id).map_err(|e| e.status())?)
613 };
614
615 let device_id = if req.device_id.is_empty() {
616 None
617 } else {
618 Some(Uuid::from_str(&req.device_id).map_err(|e| e.status())?)
619 };
620
621 self.validator
622 .validate(
623 request.extensions(),
624 validator::ValidateDeviceProfilesAccess::new(
625 validator::Flag::List,
626 tenant_id,
627 req.global_only,
628 ),
629 )
630 .await?;
631
632 let filters = device_profile::Filters {
633 global_only: req.global_only,
634 tenant_only: req.tenant_only,
635 tenant_id: if !req.global_only { tenant_id } else { None },
636 device_id: if req.global_only { device_id } else { None },
637 search: if req.search.is_empty() {
638 None
639 } else {
640 Some(req.search.to_string())
641 },
642 };
643
644 let count = device_profile::get_count(&filters)
645 .await
646 .map_err(|e| e.status())?;
647 let items = device_profile::list(req.limit as i64, req.offset as i64, &filters)
648 .await
649 .map_err(|e| e.status())?;
650
651 let mut resp = Response::new(api::ListDeviceProfilesResponse {
652 total_count: count as u32,
653 result: items
654 .iter()
655 .map(|dp| api::DeviceProfileListItem {
656 id: dp.id.to_string(),
657 created_at: Some(helpers::datetime_to_prost_timestamp(&dp.created_at)),
658 updated_at: Some(helpers::datetime_to_prost_timestamp(&dp.updated_at)),
659 name: dp.name.clone(),
660 region: dp.region.to_proto().into(),

Callers 1

test_device_profileFunction · 0.45

Calls 11

statusMethod · 0.80
to_stringMethod · 0.80
iterMethod · 0.80
to_protoMethod · 0.80
insertMethod · 0.80
unwrapMethod · 0.80
get_countFunction · 0.50
listFunction · 0.50
validateMethod · 0.45
intoMethod · 0.45

Tested by 1

test_device_profileFunction · 0.36