mirror of
https://github.com/Nutomic/ibis.git
synced 2024-11-22 08:31:09 +00:00
sort article list by recently edited first
This commit is contained in:
parent
4e53b13b70
commit
90f174bf53
3 changed files with 14 additions and 8 deletions
|
@ -20,7 +20,7 @@ use axum::Extension;
|
|||
use axum::Form;
|
||||
use axum::Json;
|
||||
use axum_macros::debug_handler;
|
||||
use chrono::Utc;
|
||||
use chrono::{Utc};
|
||||
use diffy::create_patch;
|
||||
|
||||
/// Create a new article with empty text, and federate it to followers.
|
||||
|
|
|
@ -6,6 +6,7 @@ use crate::common::EditVersion;
|
|||
use crate::common::{ArticleView, DbArticle};
|
||||
use activitypub_federation::fetch::collection_id::CollectionId;
|
||||
use activitypub_federation::fetch::object_id::ObjectId;
|
||||
use diesel::dsl::max;
|
||||
use diesel::pg::PgConnection;
|
||||
use diesel::ExpressionMethods;
|
||||
use diesel::{
|
||||
|
@ -118,9 +119,14 @@ impl DbArticle {
|
|||
.get_result(conn.deref_mut())?)
|
||||
}
|
||||
|
||||
/// Read all articles, ordered by most recently edited first.
|
||||
pub fn read_all(only_local: bool, conn: &Mutex<PgConnection>) -> MyResult<Vec<Self>> {
|
||||
let mut conn = conn.lock().unwrap();
|
||||
let query = article::table.into_boxed();
|
||||
let query = article::table
|
||||
.inner_join(edit::table)
|
||||
.group_by(article::dsl::id)
|
||||
.order_by(max(edit::dsl::created).desc())
|
||||
.select(article::all_columns);
|
||||
Ok(if only_local {
|
||||
query
|
||||
.filter(article::dsl::local.eq(true))
|
||||
|
|
|
@ -3,7 +3,7 @@ extern crate ibis_lib;
|
|||
mod common;
|
||||
|
||||
use crate::common::{TestData, TEST_ARTICLE_DEFAULT_TEXT};
|
||||
use ibis_lib::common::{ArticleView, EditArticleData, ForkArticleData, GetArticleData};
|
||||
use ibis_lib::common::{ArticleView, EditArticleData, ForkArticleData, GetArticleData, ListArticlesData};
|
||||
use ibis_lib::common::{CreateArticleData, SearchArticleData};
|
||||
use ibis_lib::common::{LoginUserData, RegisterUserData};
|
||||
use ibis_lib::frontend::error::MyResult;
|
||||
|
@ -59,11 +59,11 @@ async fn test_create_read_and_edit_local_article() -> MyResult<()> {
|
|||
assert_eq!(1, search_res.len());
|
||||
assert_eq!(edit_res.article, search_res[0]);
|
||||
|
||||
let list_articles = data.alpha.list_articles().await?;
|
||||
dbg!(&list_articles);
|
||||
// default main page and article created by this test
|
||||
assert_eq!(2, list_articles.len());
|
||||
assert_eq!(edit_res.article, list_articles[1]);
|
||||
let list_articles = data.alpha.list_articles(ListArticlesData {
|
||||
only_local: Some(false),
|
||||
}).await?;
|
||||
assert_eq!(1, list_articles.len());
|
||||
assert_eq!(edit_res.article, list_articles[0]);
|
||||
|
||||
data.stop()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue