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

Method create

chirpstack/src/api/gateway.rs:34–79  ·  view source on GitHub ↗
(
        &self,
        request: Request<api::CreateGatewayRequest>,
    )

Source from the content-addressed store, hash-verified

32#[tonic::async_trait]
33impl GatewayService for Gateway {
34 async fn create(
35 &self,
36 request: Request<api::CreateGatewayRequest>,
37 ) -> Result<Response<()>, Status> {
38 let req_gw = match &request.get_ref().gateway {
39 Some(v) => v,
40 None => {
41 return Err(Status::invalid_argument("gateway is missing"));
42 }
43 };
44 let tenant_id = Uuid::from_str(&req_gw.tenant_id).map_err(|e| e.status())?;
45
46 self.validator
47 .validate(
48 request.extensions(),
49 validator::ValidateGatewaysAccess::new(validator::Flag::Create, tenant_id),
50 )
51 .await?;
52
53 let (lat, lon, alt) = match &req_gw.location {
54 Some(v) => (v.latitude, v.longitude, v.altitude as f32),
55 None => (0.0, 0.0, 0.0),
56 };
57
58 let gw = gateway::Gateway {
59 gateway_id: EUI64::from_str(&req_gw.gateway_id).map_err(|e| e.status())?,
60 tenant_id: tenant_id.into(),
61 name: req_gw.name.clone(),
62 description: req_gw.description.clone(),
63 latitude: lat,
64 longitude: lon,
65 altitude: alt,
66 tags: fields::KeyValue::new(req_gw.tags.clone()),
67 stats_interval_secs: req_gw.stats_interval as i32,
68 downlink_priority: req_gw.downlink_priority as i16,
69 ..Default::default()
70 };
71
72 let _ = gateway::create(gw).await.map_err(|e| e.status())?;
73
74 let mut resp = Response::new(());
75 resp.metadata_mut()
76 .insert("x-log-gateway_id", req_gw.gateway_id.parse().unwrap());
77
78 Ok(resp)
79 }
80
81 async fn get(
82 &self,

Callers 1

test_gatewayFunction · 0.45

Calls 6

statusMethod · 0.80
insertMethod · 0.80
unwrapMethod · 0.80
createFunction · 0.50
validateMethod · 0.45
intoMethod · 0.45

Tested by 1

test_gatewayFunction · 0.36