|
2 | 2 | // License, v. 2.0. If a copy of the MPL was not distributed with this
|
3 | 3 | // file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
4 | 4 |
|
5 |
| -use crate::schema::system_update; |
| 5 | +use crate::{ |
| 6 | + impl_enum_type, |
| 7 | + schema::{component_update, system_update}, |
| 8 | +}; |
6 | 9 | use db_macros::Asset;
|
7 | 10 | use nexus_types::{external_api::views, identity::Asset};
|
8 | 11 | use serde::{Deserialize, Serialize};
|
| 12 | +use uuid::Uuid; |
9 | 13 |
|
10 | 14 | #[derive(
|
11 | 15 | Queryable,
|
@@ -34,3 +38,58 @@ impl From<SystemUpdate> for views::SystemUpdate {
|
34 | 38 | }
|
35 | 39 | }
|
36 | 40 | }
|
| 41 | + |
| 42 | +// TODO: more specific name than device_type, maybe update_device_type |
| 43 | + |
| 44 | +impl_enum_type!( |
| 45 | + #[derive(SqlType, Debug, QueryId)] |
| 46 | + #[diesel(postgres_type(name = "device_type"))] |
| 47 | + pub struct DeviceTypeEnum; |
| 48 | + |
| 49 | + #[derive(Copy, Clone, Debug, AsExpression, FromSqlRow, Serialize, Deserialize, PartialEq)] |
| 50 | + #[diesel(sql_type = DeviceTypeEnum)] |
| 51 | + pub enum DeviceType; |
| 52 | + |
| 53 | + // Enum values |
| 54 | + Disk => b"disk" |
| 55 | +); |
| 56 | + |
| 57 | +impl From<DeviceType> for views::DeviceType { |
| 58 | + fn from(device_type: DeviceType) -> Self { |
| 59 | + match device_type { |
| 60 | + DeviceType::Disk => views::DeviceType::Disk, |
| 61 | + } |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +#[derive( |
| 66 | + Queryable, |
| 67 | + Insertable, |
| 68 | + Selectable, |
| 69 | + Clone, |
| 70 | + Debug, |
| 71 | + Asset, |
| 72 | + Serialize, |
| 73 | + Deserialize, |
| 74 | +)] |
| 75 | +#[diesel(table_name = component_update)] |
| 76 | +pub struct ComponentUpdate { |
| 77 | + #[diesel(embed)] |
| 78 | + identity: ComponentUpdateIdentity, |
| 79 | + pub version: String, |
| 80 | + pub device_type: DeviceType, |
| 81 | + pub parent_id: Option<Uuid>, |
| 82 | +} |
| 83 | + |
| 84 | +impl From<ComponentUpdate> for views::ComponentUpdate { |
| 85 | + fn from(component_update: ComponentUpdate) -> Self { |
| 86 | + Self { |
| 87 | + identity: component_update.identity(), |
| 88 | + // TODO: figure out how to ser/de semver versions |
| 89 | + // version: system_update.version, |
| 90 | + version: views::SemverVersion::new(1, 0, 0), |
| 91 | + device_type: component_update.device_type.into(), |
| 92 | + parent_id: component_update.parent_id, |
| 93 | + } |
| 94 | + } |
| 95 | +} |
0 commit comments