Refactor and clean up

- Removed unused services (`cover`, `character`, `series_location` modules) and legacy methods to reduce code clutter.
- Consolidated `IncidentProps` and `PlotPointProps` into `incident.service` and `plotpoint.service` modules, replacing duplicated definitions.
- Updated references across modules (`act`, `incident.service`, `character`) for consistency.
- Improved serialization with `serde` for `IncidentProps`.
- Enhanced `get_incitents_incidents` to include optional chapters.
This commit is contained in:
natreex
2026-03-21 11:29:58 -04:00
parent 1f99fe0bdc
commit 1478fe10dd
7 changed files with 24 additions and 665 deletions

View File

@@ -82,30 +82,6 @@ pub struct AttributeResult {
pub attribute_value: String,
}
pub struct CompleteCharacterResult {
pub character_id: String,
pub first_name: String,
pub last_name: String,
pub nickname: Option<String>,
pub age: Option<String>,
pub gender: Option<String>,
pub species: Option<String>,
pub nationality: Option<String>,
pub status: Option<String>,
pub category: String,
pub title: String,
pub role: String,
pub biography: String,
pub history: String,
pub speech_pattern: Option<String>,
pub catchphrase: Option<String>,
pub residence: Option<String>,
pub notes: Option<String>,
pub color: Option<String>,
pub attribute_name: String,
pub attribute_value: String,
}
pub struct CharacterData {
pub first_name: String,
pub last_name: Option<String>,
@@ -346,54 +322,6 @@ pub fn fetch_attributes(conn: &Connection, character_id: &str, user_id: &str, la
/// * `book_id` - The unique identifier of the book
/// * `tags` - An optional array of character IDs to filter by
/// * `lang` - The language for error messages ("fr" or "en")
/// Returns an array of complete character results with attributes.
pub fn fetch_complete_characters(conn: &Connection, user_id: &str, book_id: &str, tags: &[String], lang: Lang) -> AppResult<Vec<CompleteCharacterResult>> {
let mut query = "SELECT charac.character_id, first_name, last_name, nickname, age, gender, species, nationality, status, category, title, role, biography, history, speech_pattern, catchphrase, residence, notes, color, attribute_name, attribute_value FROM book_characters AS charac LEFT JOIN book_characters_attributes AS attr ON charac.character_id=attr.character_id WHERE charac.user_id=?1 AND charac.book_id=?2".to_string();
let mut param_values: Vec<Box<dyn rusqlite::types::ToSql>> = Vec::new();
param_values.push(Box::new(user_id.to_string()));
param_values.push(Box::new(book_id.to_string()));
if !tags.is_empty() {
let placeholders: String = tags.iter().enumerate().map(|(index, _)| format!("?{}", index + 3)).collect::<Vec<_>>().join(",");
query += &format!(" AND charac.character_id IN ({})", placeholders);
for tag in tags {
param_values.push(Box::new(tag.clone()));
}
}
let param_refs: Vec<&dyn rusqlite::types::ToSql> = param_values.iter().map(|param| param.as_ref()).collect();
let mut statement = conn
.prepare(&query)
.map_err(|_| AppError::Internal(if lang == Lang::Fr { "Impossible de récupérer les personnages complets.".to_string() } else { "Unable to retrieve complete characters.".to_string() }))?;
let characters = statement
.query_map(param_refs.as_slice(), |query_row| {
Ok(CompleteCharacterResult {
character_id: query_row.get(0)?, first_name: query_row.get(1)?,
last_name: query_row.get(2)?, nickname: query_row.get(3)?,
age: query_row.get(4)?, gender: query_row.get(5)?,
species: query_row.get(6)?, nationality: query_row.get(7)?,
status: query_row.get(8)?, category: query_row.get(9)?,
title: query_row.get(10)?, role: query_row.get(11)?,
biography: query_row.get(12)?, history: query_row.get(13)?,
speech_pattern: query_row.get(14)?, catchphrase: query_row.get(15)?,
residence: query_row.get(16)?, notes: query_row.get(17)?,
color: query_row.get(18)?, attribute_name: query_row.get(19)?,
attribute_value: query_row.get(20)?,
})
})
.map_err(|_| AppError::Internal(if lang == Lang::Fr { "Impossible de récupérer les personnages complets.".to_string() } else { "Unable to retrieve complete characters.".to_string() }))?
.collect::<Result<Vec<_>, _>>()
.map_err(|_| AppError::Internal(if lang == Lang::Fr { "Impossible de récupérer les personnages complets.".to_string() } else { "Unable to retrieve complete characters.".to_string() }))?;
if characters.is_empty() {
return Err(AppError::NotFound(if lang == Lang::Fr { "Aucun personnage complet trouvé.".to_string() } else { "No complete characters found.".to_string() }));
}
Ok(characters)
}
/// Updates an existing character attribute.
/// * `conn` - Database connection
/// * `user_id` - The unique identifier of the user