| 195 | } |
| 196 | |
| 197 | async fn list( |
| 198 | &self, |
| 199 | request: Request<api::ListGatewaysRequest>, |
| 200 | ) -> Result<Response<api::ListGatewaysResponse>, Status> { |
| 201 | let req = request.get_ref(); |
| 202 | let tenant_id = if req.tenant_id.is_empty() { |
| 203 | None |
| 204 | } else { |
| 205 | Some(Uuid::from_str(&req.tenant_id).map_err(|e| e.status())?) |
| 206 | }; |
| 207 | let mg_id: Option<Uuid> = if req.multicast_group_id.is_empty() { |
| 208 | None |
| 209 | } else { |
| 210 | Some(Uuid::from_str(&req.multicast_group_id).map_err(|e| e.status())?) |
| 211 | }; |
| 212 | |
| 213 | if let Some(mg_id) = mg_id { |
| 214 | self.validator |
| 215 | .validate( |
| 216 | request.extensions(), |
| 217 | validator::ValidateMulticastGroupAccess::new(validator::Flag::Read, mg_id), |
| 218 | ) |
| 219 | .await?; |
| 220 | } |
| 221 | |
| 222 | let filters = gateway::Filters { |
| 223 | tenant_id, |
| 224 | multicast_group_id: mg_id, |
| 225 | search: if req.search.is_empty() { |
| 226 | None |
| 227 | } else { |
| 228 | Some(req.search.to_string()) |
| 229 | }, |
| 230 | }; |
| 231 | |
| 232 | let count = gateway::get_count(&filters).await.map_err(|e| e.status())?; |
| 233 | let result = gateway::list( |
| 234 | req.limit as i64, |
| 235 | req.offset as i64, |
| 236 | &filters, |
| 237 | req.order_by().from_proto(), |
| 238 | req.order_by_desc, |
| 239 | ) |
| 240 | .await |
| 241 | .map_err(|e| e.status())?; |
| 242 | |
| 243 | let mut resp = Response::new(api::ListGatewaysResponse { |
| 244 | total_count: count as u32, |
| 245 | result: result |
| 246 | .iter() |
| 247 | .map(|gw| api::GatewayListItem { |
| 248 | tenant_id: gw.tenant_id.to_string(), |
| 249 | gateway_id: gw.gateway_id.to_string(), |
| 250 | name: gw.name.clone(), |
| 251 | description: gw.description.clone(), |
| 252 | location: Some(common::Location { |
| 253 | latitude: gw.latitude, |
| 254 | longitude: gw.longitude, |