|
| 1 | +// This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | +// file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 4 | + |
| 5 | +//! DB model for the `fm_sb_req_ereports` per-variant table. |
| 6 | +
|
| 7 | +use crate::DbTypedUuid; |
| 8 | +use chrono::{DateTime, Utc}; |
| 9 | +use nexus_db_schema::schema::fm_sb_req_ereports; |
| 10 | +use nexus_types::support_bundle::EreportFilters; |
| 11 | +use omicron_uuid_kinds::{SitrepKind, SupportBundleKind}; |
| 12 | + |
| 13 | +#[derive(Queryable, Insertable, Clone, Debug, Selectable)] |
| 14 | +#[diesel(table_name = fm_sb_req_ereports)] |
| 15 | +pub struct SbReqEreports { |
| 16 | + pub sitrep_id: DbTypedUuid<SitrepKind>, |
| 17 | + pub request_id: DbTypedUuid<SupportBundleKind>, |
| 18 | + pub start_time: Option<DateTime<Utc>>, |
| 19 | + pub end_time: Option<DateTime<Utc>>, |
| 20 | + pub only_serials: Vec<String>, |
| 21 | + pub only_classes: Vec<String>, |
| 22 | +} |
| 23 | + |
| 24 | +impl SbReqEreports { |
| 25 | + pub fn new( |
| 26 | + sitrep_id: impl Into<DbTypedUuid<SitrepKind>>, |
| 27 | + request_id: impl Into<DbTypedUuid<SupportBundleKind>>, |
| 28 | + filters: &EreportFilters, |
| 29 | + ) -> Self { |
| 30 | + SbReqEreports { |
| 31 | + sitrep_id: sitrep_id.into(), |
| 32 | + request_id: request_id.into(), |
| 33 | + start_time: filters.start_time, |
| 34 | + end_time: filters.end_time, |
| 35 | + only_serials: filters.only_serials.clone(), |
| 36 | + only_classes: filters.only_classes.clone(), |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + /// Reconstruct the `EreportFilters` from the DB row. |
| 41 | + pub fn into_ereport_filters(self) -> EreportFilters { |
| 42 | + EreportFilters { |
| 43 | + start_time: self.start_time, |
| 44 | + end_time: self.end_time, |
| 45 | + only_serials: self.only_serials, |
| 46 | + only_classes: self.only_classes, |
| 47 | + } |
| 48 | + } |
| 49 | +} |
0 commit comments