feat: complete Phase 4 Candidate Workflow (Confirm/Reject API)

This commit is contained in:
Warren
2026-04-25 22:27:31 +08:00
parent e84982e7d9
commit 4686c5abc4
2 changed files with 106 additions and 0 deletions

View File

@@ -15,10 +15,14 @@ pub fn identity_routes() -> Router<crate::api::server::AppState> {
.route("/api/v1/people", get(list_people))
.route("/api/v1/people/search", post(search_people))
.route("/api/v1/people/candidates", get(list_candidates))
.route("/api/v1/people/{identity_id}/confirm-candidate", post(confirm_candidate))
.route("/api/v1/people/{identity_id}/reject-candidate", post(reject_candidate))
.route("/api/v1/files", get(list_files))
.route("/api/v1/files/{uuid}", get(get_file_detail))
}
// ... (Keep existing functions) ...
// --- People / Identity Endpoints ---
#[derive(Debug, Deserialize)]
@@ -156,6 +160,50 @@ async fn list_candidates(
}))
}
// --- Candidate Workflow Endpoints ---
#[derive(Debug, Deserialize)]
pub struct ConfirmCandidateRequest {
pub pre_chunk_id: i64,
}
#[derive(Debug, Serialize)]
pub struct ConfirmCandidateResponse {
pub success: bool,
pub message: String,
}
async fn confirm_candidate(
State(state): State<crate::api::server::AppState>,
Path(identity_id_str): Path<String>,
Json(req): Json<ConfirmCandidateRequest>,
) -> Result<Json<ConfirmCandidateResponse>, (StatusCode, String)> {
let identity_id = Uuid::parse_str(&identity_id_str)
.map_err(|e| (StatusCode::BAD_REQUEST, format!("Invalid UUID: {}", e)))?;
state.db.confirm_candidate(req.pre_chunk_id, identity_id).await
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?;
Ok(Json(ConfirmCandidateResponse {
success: true,
message: "Candidate confirmed and linked to identity".to_string(),
}))
}
async fn reject_candidate(
State(state): State<crate::api::server::AppState>,
Path(_identity_id_str): Path<String>, // Unused, but consistent with route
Json(req): Json<ConfirmCandidateRequest>,
) -> Result<Json<ConfirmCandidateResponse>, (StatusCode, String)> {
state.db.reject_candidate(req.pre_chunk_id).await
.map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?;
Ok(Json(ConfirmCandidateResponse {
success: true,
message: "Candidate rejected".to_string(),
}))
}
// --- Files Endpoints ---
#[derive(Debug, Deserialize)]