From 0c039ebfbc81e7c769e45355fe08e4cec2bc884d Mon Sep 17 00:00:00 2001 From: Nurfog Date: Fri, 10 Apr 2026 10:50:14 -0400 Subject: [PATCH] refactor: Remove unused variables and add dead code allowances for better clarity --- services/cms-service/src/handlers.rs | 3 ++- services/cms-service/src/handlers_admin.rs | 2 ++ services/cms-service/src/handlers_embeddings.rs | 7 +++---- .../cms-service/src/handlers_question_bank.rs | 15 ++++++++++++--- services/cms-service/src/handlers_sam.rs | 6 +++--- .../cms-service/src/handlers_test_templates.rs | 16 +++++++++++++--- services/cms-service/src/webhooks.rs | 11 ++++++----- services/lms-service/src/handlers_embeddings.rs | 1 + shared/common/src/ai.rs | 1 + shared/common/src/models.rs | 1 + 10 files changed, 44 insertions(+), 19 deletions(-) diff --git a/services/cms-service/src/handlers.rs b/services/cms-service/src/handlers.rs index e7dfcbf..261ea5d 100644 --- a/services/cms-service/src/handlers.rs +++ b/services/cms-service/src/handlers.rs @@ -948,7 +948,7 @@ pub async fn run_transcription_task(pool: PgPool, lesson_id: Uuid) -> Result<(), let full_text = transcription_result["text"].as_str().unwrap_or(""); if !full_text.is_empty() { tracing::info!("Triggering AI summary for lesson {}", lesson_id); - if let Ok((summary, input_tokens, output_tokens)) = generate_summary_with_ollama(full_text, lesson_id, &pool).await { + if let Ok((summary, _input_tokens, _output_tokens)) = generate_summary_with_ollama(full_text, lesson_id, &pool).await { tracing::info!("Summary generated successfully for lesson {}", lesson_id); let _ = sqlx::query("UPDATE lessons SET summary = $1 WHERE id = $2") .bind(summary) @@ -2879,6 +2879,7 @@ pub async fn get_organization( } /// GET /organization - Public endpoint (returns default organization) +#[allow(dead_code)] pub async fn get_public_organization( State(pool): State, ) -> Result, StatusCode> { diff --git a/services/cms-service/src/handlers_admin.rs b/services/cms-service/src/handlers_admin.rs index 47fde1c..49b2673 100644 --- a/services/cms-service/src/handlers_admin.rs +++ b/services/cms-service/src/handlers_admin.rs @@ -1,3 +1,5 @@ +#![allow(dead_code)] + use axum::{ Json, extract::{Path, Query, State}, diff --git a/services/cms-service/src/handlers_embeddings.rs b/services/cms-service/src/handlers_embeddings.rs index 2c4d652..d930674 100644 --- a/services/cms-service/src/handlers_embeddings.rs +++ b/services/cms-service/src/handlers_embeddings.rs @@ -9,7 +9,6 @@ use axum::{ use common::ai::{self, generate_embedding}; use common::models::QuestionBank; use common::middleware::Org; -use reqwest::Client; use serde::{Deserialize, Serialize}; use sqlx::PgPool; use uuid::Uuid; @@ -77,7 +76,7 @@ pub async fn generate_question_embeddings( .await .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))?; - let total = questions.len(); + let _total = questions.len(); let mut processed = 0; let mut failed = 0; @@ -280,12 +279,12 @@ pub async fn semantic_search( let mut param_idx = 3; - if let Some(ref question_type) = filters.question_type { + if filters.question_type.is_some() { param_idx += 1; query.push_str(&format!(" AND question_type::text = ${}", param_idx)); } - if let Some(ref difficulty) = filters.difficulty { + if filters.difficulty.is_some() { param_idx += 1; query.push_str(&format!(" AND difficulty = ${}", param_idx)); } diff --git a/services/cms-service/src/handlers_question_bank.rs b/services/cms-service/src/handlers_question_bank.rs index 758decd..151556b 100644 --- a/services/cms-service/src/handlers_question_bank.rs +++ b/services/cms-service/src/handlers_question_bank.rs @@ -137,6 +137,7 @@ async fn connect_mysql_pool(env_var: &str) -> Result, @@ -1514,6 +1517,7 @@ pub async fn import_all_from_mysql( } #[derive(Debug, Serialize)] +#[allow(dead_code)] pub struct ImportResult { pub imported: i32, pub skipped: i32, @@ -1549,6 +1553,7 @@ pub struct MySqlQuestionFull { } #[derive(Debug, sqlx::FromRow)] +#[allow(dead_code)] struct MySqlQuestion { id_pregunta: i32, descripcion: String, @@ -1565,6 +1570,7 @@ struct MySqlQuestion { #[derive(Debug, Deserialize)] pub struct AIGenerateQuestionPayload { pub question_text: Option, + #[allow(dead_code)] pub question_type: Option, pub difficulty: Option, pub skill: Option, @@ -1588,6 +1594,7 @@ pub async fn ai_generate_question( use std::time::Duration; let question_text = payload.question_text.unwrap_or_else(|| "Pregunta de gramática inglesa".to_string()); + let question_type = payload.question_type.unwrap_or_else(|| "multiple-choice".to_string()); let difficulty = payload.difficulty.unwrap_or_else(|| "medium".to_string()); let skill = payload.skill.unwrap_or_else(|| "grammar".to_string()); @@ -1597,6 +1604,7 @@ pub async fn ai_generate_question( Create a multiple-choice question with the following parameters: - Topic/Context: {} + - Question type: {} - Difficulty: {} - Skill assessed: {} @@ -1607,7 +1615,7 @@ pub async fn ai_generate_question( "correct_answer": 0, "explanation": "Detailed explanation of why this is correct" }}"#, - question_text, difficulty, skill + question_text, question_type, difficulty, skill ); // Llamar a Ollama AI con tiempo de espera extendido @@ -1800,8 +1808,8 @@ async fn generate_course_structure<'a>( course_id: Uuid, org_id: Uuid, course_type: &str, - level: &str, - course_name: &str, + _level: &str, + _course_name: &str, ) -> Result<(i32, i32), String> { // Definir la estructura de módulos basada en el tipo de curso // Regular (40h): 4 módulos @@ -1892,6 +1900,7 @@ struct SamDiagnosticoQuestion { pub id_curso: i32, pub id_pregunta: i32, pub pregunta_nombre: Option, + #[allow(dead_code)] pub tipo_pregunta: Option, /// Opciones separadas por '|||' (GROUP_CONCAT) pub opciones: Option, diff --git a/services/cms-service/src/handlers_sam.rs b/services/cms-service/src/handlers_sam.rs index 43aaada..c0d163b 100644 --- a/services/cms-service/src/handlers_sam.rs +++ b/services/cms-service/src/handlers_sam.rs @@ -115,7 +115,7 @@ pub async fn sync_sam_students( .flatten(); match existing_user { - Some((user_id, existing_sam_id)) => { + Some((user_id, _existing_sam_id)) => { // Actualizar usuario existente con información de SAM let update_result = sqlx::query( r#" @@ -373,8 +373,8 @@ pub async fn get_sam_student_courses( /// POST /api/sam/sync-all /// Sincronización completa: estudiantes + asignaciones pub async fn sync_all_sam( - org: Org, - claims: Claims, + _org: Org, + _claims: Claims, State(pool): State, ) -> Result, (StatusCode, String)> { let mut errors = Vec::new(); diff --git a/services/cms-service/src/handlers_test_templates.rs b/services/cms-service/src/handlers_test_templates.rs index 04d7611..8168a57 100644 --- a/services/cms-service/src/handlers_test_templates.rs +++ b/services/cms-service/src/handlers_test_templates.rs @@ -270,7 +270,7 @@ pub async fn get_test_template( pub async fn update_test_template( Org(org_ctx): Org, Path(template_id): Path, - claims: Claims, + _claims: Claims, State(pool): State, Json(payload): Json, ) -> Result, (StatusCode, String)> { @@ -511,7 +511,7 @@ pub struct CreateSectionPayload { /// DELETE /api/test-templates/:template_id/sections/:section_id - Eliminar una sección pub async fn delete_template_section( - Org(org_ctx): Org, + Org(_org_ctx): Org, Path((template_id, section_id)): Path<(Uuid, Uuid)>, State(pool): State, ) -> Result { @@ -540,7 +540,7 @@ pub async fn delete_template_section( pub async fn apply_template_to_lesson( Org(org_ctx): Org, Path(template_id): Path, - claims: Claims, + _claims: Claims, State(pool): State, Json(payload): Json, ) -> Result { @@ -1075,6 +1075,8 @@ pub async fn generate_questions_with_rag( tracing::info!("La búsqueda semántica encontró {} preguntas similares", mysql_questions.len()); if mysql_questions.is_empty() { + tracing::info!( + "Sin coincidencias semánticas para el tema; recurso a búsqueda por palabras clave. topic={} course_id={:?}", topic, payload.course_id ); @@ -1124,6 +1126,8 @@ pub async fn generate_questions_with_rag( .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("El recurso a palabras clave falló: {}", e)))?; if mysql_questions.is_empty() { + tracing::info!( + "Sin coincidencias por palabras clave; recurso a preguntas importadas por curso. course_id={:?}", payload.course_id ); @@ -1219,6 +1223,8 @@ pub async fn generate_questions_with_rag( .map_err(|e| (StatusCode::INTERNAL_SERVER_ERROR, format!("La búsqueda por palabras clave falló: {}", e)))?; if mysql_questions.is_empty() { + tracing::info!( + "Sin resultados semánticos ni por palabras clave; recurso a preguntas importadas por curso. course_id={:?}", payload.course_id ); @@ -1337,6 +1343,8 @@ pub async fn generate_questions_with_rag( } if mysql_questions.is_empty() { + tracing::warn!( + "No se encontraron preguntas importadas para org={} course_id={:?} topic={:?}; recurso a preguntas de toda la organización", org_ctx.id, payload.course_id, payload.topic @@ -1828,6 +1836,7 @@ pub struct RagGenerationPayload { } #[derive(Debug, sqlx::FromRow)] +#[allow(dead_code)] struct QuestionBankForRAG { descripcion: String, options: Option, @@ -1839,6 +1848,7 @@ struct QuestionBankForRAG { } #[derive(Debug, sqlx::FromRow)] +#[allow(dead_code)] struct MySqlQuestion { descripcion: String, id_tipo_pregunta: i32, diff --git a/services/cms-service/src/webhooks.rs b/services/cms-service/src/webhooks.rs index de75bb3..0ccfa65 100644 --- a/services/cms-service/src/webhooks.rs +++ b/services/cms-service/src/webhooks.rs @@ -56,11 +56,12 @@ impl WebhookService { match res { Ok(response) => { if !response.status().is_success() { - "El envío del webhook a {} (evento: {}) falló con estado {}", - url, - event_type, - response.status() - ); + tracing::error!( + "El envío del webhook a {} (evento: {}) falló con estado {}", + url, + event_type, + response.status() + ); } else { tracing::info!( "Webhook enviado con éxito a {} (evento: {})", diff --git a/services/lms-service/src/handlers_embeddings.rs b/services/lms-service/src/handlers_embeddings.rs index 07b011b..5e33a0c 100644 --- a/services/lms-service/src/handlers_embeddings.rs +++ b/services/lms-service/src/handlers_embeddings.rs @@ -272,6 +272,7 @@ pub async fn semantic_search_knowledge( // ==================== Estructuras de Ayuda ==================== #[derive(Debug, sqlx::FromRow, Clone)] +#[allow(dead_code)] struct KnowledgeBaseEntry { id: Uuid, organization_id: Uuid, diff --git a/shared/common/src/ai.rs b/shared/common/src/ai.rs index 5632f9d..ce15ae2 100644 --- a/shared/common/src/ai.rs +++ b/shared/common/src/ai.rs @@ -117,6 +117,7 @@ pub fn get_model_for_task(task: &str) -> String { } /// Crear un cliente reqwest que acepte certificados inválidos (para desarrollo con certificados autofirmados) +#[allow(dead_code)] fn create_insecure_client() -> Result { reqwest::Client::builder() .danger_accept_invalid_certs(true) diff --git a/shared/common/src/models.rs b/shared/common/src/models.rs index 79b162b..6212300 100644 --- a/shared/common/src/models.rs +++ b/shared/common/src/models.rs @@ -1182,6 +1182,7 @@ pub struct PublicProfile { #[derive(Debug, Serialize, Deserialize, sqlx::Type, Clone, PartialEq)] #[sqlx(type_name = "course_level", rename_all = "lowercase")] #[serde(rename_all = "lowercase")] +#[allow(non_camel_case_types)] pub enum CourseLevel { Beginner, Beginner_1,