feat(db): Add view for ordering thread index by most recent post

This implements the classic thread ordering expected by most forum
users (i.e. the thread with the most recent post is at the top).
This commit is contained in:
Vincent Ambo 2018-04-14 17:15:27 +02:00
parent cf64826e4e
commit f10bd20276
6 changed files with 45 additions and 7 deletions

View file

@ -26,6 +26,18 @@ pub struct Thread {
pub author_email: String,
}
/// This struct is used as the query type for the thread index view,
/// which lists the index of threads ordered by the last post in each
/// thread.
#[derive(Queryable, Serialize)]
pub struct ThreadIndex {
pub thread_id: i32,
pub title: String,
pub author_name: String,
pub posted: DateTime<Utc>,
pub post_id: i32,
}
#[derive(Identifiable, Queryable, Serialize, Associations)]
#[belongs_to(Thread)]
pub struct Post {