From 031e674dced95aeb0dc2c222f1fc8138ffcede24 Mon Sep 17 00:00:00 2001 From: Adam Marcus Date: Sun, 15 Sep 2024 17:55:51 -0400 Subject: [PATCH] WIP rust data models --- src/ayb_db/models.rs | 73 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/src/ayb_db/models.rs b/src/ayb_db/models.rs index d640a81c..9f017eb7 100644 --- a/src/ayb_db/models.rs +++ b/src/ayb_db/models.rs @@ -114,11 +114,44 @@ impl AuthenticationMethodStatus { } } +#[derive( + Serialize_repr, Deserialize_repr, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, ValueEnum, +)] +#[repr(i16)] +pub enum PublicSharingLevel { + Metadata = 0, + Fork = 1, + ReadOnly = 2, +} + +from_str!(PublicSharingLevel, { + "metadata" => PublicSharingLevel::Metadata, + "fork" => PublicSharingLevel::Fork, + "read_only" => PublicSharingLevel::ReadOnly +}); + +try_from_i16!(PublicSharingLevel, { + 0 => PublicSharingLevel::Metadata, + 1 => PublicSharingLevel::Fork, + 3 => PublicSharingLevel::ReadOnly, +}); + +impl PublicSharingLevel { + pub fn to_str(&self) -> &str { + match self { + PublicSharingLevel::Metadata => "metadata", + PublicSharingLevel::Fork => "fork", + PublicSharingLevel::ReadOnly => "read_only", + } + } +} + #[derive(Debug, Serialize, Deserialize)] pub struct Database { pub entity_id: i32, pub slug: String, pub db_type: i16, + pub public_sharing_level: i16, } #[derive(Debug, FromRow, Serialize, Deserialize)] @@ -127,6 +160,7 @@ pub struct InstantiatedDatabase { pub entity_id: i32, pub slug: String, pub db_type: i16, + pub public_sharing_level: i16, } #[derive(Debug, Serialize, Deserialize)] @@ -241,3 +275,42 @@ pub struct APIToken { pub hash: String, pub status: i16, } + +#[derive( + Serialize_repr, Deserialize_repr, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, ValueEnum, +)] +#[repr(i16)] +pub enum EntityDatabaseSharingLevel { + ReadOnly = 0, + ReadWrite = 1, + Manager = 2, +} + +from_str!(EntityDatabaseSharingLevel, { + "read_only" => EntityDatabaseSharingLevel::ReadOnly + "read_write" => EntityDatabaseSharingLevel::ReadWrite, + "manager" => EntityDatabaseSharingLevel::Manager, +}); + +try_from_i16!(EntityDatabaseSharingLevel, { + 0 => EntityDatabaseSharingLevel::ReadOnly, + 1 => EntityDatabaseSharingLevel::ReadWrite, + 2 => EntityDatabaseSharingLevel::Manager, +}); + +impl EntityDatabaseSharingLevel { + pub fn to_str(&self) -> &str { + match self { + EntityDatabaseSharingLevel::ReadOnly => "read_only", + EntityDatabaseSharingLevel::ReadWrite => "read_write", + EntityDatabaseSharingLevel::Manager => "manager", + } + } +} + +#[derive(Debug, FromRow, Serialize, Deserialize)] +pub struct EntityDatabasePermission { + pub entity_id: i32, + pub database_id: i32, + pub sharing_level: i16, +}