From 2083f3bb16ce25d9df112005bae8f853ff5651cf Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Sun, 7 Sep 2025 22:37:12 +0200 Subject: [PATCH] feat: refactor author username assignment in ThoughtSchema --- thoughts-backend/models/src/schemas/thought.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/thoughts-backend/models/src/schemas/thought.rs b/thoughts-backend/models/src/schemas/thought.rs index f24d85f..2504551 100644 --- a/thoughts-backend/models/src/schemas/thought.rs +++ b/thoughts-backend/models/src/schemas/thought.rs @@ -23,9 +23,15 @@ 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.clone(), + author_username, content: thought.content.clone(), visibility: thought.visibility.clone(), reply_to_id: thought.reply_to_id,