mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Implement factory in main database, close #80
This commit is contained in:
@@ -294,14 +294,10 @@ impl crate::VehicleFactoryAdapter for ArcAdapter {
|
||||
if self.is_readonly {
|
||||
return Ok(());
|
||||
}
|
||||
// TODO this should probably be a transaction
|
||||
if let Some(meta) = super::entities::robot_metadata::Entity::find_by_id(id as u32).one(&self.orm).await? {
|
||||
super::entities::robot_metadata::ActiveModel {
|
||||
id: sea_orm::ActiveValue::Set(id as u32),
|
||||
buy_count: sea_orm::ActiveValue::Set(meta.buy_count + 1),
|
||||
..Default::default()
|
||||
}.update(&self.orm).await?;
|
||||
}
|
||||
super::entities::robot_metadata::Entity::update_many()
|
||||
.col_expr(super::entities::robot_metadata::Column::BuyCount, super::entities::robot_metadata::Column::BuyCount.into_expr().add(1))
|
||||
.filter(super::entities::robot_metadata::Column::Id.eq(id))
|
||||
.exec(&self.orm).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -325,6 +321,18 @@ impl crate::VehicleFactoryAdapter for ArcAdapter {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn remove_vehicle(&self, id: i32, _user_id: i32) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if self.is_readonly {
|
||||
return Ok(());
|
||||
}
|
||||
super::entities::robot_metadata::ActiveModel {
|
||||
id: sea_orm::ActiveValue::Set(id as u32),
|
||||
buyable: sea_orm::ActiveValue::Set(0),
|
||||
..Default::default()
|
||||
}.update(&self.orm).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn set_featured(&self, id: i32, is_featured: bool) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if self.is_readonly {
|
||||
return Ok(());
|
||||
|
||||
@@ -7,6 +7,7 @@ pub trait VehicleFactoryAdapter: Send + Sync + 'static {
|
||||
/// Just update any purchase trackers
|
||||
async fn purchase(&self, id: i32) -> Result<(), Box<dyn std::error::Error>>;
|
||||
async fn update_vehicle(&self, id: i32, cube_data: Option<Vec<u8>>, colour_data: Option<Vec<u8>>) -> Result<(), Box<dyn std::error::Error>>;
|
||||
async fn remove_vehicle(&self, id: i32, user_id: i32) -> Result<(), Box<dyn std::error::Error>>;
|
||||
async fn set_featured(&self, id: i32, is_featured: bool) -> Result<(), Box<dyn std::error::Error>>;
|
||||
}
|
||||
|
||||
@@ -64,6 +65,8 @@ pub struct VehicleUploadInfo {
|
||||
pub thumbnail: Vec<u8>,
|
||||
pub added_by: String,
|
||||
pub added_by_display_name: String,
|
||||
pub added_by_id: i32,
|
||||
pub garage_id: i32,
|
||||
pub cpu: u32,
|
||||
pub total_robot_ranking: u32,
|
||||
pub cube_data: Vec<u8>,
|
||||
|
||||
Reference in New Issue
Block a user