| 183 | } |
| 184 | |
| 185 | pub async fn create_deployment(d: FuotaDeployment) -> Result<FuotaDeployment, Error> { |
| 186 | d.validate()?; |
| 187 | |
| 188 | let dp = device_profile::get(&d.device_profile_id).await?; |
| 189 | |
| 190 | if let Some(tenant_id) = dp.tenant_id { |
| 191 | let app = storage::application::get(&d.application_id).await?; |
| 192 | if app.tenant_id != tenant_id { |
| 193 | return Err(Error::Validation( |
| 194 | "The application and device-profile must be under the same tenant".into(), |
| 195 | )); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | let d: FuotaDeployment = diesel::insert_into(fuota_deployment::table) |
| 200 | .values(&d) |
| 201 | .get_result(&mut get_async_db_conn().await?) |
| 202 | .await |
| 203 | .map_err(|e| Error::from_diesel(e, d.id.to_string()))?; |
| 204 | |
| 205 | info!(id = %d.id, "FUOTA deployment created"); |
| 206 | Ok(d) |
| 207 | } |
| 208 | |
| 209 | pub async fn get_deployment(id: Uuid) -> Result<FuotaDeployment, Error> { |
| 210 | fuota_deployment::dsl::fuota_deployment |