| 326 | } |
| 327 | |
| 328 | async fn list_deployments( |
| 329 | &self, |
| 330 | request: Request<api::ListFuotaDeploymentsRequest>, |
| 331 | ) -> Result<Response<api::ListFuotaDeploymentsResponse>, Status> { |
| 332 | let req = request.get_ref(); |
| 333 | let user_id: Option<Uuid> = |
| 334 | if let Some(AuthID::User(v)) = request.extensions().get::<AuthID>() { |
| 335 | Some(*v) |
| 336 | } else { |
| 337 | None |
| 338 | }; |
| 339 | let tenant_id = if req.tenant_id.is_empty() { |
| 340 | None |
| 341 | } else { |
| 342 | Some(Uuid::from_str(&req.tenant_id).map_err(|e| e.status())?) |
| 343 | }; |
| 344 | let app_id = if req.application_id.is_empty() { |
| 345 | None |
| 346 | } else { |
| 347 | Some(Uuid::from_str(&req.application_id).map_err(|e| e.status())?) |
| 348 | }; |
| 349 | |
| 350 | self.validator |
| 351 | .validate( |
| 352 | request.extensions(), |
| 353 | validator::ValidateFuotaDeploymentsAccess::new( |
| 354 | validator::Flag::List, |
| 355 | tenant_id, |
| 356 | app_id, |
| 357 | ), |
| 358 | ) |
| 359 | .await?; |
| 360 | |
| 361 | let count = fuota::get_deployment_count(user_id, tenant_id, app_id) |
| 362 | .await |
| 363 | .map_err(|e| e.status())?; |
| 364 | let items = fuota::list_deployments( |
| 365 | user_id, |
| 366 | tenant_id, |
| 367 | app_id, |
| 368 | req.limit as i64, |
| 369 | req.offset as i64, |
| 370 | ) |
| 371 | .await |
| 372 | .map_err(|e| e.status())?; |
| 373 | |
| 374 | let mut resp = Response::new(api::ListFuotaDeploymentsResponse { |
| 375 | total_count: count as u32, |
| 376 | result: items |
| 377 | .iter() |
| 378 | .map(|d| api::FuotaDeploymentListItem { |
| 379 | id: d.id.to_string(), |
| 380 | created_at: Some(helpers::datetime_to_prost_timestamp(&d.created_at)), |
| 381 | updated_at: Some(helpers::datetime_to_prost_timestamp(&d.created_at)), |
| 382 | started_at: d |
| 383 | .started_at |
| 384 | .as_ref() |
| 385 | .map(helpers::datetime_to_prost_timestamp), |