feat: add author display name to thought schemas and update related components
This commit is contained in:
@@ -38,6 +38,7 @@ pub async fn search_thoughts(
|
||||
// We must join with the user table to get the author's username
|
||||
let thoughts_with_authors = thought::Entity::find()
|
||||
.column_as(user::Column::Username, "author_username")
|
||||
.column_as(user::Column::DisplayName, "author_display_name")
|
||||
.join(JoinType::InnerJoin, thought::Relation::User.def())
|
||||
.filter(Expr::cust_with_values(
|
||||
"thought.search_document @@ websearch_to_tsquery('english', $1)",
|
||||
|
@@ -102,6 +102,7 @@ pub async fn get_thoughts_by_user(
|
||||
.column(thought::Column::CreatedAt)
|
||||
.column(thought::Column::AuthorId)
|
||||
.column(thought::Column::Visibility)
|
||||
.column_as(user::Column::DisplayName, "author_display_name")
|
||||
.column_as(user::Column::Username, "author_username")
|
||||
.join(JoinType::InnerJoin, thought::Relation::User.def())
|
||||
.filter(apply_visibility_filter(user_id, viewer_id, &friend_ids))
|
||||
@@ -137,6 +138,7 @@ pub async fn get_feed_for_user(
|
||||
.column(thought::Column::Visibility)
|
||||
.column(thought::Column::AuthorId)
|
||||
.column_as(user::Column::Username, "author_username")
|
||||
.column_as(user::Column::DisplayName, "author_display_name")
|
||||
.join(JoinType::InnerJoin, thought::Relation::User.def())
|
||||
.filter(
|
||||
Condition::any().add(following_ids.iter().fold(
|
||||
@@ -173,6 +175,7 @@ pub async fn get_thoughts_by_tag_name(
|
||||
.column(thought::Column::AuthorId)
|
||||
.column(thought::Column::Visibility)
|
||||
.column_as(user::Column::Username, "author_username")
|
||||
.column_as(user::Column::DisplayName, "author_display_name")
|
||||
.join(JoinType::InnerJoin, thought::Relation::User.def())
|
||||
.join(JoinType::InnerJoin, thought::Relation::ThoughtTag.def())
|
||||
.join(JoinType::InnerJoin, thought_tag::Relation::Tag.def())
|
||||
@@ -288,6 +291,7 @@ pub async fn get_thought_with_replies(
|
||||
ThoughtThreadSchema {
|
||||
id: thought_schema.id,
|
||||
author_username: thought_schema.author_username.clone(),
|
||||
author_display_name: thought_schema.author_display_name.clone(),
|
||||
content: thought_schema.content.clone(),
|
||||
visibility: thought_schema.visibility.clone(),
|
||||
reply_to_id: thought_schema.reply_to_id,
|
||||
|
@@ -14,6 +14,7 @@ pub struct ThoughtSchema {
|
||||
pub id: Uuid,
|
||||
#[schema(example = "frutiger")]
|
||||
pub author_username: String,
|
||||
pub author_display_name: Option<String>,
|
||||
#[schema(example = "This is my first thought! #welcome")]
|
||||
pub content: String,
|
||||
pub visibility: Visibility,
|
||||
@@ -23,15 +24,10 @@ pub struct ThoughtSchema {
|
||||
|
||||
impl ThoughtSchema {
|
||||
pub fn from_models(thought: &thought::Model, author: &user::Model) -> Self {
|
||||
let author_username = if let Some(display_name) = author.display_name.clone() {
|
||||
display_name
|
||||
} else {
|
||||
author.username.clone()
|
||||
};
|
||||
|
||||
Self {
|
||||
id: thought.id,
|
||||
author_username,
|
||||
author_username: author.username.clone(),
|
||||
author_display_name: author.display_name.clone(),
|
||||
content: thought.content.clone(),
|
||||
visibility: thought.visibility.clone(),
|
||||
reply_to_id: thought.reply_to_id,
|
||||
@@ -60,6 +56,7 @@ pub struct ThoughtWithAuthor {
|
||||
pub visibility: Visibility,
|
||||
pub author_id: Uuid,
|
||||
pub author_username: String,
|
||||
pub author_display_name: Option<String>,
|
||||
pub reply_to_id: Option<Uuid>,
|
||||
}
|
||||
|
||||
@@ -68,6 +65,7 @@ impl From<ThoughtWithAuthor> for ThoughtSchema {
|
||||
Self {
|
||||
id: model.id,
|
||||
author_username: model.author_username,
|
||||
author_display_name: model.author_display_name,
|
||||
content: model.content,
|
||||
created_at: model.created_at.into(),
|
||||
reply_to_id: model.reply_to_id,
|
||||
@@ -81,6 +79,7 @@ impl From<ThoughtWithAuthor> for ThoughtSchema {
|
||||
pub struct ThoughtThreadSchema {
|
||||
pub id: Uuid,
|
||||
pub author_username: String,
|
||||
pub author_display_name: Option<String>,
|
||||
pub content: String,
|
||||
pub visibility: Visibility,
|
||||
pub reply_to_id: Option<Uuid>,
|
||||
|
Reference in New Issue
Block a user