#![allow(deprecated)]
use crate::{
database::ThingsDatabase,
error::{Result as ThingsResult, ThingsError},
models::{Area, ThingsId},
};
use chrono::Utc;
use sqlx::Row;
use tracing::{debug, instrument};
impl ThingsDatabase {
#[instrument]
pub async fn get_all_areas(&self) -> ThingsResult<Vec<Area>> {
let rows = sqlx::query(
r"
SELECT
uuid, title, visible, `index`
FROM TMArea
ORDER BY `index` ASC
",
)
.fetch_all(&self.pool)
.await
.map_err(|e| ThingsError::unknown(format!("Failed to fetch areas: {e}")))?;
let mut areas = Vec::new();
for row in rows {
let uuid_str: String = row.get("uuid");
let area = Area {
uuid: ThingsId::from_trusted(uuid_str),
title: row.get("title"),
notes: None, projects: Vec::new(), tags: Vec::new(), created: Utc::now(), modified: Utc::now(), };
areas.push(area);
}
debug!("Fetched {} areas", areas.len());
Ok(areas)
}
#[instrument(skip(self))]
pub async fn get_areas(&self) -> ThingsResult<Vec<Area>> {
self.get_all_areas().await
}
}