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

Method global_search

chirpstack/src/api/internal.rs:224–294  ·  view source on GitHub ↗
(
        &self,
        request: Request<api::GlobalSearchRequest>,
    )

Source from the content-addressed store, hash-verified

222 }
223
224 async fn global_search(
225 &self,
226 request: Request<api::GlobalSearchRequest>,
227 ) -> Result<Response<api::GlobalSearchResponse>, Status> {
228 let req = request.get_ref();
229 self.validator
230 .validate(request.extensions(), validator::ValidateActiveUser::new())
231 .await?;
232
233 let auth_id = request.extensions().get::<AuthID>().unwrap();
234 let user_id = match auth_id {
235 AuthID::User(id) => id,
236 _ => {
237 return Err(Status::unauthenticated("no user id"));
238 }
239 };
240
241 let u = user::get(user_id).await.map_err(|e| e.status())?;
242
243 let items = search::global_search(
244 &u.id,
245 u.is_admin,
246 &req.search,
247 req.limit as usize,
248 req.offset as usize,
249 )
250 .await
251 .map_err(|e| e.status())?;
252
253 Ok(Response::new(api::GlobalSearchResponse {
254 result: items
255 .iter()
256 .map(|r| api::GlobalSearchResult {
257 kind: r.kind.clone(),
258 score: r.score,
259 tenant_id: match &r.tenant_id {
260 Some(v) => v.to_string(),
261 None => "".to_string(),
262 },
263 tenant_name: match &r.tenant_name {
264 Some(v) => v.clone(),
265 None => "".to_string(),
266 },
267 application_id: match &r.application_id {
268 Some(v) => v.to_string(),
269 None => "".to_string(),
270 },
271 application_name: match &r.application_name {
272 Some(v) => v.clone(),
273 None => "".to_string(),
274 },
275 device_dev_eui: match &r.device_dev_eui {
276 Some(v) => v.to_string(),
277 None => "".to_string(),
278 },
279 device_name: match &r.device_name {
280 Some(v) => v.clone(),
281 None => "".to_string(),

Callers

nothing calls this directly

Calls 7

global_searchFunction · 0.85
unwrapMethod · 0.80
statusMethod · 0.80
iterMethod · 0.80
to_stringMethod · 0.80
getFunction · 0.50
validateMethod · 0.45

Tested by

no test coverage detected