forgot to cd into a directory before generating entities
This commit is contained in:
parent
a65657aea1
commit
ec8859b59c
|
@ -21,8 +21,8 @@ pub struct CreateGroupWithoutId {
|
|||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct CreateNode {
|
||||
id: i32,
|
||||
struct CreateNodeRequest {
|
||||
id: u64,
|
||||
group: uuid::Uuid,
|
||||
}
|
||||
|
||||
|
@ -95,31 +95,15 @@ pub async fn create_group(
|
|||
|
||||
pub async fn create_node(
|
||||
state: web::Data<AppState>,
|
||||
node: web::Json<CreateNode>,
|
||||
node_request: web::Json<CreateNodeRequest>,
|
||||
) -> actix_web::Result<impl Responder> {
|
||||
let db = &state.db;
|
||||
|
||||
let node = node.into_inner();
|
||||
|
||||
println!("Checking group ID: {:?}", node.group);
|
||||
|
||||
let group_exists = entity::node_group::Entity::find_by_id(node.group)
|
||||
.one(db)
|
||||
.await
|
||||
.map_err(ErrorInternalServerError)?
|
||||
.is_some();
|
||||
|
||||
if !group_exists {
|
||||
return Err(ErrorInternalServerError("Group ID does not exist"));
|
||||
}
|
||||
|
||||
let mac_int =
|
||||
mac_to_i32(&node.id).map_err(|_| ErrorInternalServerError("Invalid MAC address"))?;
|
||||
node.id = mac_int;
|
||||
let node = node_request.into_inner();
|
||||
|
||||
let node = entity::node::ActiveModel {
|
||||
id: ActiveValue::Set(node.id),
|
||||
group: ActiveValue::Set(node.group),
|
||||
group: ActiveValue::Set(node_request.group),
|
||||
};
|
||||
|
||||
let result = node.insert(db).await.map_err(ErrorInternalServerError)?;
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1
|
||||
|
||||
pub mod prelude;
|
||||
|
||||
pub mod node;
|
||||
pub mod node_group;
|
||||
pub mod sensor_data;
|
||||
pub mod user;
|
|
@ -1,44 +0,0 @@
|
|||
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "node")]
|
||||
pub struct Model {
|
||||
#[sea_orm(
|
||||
primary_key,
|
||||
auto_increment = false,
|
||||
column_type = "custom(\"macaddr\")"
|
||||
)]
|
||||
pub id: String,
|
||||
pub group: Uuid,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::node_group::Entity",
|
||||
from = "Column::Group",
|
||||
to = "super::node_group::Column::Id",
|
||||
on_update = "Cascade",
|
||||
on_delete = "Cascade"
|
||||
)]
|
||||
NodeGroup,
|
||||
#[sea_orm(has_many = "super::sensor_data::Entity")]
|
||||
SensorData,
|
||||
}
|
||||
|
||||
impl Related<super::node_group::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::NodeGroup.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::sensor_data::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::SensorData.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
|
@ -1,26 +0,0 @@
|
|||
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "node_group")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::node::Entity")]
|
||||
Node,
|
||||
}
|
||||
|
||||
impl Related<super::node::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Node.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
|
@ -1,6 +0,0 @@
|
|||
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1
|
||||
|
||||
pub use super::node::Entity as Node;
|
||||
pub use super::node_group::Entity as NodeGroup;
|
||||
pub use super::sensor_data::Entity as SensorData;
|
||||
pub use super::user::Entity as User;
|
|
@ -1,54 +0,0 @@
|
|||
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "sensor_data")]
|
||||
pub struct Model {
|
||||
#[sea_orm(
|
||||
primary_key,
|
||||
auto_increment = false,
|
||||
column_type = "custom(\"macaddr\")"
|
||||
)]
|
||||
pub id: String,
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub timestamp: DateTime,
|
||||
#[sea_orm(column_type = "Double")]
|
||||
pub coord_la: f64,
|
||||
#[sea_orm(column_type = "Double")]
|
||||
pub coord_lo: f64,
|
||||
#[sea_orm(column_type = "Float")]
|
||||
pub temperature: f32,
|
||||
#[sea_orm(column_type = "Double")]
|
||||
pub battery_minimum: f64,
|
||||
#[sea_orm(column_type = "Double")]
|
||||
pub battery_current: f64,
|
||||
#[sea_orm(column_type = "Double")]
|
||||
pub battery_maximum: f64,
|
||||
#[sea_orm(column_type = "Double")]
|
||||
pub voltage: f64,
|
||||
pub uptime: i64,
|
||||
#[sea_orm(column_type = "custom(\"macaddr\")", nullable)]
|
||||
pub node_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::node::Entity",
|
||||
from = "Column::NodeId",
|
||||
to = "super::node::Column::Id",
|
||||
on_update = "Cascade",
|
||||
on_delete = "Cascade"
|
||||
)]
|
||||
Node,
|
||||
}
|
||||
|
||||
impl Related<super::node::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Node.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
|
@ -1,19 +0,0 @@
|
|||
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "user")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub email: String,
|
||||
pub hash: String,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
|
@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
|
|||
#[sea_orm(table_name = "node")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: i32,
|
||||
pub id: i64,
|
||||
pub group: Uuid,
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ pub struct Model {
|
|||
#[sea_orm(column_type = "Double")]
|
||||
pub voltage: f64,
|
||||
pub uptime: i64,
|
||||
pub node_id: i32,
|
||||
pub node_id: i64,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
|
|
|
@ -26,7 +26,7 @@ impl MigrationTrait for Migration {
|
|||
Table::create()
|
||||
.table(Node::Table)
|
||||
.if_not_exists()
|
||||
.col(integer(Node::Id).primary_key())
|
||||
.col(big_unsigned(Node::Id).primary_key())
|
||||
.col(uuid(Node::Group))
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
|
|
|
@ -27,7 +27,7 @@ impl MigrationTrait for Migration {
|
|||
.col(double(SensorData::BatteryMaximum).default(-127))
|
||||
.col(double(SensorData::Voltage).default(-127))
|
||||
.col(big_unsigned(SensorData::Uptime).default(0))
|
||||
.col(integer(SensorData::NodeId))
|
||||
.col(big_unsigned(SensorData::NodeId))
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-data-node_id")
|
||||
|
|
Loading…
Reference in a new issue