(
state: &Arc<ServerState>,
request: Request<EditDraftChunkRequest>,
)
| 2847 | } |
| 2848 | |
| 2849 | pub(super) async fn handle_edit_draft_chunk( |
| 2850 | state: &Arc<ServerState>, |
| 2851 | request: Request<EditDraftChunkRequest>, |
| 2852 | ) -> Result<Response<EditDraftChunkResponse>, Status> { |
| 2853 | let req = request.into_inner(); |
| 2854 | if req.name.is_empty() { |
| 2855 | return Err(Status::invalid_argument("name is required")); |
| 2856 | } |
| 2857 | if req.chunk_id.is_empty() { |
| 2858 | return Err(Status::invalid_argument("chunk_id is required")); |
| 2859 | } |
| 2860 | let proposed_rule = req |
| 2861 | .proposed_rule |
| 2862 | .ok_or_else(|| Status::invalid_argument("proposed_rule is required"))?; |
| 2863 | |
| 2864 | let sandbox = state |
| 2865 | .store |
| 2866 | .get_message_by_name::<Sandbox>(&req.name) |
| 2867 | .await |
| 2868 | .map_err(|e| Status::internal(format!("fetch sandbox failed: {e}")))? |
| 2869 | .ok_or_else(|| Status::not_found("sandbox not found"))?; |
| 2870 | let sandbox_id = sandbox.object_id().to_string(); |
| 2871 | |
| 2872 | let chunk = state |
| 2873 | .store |
| 2874 | .get_draft_chunk(&req.chunk_id) |
| 2875 | .await |
| 2876 | .map_err(|e| Status::internal(format!("fetch chunk failed: {e}")))? |
| 2877 | .ok_or_else(|| Status::not_found("chunk not found"))?; |
| 2878 | ensure_chunk_belongs_to_sandbox(&chunk, &sandbox_id)?; |
| 2879 | |
| 2880 | if chunk.status != "pending" { |
| 2881 | return Err(Status::failed_precondition(format!( |
| 2882 | "chunk status is '{}', expected 'pending'", |
| 2883 | chunk.status |
| 2884 | ))); |
| 2885 | } |
| 2886 | |
| 2887 | let rule_bytes = proposed_rule.encode_to_vec(); |
| 2888 | state |
| 2889 | .store |
| 2890 | .update_draft_chunk_rule(&req.chunk_id, &rule_bytes) |
| 2891 | .await |
| 2892 | .map_err(|e| Status::internal(format!("update chunk rule failed: {e}")))?; |
| 2893 | |
| 2894 | info!( |
| 2895 | chunk_id = %req.chunk_id, |
| 2896 | "EditDraftChunk: proposed rule updated" |
| 2897 | ); |
| 2898 | |
| 2899 | Ok(Response::new(EditDraftChunkResponse {})) |
| 2900 | } |
| 2901 | |
| 2902 | pub(super) async fn handle_undo_draft_chunk( |
| 2903 | state: &Arc<ServerState>, |
no test coverage detected