mirror of
https://github.com/YGGverse/rssto.git
synced 2026-03-31 17:15:29 +00:00
implement default sort ordering features
This commit is contained in:
parent
c324246cc6
commit
5d232f54c9
2 changed files with 19 additions and 5 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue