Refactor: Remove unused structs, redundant services, and streamline repository models
This commit is contained in:
@@ -24,13 +24,6 @@ pub struct LocationElementQueryResult {
|
||||
pub element_description: Option<String>,
|
||||
}
|
||||
|
||||
pub struct LocationByTagResult {
|
||||
pub element_name: String,
|
||||
pub element_description: Option<String>,
|
||||
pub sub_elem_name: Option<String>,
|
||||
pub sub_elem_description: Option<String>,
|
||||
}
|
||||
|
||||
pub struct BookLocationTable {
|
||||
pub loc_id: String,
|
||||
pub book_id: String,
|
||||
@@ -349,51 +342,6 @@ pub fn fetch_location_tags(conn: &Connection, user_id: &str, book_id: &str, lang
|
||||
/// * `conn` - Database connection
|
||||
/// * `user_id` - The user's unique identifier
|
||||
/// * `locations` - An array of location tag IDs to search for
|
||||
/// * `lang` - The language for error messages ("fr" or "en")
|
||||
/// Returns an array of locations matching the provided tags.
|
||||
/// Errors if no tags are provided or no locations are found.
|
||||
pub fn fetch_locations_by_tags(conn: &Connection, user_id: &str, locations: &[String], lang: Lang) -> AppResult<Vec<LocationByTagResult>> {
|
||||
if locations.is_empty() {
|
||||
return Err(AppError::Validation(if lang == Lang::Fr { "Aucun tag fourni.".to_string() } else { "No tags provided.".to_string() }));
|
||||
}
|
||||
|
||||
let location_placeholders: String = locations.iter().map(|_| "?").collect::<Vec<_>>().join(",");
|
||||
let query = format!("SELECT el.element_name, el.element_description, se.sub_elem_name, se.sub_elem_description FROM location_element AS el LEFT JOIN location_sub_element AS se ON el.element_id = se.element_id WHERE el.user_id = ?1 AND (el.element_id IN ({}) OR se.sub_element_id IN ({}))", location_placeholders, location_placeholders);
|
||||
|
||||
let mut statement = conn
|
||||
.prepare(&query)
|
||||
.map_err(|_| AppError::Internal(if lang == Lang::Fr { "Impossible de récupérer les emplacements par tags.".to_string() } else { "Unable to retrieve locations by tags.".to_string() }))?;
|
||||
|
||||
let mut param_values: Vec<Box<dyn rusqlite::types::ToSql>> = Vec::new();
|
||||
param_values.push(Box::new(user_id.to_string()));
|
||||
for location in locations {
|
||||
param_values.push(Box::new(location.clone()));
|
||||
}
|
||||
for location in locations {
|
||||
param_values.push(Box::new(location.clone()));
|
||||
}
|
||||
let param_refs: Vec<&dyn rusqlite::types::ToSql> = param_values.iter().map(|parameter| parameter.as_ref() as &dyn rusqlite::types::ToSql).collect();
|
||||
|
||||
let locations_by_tags = statement
|
||||
.query_map(param_refs.as_slice(), |query_row| {
|
||||
Ok(LocationByTagResult {
|
||||
element_name: query_row.get(0)?,
|
||||
element_description: query_row.get(1)?,
|
||||
sub_elem_name: query_row.get(2)?,
|
||||
sub_elem_description: query_row.get(3)?,
|
||||
})
|
||||
})
|
||||
.map_err(|_| AppError::Internal(if lang == Lang::Fr { "Impossible de récupérer les emplacements par tags.".to_string() } else { "Unable to retrieve locations by tags.".to_string() }))?
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.map_err(|_| AppError::Internal(if lang == Lang::Fr { "Impossible de récupérer les emplacements par tags.".to_string() } else { "Unable to retrieve locations by tags.".to_string() }))?;
|
||||
|
||||
if locations_by_tags.is_empty() {
|
||||
return Err(AppError::NotFound(if lang == Lang::Fr { "Aucun emplacement trouvé avec ces tags.".to_string() } else { "No locations found with these tags.".to_string() }));
|
||||
}
|
||||
|
||||
Ok(locations_by_tags)
|
||||
}
|
||||
|
||||
/// Checks if a location exists in the database.
|
||||
/// * `conn` - Database connection
|
||||
/// * `user_id` - The user's unique identifier
|
||||
|
||||
Reference in New Issue
Block a user