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:
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 crf_rate_vehicle;
|
||||
mod crf_shift_vehicle;
|
||||
mod crf_make_featured;
|
||||
mod crf_unmake_featured;
|
||||
|
||||
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(item_shop_purchase::item_purchase_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