-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
220 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use crate::database::Database; | ||
use crate::models::field::kind::FieldKind; | ||
use serde::{Deserialize, Serialize}; | ||
use poem_openapi::Object; | ||
use sqlx::FromRow; | ||
|
||
#[derive(FromRow, Object, Debug, Clone, Serialize, Deserialize)] | ||
pub struct FieldDefinition { | ||
pub definition_id: String, | ||
pub kind: FieldKind, | ||
pub name: String, | ||
pub created_at: Option<chrono::DateTime<chrono::Utc>>, | ||
pub updated_at: Option<chrono::DateTime<chrono::Utc>>, | ||
} | ||
|
||
impl FieldDefinition { | ||
pub async fn create( | ||
kind: FieldKind, | ||
name: String, | ||
database: &Database, | ||
) -> Result<FieldDefinition, sqlx::Error> { | ||
sqlx::query_as!( | ||
FieldDefinition, | ||
"INSERT INTO field_definitions (kind, name) VALUES ($1, $2) RETURNING *", | ||
kind.to_string(), | ||
name | ||
) | ||
.fetch_one(&database.pool) | ||
.await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use sqlx::Type; | ||
use poem_openapi::Enum; | ||
|
||
#[derive(Type, Enum, Debug, Clone, Serialize, Deserialize)] | ||
#[sqlx(type_name = "text")] | ||
#[sqlx(rename_all = "lowercase")] | ||
pub enum FieldKind { | ||
String, | ||
Number, | ||
Boolean, | ||
Json, | ||
} | ||
|
||
impl std::fmt::Display for FieldKind { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{:?}", self) | ||
} | ||
} | ||
|
||
impl FieldKind { | ||
pub fn from_str(s: &str) -> Self { | ||
match s.to_lowercase().as_str() { | ||
"string" => FieldKind::String, | ||
"number" => FieldKind::Number, | ||
"boolean" => FieldKind::Boolean, | ||
"json" => FieldKind::Json, | ||
_ => FieldKind::String, | ||
} | ||
} | ||
} | ||
|
||
impl From<String> for FieldKind { | ||
fn from(s: String) -> Self { | ||
FieldKind::from_str(&s) | ||
} | ||
} | ||
|
||
impl From<FieldKind> for String { | ||
fn from(kind: FieldKind) -> Self { | ||
kind.to_string().to_lowercase() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use sqlx::prelude::*; | ||
|
||
use crate::database::Database; | ||
|
||
pub mod kind; | ||
pub mod definition; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
use crate::database::Database; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(sqlx::FromRow, poem_openapi::Object, Debug, Clone, Serialize, Deserialize)] | ||
pub struct ItemField { | ||
pub item_id: String, | ||
pub definition_id: String, | ||
pub value: serde_json::Value, | ||
pub created_at: Option<chrono::DateTime<chrono::Utc>>, | ||
pub updated_at: Option<chrono::DateTime<chrono::Utc>>, | ||
} | ||
|
||
impl ItemField { | ||
pub async fn create( | ||
item_id: String, | ||
definition_id: String, | ||
value: serde_json::Value, | ||
database: &Database, | ||
) -> Result<ItemField, sqlx::Error> { | ||
sqlx::query_as!( | ||
ItemField, | ||
"INSERT INTO item_fields (item_id, definition_id, value) VALUES ($1, $2, $3) RETURNING *", | ||
item_id, | ||
definition_id, | ||
value | ||
) | ||
.fetch_one(&database.pool) | ||
.await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::database::Database; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(sqlx::FromRow, poem_openapi::Object, Debug, Clone, Serialize, Deserialize)] | ||
pub struct ItemMedia { | ||
pub item_id: String, | ||
pub media_id: i32, | ||
} | ||
|
||
impl ItemMedia { | ||
pub async fn create( | ||
item_id: String, | ||
media_id: i32, | ||
database: &Database, | ||
) -> Result<ItemMedia, sqlx::Error> { | ||
sqlx::query_as!( | ||
ItemMedia, | ||
"INSERT INTO item_media (item_id, media_id) VALUES ($1, $2) RETURNING *", | ||
item_id, | ||
media_id | ||
) | ||
.fetch_one(&database.pool) | ||
.await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
engine/src/models/locations.rs → engine/src/models/location.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.