mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Add dev-only factory ops for featuring a vehicle
This commit is contained in:
@@ -57,6 +57,14 @@ impl oj_rc_factory::VehicleFactoryAdapter for Factory {
|
|||||||
Self::None => Ok(()),
|
Self::None => Ok(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn set_featured(&self, id: i32, is_featured: bool) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
match self {
|
||||||
|
Self::Arc(x) => x.set_featured(id, is_featured).await,
|
||||||
|
Self::Custom(x) => x.set_featured(id, is_featured).await,
|
||||||
|
Self::None => Ok(()),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Factory {
|
impl Factory {
|
||||||
|
|||||||
@@ -321,4 +321,16 @@ impl crate::VehicleFactoryAdapter for ArcAdapter {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn set_featured(&self, id: i32, is_featured: bool) -> 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),
|
||||||
|
featured: sea_orm::ActiveValue::Set(is_featured as i32),
|
||||||
|
..Default::default()
|
||||||
|
}.update(&self.orm).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ pub trait VehicleFactoryAdapter: Send + Sync + 'static {
|
|||||||
/// Just update any purchase trackers
|
/// Just update any purchase trackers
|
||||||
async fn purchase(&self, id: i32) -> Result<(), Box<dyn std::error::Error>>;
|
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 update_vehicle(&self, id: i32, cube_data: Option<Vec<u8>>, colour_data: Option<Vec<u8>>) -> Result<(), Box<dyn std::error::Error>>;
|
||||||
|
async fn set_featured(&self, id: i32, is_featured: bool) -> Result<(), Box<dyn std::error::Error>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|||||||
39
rc_services_room/src/operations/crf_make_featured.rs
Normal file
39
rc_services_room/src/operations/crf_make_featured.rs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
use polariton_server::operations::{SimpleOpError, SimpleOperation, SimpleOpImpl};
|
||||||
|
use polariton::operation::{ParameterTable, Typed};
|
||||||
|
use oj_rc_factory::VehicleFactoryAdapter;
|
||||||
|
|
||||||
|
const CODE: u8 = 99;
|
||||||
|
|
||||||
|
const ID_PARAM_KEY: u8 = 94;
|
||||||
|
|
||||||
|
pub(super) struct FactorySetFeatured {
|
||||||
|
factory: std::sync::Arc<oj_rc_core::factory::Factory>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl <C: Send + 'static> SimpleOperation<C> for FactorySetFeatured {
|
||||||
|
type User = crate::UserTy;
|
||||||
|
const CODE: u8 = CODE;
|
||||||
|
|
||||||
|
async fn handle(&self, mut params: ParameterTable<C>, user: &Self::User) -> Result<ParameterTable<C>, SimpleOpError> {
|
||||||
|
if let Some(Typed::Int(factory_id)) = params.remove(&ID_PARAM_KEY) {
|
||||||
|
let user_info = user.user()?;
|
||||||
|
if user_info.is_dev() {
|
||||||
|
self.factory.set_featured(factory_id, true).await.map_err(|e| {
|
||||||
|
log::error!("Failed to make featured vehicle {} (for offset) from factory: {}", factory_id, e);
|
||||||
|
SimpleOpError::with_message(
|
||||||
|
oj_rc_core::data::error_codes::WebServicesError::DatabaseError as i16,
|
||||||
|
format!("Failed to make featured vehicle (for offset) from factory: {}", e)
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(ParameterTable::with_capacity(1))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn factory_featured_provider<C: Send + 'static>(factory: &std::sync::Arc<oj_rc_core::factory::Factory>) -> SimpleOpImpl<C, crate::UserTy, FactorySetFeatured> {
|
||||||
|
SimpleOpImpl::new(FactorySetFeatured {
|
||||||
|
factory: factory.to_owned()
|
||||||
|
})
|
||||||
|
}
|
||||||
39
rc_services_room/src/operations/crf_unmake_featured.rs
Normal file
39
rc_services_room/src/operations/crf_unmake_featured.rs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
use polariton_server::operations::{SimpleOpError, SimpleOperation, SimpleOpImpl};
|
||||||
|
use polariton::operation::{ParameterTable, Typed};
|
||||||
|
use oj_rc_factory::VehicleFactoryAdapter;
|
||||||
|
|
||||||
|
const CODE: u8 = 100;
|
||||||
|
|
||||||
|
const ID_PARAM_KEY: u8 = 94;
|
||||||
|
|
||||||
|
pub(super) struct FactoryUnsetFeatured {
|
||||||
|
factory: std::sync::Arc<oj_rc_core::factory::Factory>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl <C: Send + 'static> SimpleOperation<C> for FactoryUnsetFeatured {
|
||||||
|
type User = crate::UserTy;
|
||||||
|
const CODE: u8 = CODE;
|
||||||
|
|
||||||
|
async fn handle(&self, mut params: ParameterTable<C>, user: &Self::User) -> Result<ParameterTable<C>, SimpleOpError> {
|
||||||
|
if let Some(Typed::Int(factory_id)) = params.remove(&ID_PARAM_KEY) {
|
||||||
|
let user_info = user.user()?;
|
||||||
|
if user_info.is_dev() {
|
||||||
|
self.factory.set_featured(factory_id, false).await.map_err(|e| {
|
||||||
|
log::error!("Failed to make featured vehicle {} (for offset) from factory: {}", factory_id, e);
|
||||||
|
SimpleOpError::with_message(
|
||||||
|
oj_rc_core::data::error_codes::WebServicesError::DatabaseError as i16,
|
||||||
|
format!("Failed to make featured vehicle (for offset) from factory: {}", e)
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(ParameterTable::with_capacity(1))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) fn factory_featured_provider<C: Send + 'static>(factory: &std::sync::Arc<oj_rc_core::factory::Factory>) -> SimpleOpImpl<C, crate::UserTy, FactoryUnsetFeatured> {
|
||||||
|
SimpleOpImpl::new(FactoryUnsetFeatured {
|
||||||
|
factory: factory.to_owned()
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -103,6 +103,8 @@ mod item_shop_purchase;
|
|||||||
mod code_redeem;
|
mod code_redeem;
|
||||||
mod crf_rate_vehicle;
|
mod crf_rate_vehicle;
|
||||||
mod crf_shift_vehicle;
|
mod crf_shift_vehicle;
|
||||||
|
mod crf_make_featured;
|
||||||
|
mod crf_unmake_featured;
|
||||||
|
|
||||||
use polariton_server::operations::OperationsHandler;
|
use polariton_server::operations::OperationsHandler;
|
||||||
|
|
||||||
@@ -229,4 +231,7 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy>
|
|||||||
.add(steam_promo::steam_promos_provider())
|
.add(steam_promo::steam_promos_provider())
|
||||||
.add(item_shop_purchase::item_purchase_provider(&init_ctx.cubes))
|
.add(item_shop_purchase::item_purchase_provider(&init_ctx.cubes))
|
||||||
.add(code_redeem::code_redeem_provider(&init_ctx.cubes))
|
.add(code_redeem::code_redeem_provider(&init_ctx.cubes))
|
||||||
|
.add(crf_make_featured::factory_featured_provider(&init_ctx.factory))
|
||||||
|
.add(crf_unmake_featured::factory_featured_provider(&init_ctx.factory))
|
||||||
|
.add(polariton_server::operations::Ack::<101, _>::default()) // RestoreCRFFeaturedRobot unused and also redundant???
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user