feat: refactor author username assignment in ThoughtSchema
This commit is contained in:
@@ -23,9 +23,15 @@ pub struct ThoughtSchema {
|
|||||||
|
|
||||||
impl ThoughtSchema {
|
impl ThoughtSchema {
|
||||||
pub fn from_models(thought: &thought::Model, author: &user::Model) -> Self {
|
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 {
|
Self {
|
||||||
id: thought.id,
|
id: thought.id,
|
||||||
author_username: author.username.clone(),
|
author_username,
|
||||||
content: thought.content.clone(),
|
content: thought.content.clone(),
|
||||||
visibility: thought.visibility.clone(),
|
visibility: thought.visibility.clone(),
|
||||||
reply_to_id: thought.reply_to_id,
|
reply_to_id: thought.reply_to_id,
|
||||||
|
Reference in New Issue
Block a user