Codex worktree snapshot: settings-delete-targeted
Co-authored-by: Codex
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
use crate::*;
|
||||
use serde::Serialize;
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::{Serialize, de::DeserializeOwned};
|
||||
use sha2::{Digest, Sha256};
|
||||
|
||||
pub(crate) mod tables;
|
||||
@@ -15,7 +14,7 @@ pub fn create_bark_battle_draft(
|
||||
input: BarkBattleDraftCreateInput,
|
||||
) -> BarkBattleProcedureResult {
|
||||
match ctx.try_with_tx(|tx| create_bark_battle_draft_tx(tx, input.clone())) {
|
||||
Ok(snapshot) => bark_battle_json_result(&snapshot),
|
||||
Ok(snapshot) => bark_battle_draft_config_result(snapshot),
|
||||
Err(error) => bark_battle_error_result(error),
|
||||
}
|
||||
}
|
||||
@@ -26,7 +25,7 @@ pub fn update_bark_battle_draft_config(
|
||||
input: BarkBattleDraftConfigUpsertInput,
|
||||
) -> BarkBattleProcedureResult {
|
||||
match ctx.try_with_tx(|tx| update_bark_battle_draft_config_tx(tx, input.clone())) {
|
||||
Ok(snapshot) => bark_battle_json_result(&snapshot),
|
||||
Ok(snapshot) => bark_battle_draft_config_result(snapshot),
|
||||
Err(error) => bark_battle_error_result(error),
|
||||
}
|
||||
}
|
||||
@@ -37,7 +36,7 @@ pub fn publish_bark_battle_work(
|
||||
input: BarkBattleWorkPublishInput,
|
||||
) -> BarkBattleProcedureResult {
|
||||
match ctx.try_with_tx(|tx| publish_bark_battle_work_tx(tx, input.clone())) {
|
||||
Ok(snapshot) => bark_battle_json_result(&snapshot),
|
||||
Ok(snapshot) => bark_battle_runtime_config_result(snapshot),
|
||||
Err(error) => bark_battle_error_result(error),
|
||||
}
|
||||
}
|
||||
@@ -48,7 +47,7 @@ pub fn get_bark_battle_runtime_config(
|
||||
input: BarkBattleRuntimeConfigGetInput,
|
||||
) -> BarkBattleProcedureResult {
|
||||
match ctx.try_with_tx(|tx| get_bark_battle_runtime_config_tx(tx, input.clone())) {
|
||||
Ok(snapshot) => bark_battle_json_result(&snapshot),
|
||||
Ok(snapshot) => bark_battle_runtime_config_result(snapshot),
|
||||
Err(error) => bark_battle_error_result(error),
|
||||
}
|
||||
}
|
||||
@@ -59,7 +58,7 @@ pub fn start_bark_battle_run(
|
||||
input: BarkBattleRunStartInput,
|
||||
) -> BarkBattleProcedureResult {
|
||||
match ctx.try_with_tx(|tx| start_bark_battle_run_tx(tx, input.clone())) {
|
||||
Ok(snapshot) => bark_battle_json_result(&snapshot),
|
||||
Ok(snapshot) => bark_battle_run_result(snapshot),
|
||||
Err(error) => bark_battle_error_result(error),
|
||||
}
|
||||
}
|
||||
@@ -70,7 +69,7 @@ pub fn finish_bark_battle_run(
|
||||
input: BarkBattleRunFinishInput,
|
||||
) -> BarkBattleProcedureResult {
|
||||
match ctx.try_with_tx(|tx| finish_bark_battle_run_tx(tx, input.clone())) {
|
||||
Ok(snapshot) => bark_battle_json_result(&snapshot),
|
||||
Ok(snapshot) => bark_battle_run_result(snapshot),
|
||||
Err(error) => bark_battle_error_result(error),
|
||||
}
|
||||
}
|
||||
@@ -81,7 +80,7 @@ pub fn get_bark_battle_run(
|
||||
input: BarkBattleRunGetInput,
|
||||
) -> BarkBattleProcedureResult {
|
||||
match ctx.try_with_tx(|tx| get_bark_battle_run_tx(tx, input.clone())) {
|
||||
Ok(snapshot) => bark_battle_json_result(&snapshot),
|
||||
Ok(snapshot) => bark_battle_run_result(snapshot),
|
||||
Err(error) => bark_battle_error_result(error),
|
||||
}
|
||||
}
|
||||
@@ -584,10 +583,36 @@ fn validate_json<T: DeserializeOwned>(value: &str, field_name: &str) -> Result<(
|
||||
.map_err(|error| format!("bark_battle {field_name} JSON 无效: {error}"))
|
||||
}
|
||||
|
||||
fn bark_battle_json_result<T: Serialize>(value: &T) -> BarkBattleProcedureResult {
|
||||
fn bark_battle_draft_config_result(
|
||||
draft_config: BarkBattleDraftConfigSnapshot,
|
||||
) -> BarkBattleProcedureResult {
|
||||
BarkBattleProcedureResult {
|
||||
ok: true,
|
||||
row_json: Some(to_json_string(value)),
|
||||
draft_config: Some(draft_config),
|
||||
runtime_config: None,
|
||||
run: None,
|
||||
error_message: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn bark_battle_runtime_config_result(
|
||||
runtime_config: BarkBattleRuntimeConfigSnapshot,
|
||||
) -> BarkBattleProcedureResult {
|
||||
BarkBattleProcedureResult {
|
||||
ok: true,
|
||||
draft_config: None,
|
||||
runtime_config: Some(runtime_config),
|
||||
run: None,
|
||||
error_message: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn bark_battle_run_result(run: BarkBattleRunSnapshot) -> BarkBattleProcedureResult {
|
||||
BarkBattleProcedureResult {
|
||||
ok: true,
|
||||
draft_config: None,
|
||||
runtime_config: None,
|
||||
run: Some(run),
|
||||
error_message: None,
|
||||
}
|
||||
}
|
||||
@@ -595,7 +620,9 @@ fn bark_battle_json_result<T: Serialize>(value: &T) -> BarkBattleProcedureResult
|
||||
fn bark_battle_error_result(error: String) -> BarkBattleProcedureResult {
|
||||
BarkBattleProcedureResult {
|
||||
ok: false,
|
||||
row_json: None,
|
||||
draft_config: None,
|
||||
runtime_config: None,
|
||||
run: None,
|
||||
error_message: Some(error),
|
||||
}
|
||||
}
|
||||
@@ -850,7 +877,21 @@ mod tests {
|
||||
|
||||
let result = BarkBattleProcedureResult {
|
||||
ok: true,
|
||||
row_json: Some(input.config_json.clone()),
|
||||
draft_config: Some(BarkBattleDraftConfigSnapshot {
|
||||
draft_id: input.draft_id.clone(),
|
||||
owner_user_id: input.owner_user_id.clone(),
|
||||
work_id: input.work_id.clone(),
|
||||
config_version: input.config_version,
|
||||
ruleset_version: input.ruleset_version.clone(),
|
||||
difficulty_preset: input.difficulty_preset.clone(),
|
||||
leaderboard_enabled: input.leaderboard_enabled,
|
||||
config_json: input.config_json.clone(),
|
||||
editor_state_json: "{}".to_string(),
|
||||
created_at_micros: 1_700_000,
|
||||
updated_at_micros: input.updated_at_micros,
|
||||
}),
|
||||
runtime_config: None,
|
||||
run: None,
|
||||
error_message: None,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user