implement default sort ordering features

This commit is contained in:
yggverse 2026-01-08 00:22:07 +02:00
parent c324246cc6
commit 5d232f54c9
2 changed files with 19 additions and 5 deletions

View file

@ -114,13 +114,13 @@ impl Mysql {
Ok(total.unwrap_or(0))
}
pub fn contents(&self, limit: Option<usize>) -> Result<Vec<Content>, Error> {
pub fn contents(&self, sort: Sort, limit: Option<usize>) -> Result<Vec<Content>, Error> {
self.pool.get_conn()?.query(format!(
"SELECT `content_id`,
`channel_item_id`,
`source_id`,
`title`,
`description` FROM `content` LIMIT {}",
`description` FROM `content` ORDER BY `content_id` {sort} LIMIT {}",
limit.unwrap_or(DEFAULT_LIMIT)
))
}
@ -188,4 +188,18 @@ pub struct Content {
pub description: String,
}
pub enum Sort {
Asc,
Desc,
}
impl std::fmt::Display for Sort {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Self::Asc => write!(f, "ASC"),
Self::Desc => write!(f, "DESC"),
}
}
}
const DEFAULT_LIMIT: usize = 100;