Implement factory in main database, close #80

This commit is contained in:
NG (Graham) committed 2026-02-01 18:14:16 -05:00
1 parent a346299de8
commit 3b909327d8
33 files changed
+741 -78

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
pub mod vehicle;
pub mod vehicle_query;
+58
View File
@@ -0,0 +1,58 @@
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, DeriveEntityModel)]
#[sea_orm(table_name = "factory_vehicles")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub user_id: i32,
pub garage_id: i32,
pub creation_time: i64, // seconds since unix epoch
pub name: String,
pub description: String,
pub added_time: DateTime,
pub expiry_time: DateTime,
pub cpu: i32,
pub total_robot_ranking: i32,
pub get_count: i32,
pub buyable: bool,
pub removed_date: Option<DateTime>,
pub ban_date: Option<DateTime>,
pub featured: bool,
pub banner_message: Option<String>,
pub combat_rating: f64,
pub cosmetic_rating: f64,
pub cube_amounts: String,
pub cube_data: Vec<u8>,
pub colour_data: Vec<u8>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::super::user::Entity",
from = "Column::UserId",
to = "super::super::user::Column::Id"
)]
User,
#[sea_orm(
belongs_to = "super::super::garage::Entity",
from = "Column::UserId",
to = "super::super::garage::Column::Id"
)]
Garage,
}
impl Related<super::super::user::Entity> for Entity {
fn to() -> RelationDef {
Relation::User.def()
}
}
impl Related<super::super::garage::Entity> for Entity {
fn to() -> RelationDef {
Relation::User.def()
}
}
impl ActiveModelBehavior for ActiveModel {}
@@ -0,0 +1,32 @@
use sea_orm::{DerivePartialModel, FromQueryResult};
use sea_orm::entity::prelude::DateTime;
#[derive(FromQueryResult, DerivePartialModel)]
#[sea_orm(entity = "crate::schema::factory::vehicle::Entity")]
pub struct VehicleInfo {
pub id: i32,
pub user_id: i32,
pub creation_time: i64, // seconds since unix epoch
pub name: String,
pub description: String,
pub added_time: DateTime,
pub expiry_time: DateTime,
pub cpu: i32,
pub total_robot_ranking: i32,
pub get_count: i32,
pub buyable: bool,
pub removed_date: Option<DateTime>,
pub ban_date: Option<DateTime>,
pub featured: bool,
pub banner_message: Option<String>,
pub combat_rating: f64,
pub cosmetic_rating: f64,
pub cube_amounts: String,
}
#[derive(FromQueryResult, DerivePartialModel)]
#[sea_orm(entity = "crate::schema::user::Entity")]
pub struct VehicleOwnerInfo {
pub public_id: String,
pub display_name: String,
}
+8
View File
@@ -54,6 +54,8 @@ pub enum Relation {
to = "super::user::Column::Id"
)]
User,
#[sea_orm(has_many = "super::factory::vehicle::Entity")]
FactoryUploads,
}
impl Related<super::user::Entity> for Entity {
@@ -62,6 +64,12 @@ impl Related<super::user::Entity> for Entity {
}
}
impl Related<super::factory::vehicle::Entity> for Entity {
fn to() -> RelationDef {
Relation::FactoryUploads.def()
}
}
impl ActiveModelBehavior for ActiveModel {}
#[repr(i32)]
+2
View File
@@ -10,6 +10,8 @@ pub mod multiplayer_game;
pub mod multiplayer_game_player;
pub mod game_event;
pub mod multiplayer_game_score;
#[cfg(feature = "factory")]
pub mod factory;
pub fn parse_int_csv(s: &str) -> Vec<u32> {
s.split(',').filter_map(|i_as_s| {
+8
View File
@@ -25,6 +25,8 @@ pub enum Relation {
Campaigns,
#[sea_orm(has_many = "super::multiplayer_game_player::Entity")]
Player,
#[sea_orm(has_many = "super::factory::vehicle::Entity")]
FactoryUploads,
}
impl Related<super::permissions::Entity> for Entity {
@@ -57,4 +59,10 @@ impl Related<super::multiplayer_game_player::Entity> for Entity {
}
}
impl Related<super::factory::vehicle::Entity> for Entity {
fn to() -> RelationDef {
Relation::FactoryUploads.def()
}
}
impl ActiveModelBehavior for ActiveModel {}